我有一个用Haskell写的库,我想在iOS和安卓应用程序中使用。库主要包含业务逻辑和网络,没有GUI调用,因此使用iOS或安卓应用程序的库只是使用C调用单个入口点的问题。我首先从iOS目标开始。
据我所知,为了将Haskell源代码编译成一个Mach-O aarch64对象文件(以后可以链接到iOS应用程序),我需要用一个目标aarch64 apple-ios编译GHC编译器。
下面是我如何编译GHC的过程:
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
有没有人知道如何解决这个问题?GHC9.2.1是否立即支持iOS和安卓目标,还是需要进行任何类型的编译器修补?
发布于 2022-02-23 09:30:50
我有一个关于Haskell Discource的答案,这里有一个链接:
https://stackoverflow.com/questions/71208444
复制相似问题