'Error while building GHC 9.2.1 for target=aarch64-apple-ios

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:

  1. 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://[email protected]/ghc/packages-".insteadOf ssh://[email protected]/ghc/packages/ 
git config --global url."[email protected]:ghc/packages-".insteadOf       [email protected]: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?



Solution 1:[1]

I have got an answer on Haskell Discource, here is a link:

https://discourse.haskell.org/t/need-help-error-while-building-ghc-9-2-1-for-target-aarch64-apple-ios/4129/3

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Denis Krivitski