I have a library written in Haskell that I would like to use in iOS and Android apps.
The library contains mainly business logic and networking, no GUI calls, therefore using this library
from an iOS or Android app is just a matter of calling a single entry point using C FFI.
I am starting first with the iOS target.
To the best of my knowledge, in order to compile Haskell sources into a Mach-O aarch64 object file,
which could later be linked to the iOS app, I need to compile the GHC compiler with a target aarch64-apple-ios.
Here is how I did the compilation of GHC:
- First create a nix-shell with the following shell.nix:
let
unstable = import <unstable> { };
in
{ nixpkgs ? import <nixpkgs> {} }:
nixpkgs.mkShell {
nativeBuildInputs = [
nixpkgs.automake
nixpkgs.autoconf
nixpkgs.python38
nixpkgs.haskell.compiler.ghc8107
nixpkgs.cabal-install
nixpkgs.sphinx
unstable.clang_13
nixpkgs.llvmPackages_13.llvm
nixpkgs.gmp
nixpkgs.gnumake
nixpkgs.git
];
shellHook =
''
cabal install alex-3.2.6 happy-1.20.0
export PATH=$PATH:~/.cabal/bin
'';
}
then from inside the nix-shell run the following commands:
git config --global url."git://github.com/ghc/packages-".insteadOf git://github.com/ghc/packages/
git config --global url."http://github.com/ghc/packages-".insteadOf http://github.com/ghc/packages/
git config --global url."https://github.com/ghc/packages-".insteadOf https://github.com/ghc/packages/
git config --global url."ssh://git@github.com/ghc/packages-".insteadOf ssh://git@github.com/ghc/packages/
git config --global url."git@github.com:ghc/packages-".insteadOf git@github.com:ghc/packages/
git clone --recurse-submodules git://github.com/ghc/ghc
cd ghc
git checkout ghc-9.2.1-release
git submodule update --init --recursive
echo "HADDOCK_DOCS = NO" >> mk/build.mk
./boot
./configure --target=aarch64-apple-ios -disable-large-address-space
make -j
Then I get the following compilation error:
rts/StgCRun.c:965:11: error:
error: unknown register name '%x19' in asm
: "%x19", "%x20", "%x21", "%x22", "%x23", "%x24", "%x25", "%x26", "%x27", "%x28",
^
|
965 | : "%x19", "%x20", "%x21", "%x22", "%x23", "%x24", "%x25", "%x26", "%x27", "%x28",
| ^
1 error generated.
`clang' failed in phase `C Compiler'. (Exit code: 1)
make[1]: *** [rts/ghc.mk:345: rts/dist/build/StgCRun.o] Error 1
make: *** [Makefile:128: all] Error 2
I tried to build with hadrian
, got exactly the same results.
The machine I am building on is: macOS Monterey 12.1
Does anybody habe any idea how to solve this?
Does GHC 9.2.1 support iOS and Android targets straight away or is any kind of compiler patching required?