为target=aarch64苹果ios构建GHC 9.2.1时出错



我有一个用Haskell编写的库,我想在iOS和Android应用程序中使用。该库主要包含业务逻辑和网络,没有GUI调用,因此使用该库从iOS或Android应用程序只需使用C FFI调用单个入口点即可。我首先从iOS目标开始。

据我所知,为了将Haskell源代码编译成Mach-O-arch64对象文件,稍后可能链接到iOS应用程序,我需要使用目标aarch64苹果iOS编译GHC编译器。

以下是我如何编译GHC:

  1. 首先使用以下shell创建一个nix 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
'';
}

然后从nix shell内部运行以下命令:

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

然后我得到以下编译错误:

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

我尝试使用hadrian进行构建,得到了完全相同的结果。我正在构建的机器是:macOS蒙特利12.1

有人知道怎么解决这个问题吗?GHC 9.2.1是否直接支持iOS和Android目标,或者是否需要任何类型的编译器补丁?

我在Haskell Discource上得到了答案,这里有一个链接:

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

最新更新