LoginSignup
9
2

More than 1 year has passed since last update.

Apple Silicon MacでGHC masterをビルドするメモ

Last updated at Posted at 2020-12-16

この記事は元々arm64-apple-darwin向けの公式バイナリーが出る前に書かれたが、2021年8月現在の状況を反映して大幅に書き換えられた。古い話(Rosetta 2を使ったbootstrappingとか)に興味のある人は記事の編集履歴を見てほしい。

公式のissue

これが公式のissueだったが最近は更新されていない:

メモ:

すでにApple Silicon対応のバイナリー(8.10.5以降)がリリースされ、masterブランチにAArch64 NCGも入ってしまった今となってはこのissueもほぼ用済みかもしれない。あとはGHC 9.0.2が出れば……。

必要な外部のツール類

python3, automake, autoconf, llvm-11

筆者はMacPortsで入れた。

$ port install python3 automake autoconf cmake llvm-11

これで opt-mp-11 コマンドと llc-mp-11 コマンドが使えるようになるはず。

Haskell環境のインストール

Apple Silicon MacにGHC/cabalを入れるメモ - Qiitaにも書いたが、ghcupやstackが対応していない現段階ではHomebrewで入れるのが手っ取り早い。

$ brew install ghc cabal-install

GHCをビルドするための alexhappy を入れる。

$ cabal install alex happy

ghc-9.0 をビルドする際には happy 1.19.x が必要なようなのでバージョンを指定する。

$ cabal install --constraint="happy==1.19.*" --overwrite-policy=always happy

GHCのビルド

まず、GHCを「x86_64で動作し、AArch64バイナリーを吐く」クロスコンパイラーとしてビルドする。

$ git clone --recursive https://gitlab.haskell.org/ghc/ghc.git
$ cd ghc
$ ./boot
$ ./configure --with-intree-gmp LLC=llc-mp-11 OPT=opt-mp-11 ALEX=$HOME/.cabal/bin/alex HAPPY=$HOME/.cabal/bin/happy
$ hadrian/build --flavour=quick -j

これで _build/stage1/bin/ghc (あるいはエイリアスとして _build/ghc-stage1)ができる。

masterブランチ(あるいは9.2ブランチ)にはAArch64 NCGが入っているので、LLVMがなくても動作するはずだ。LLVMバックエンドを使いたい場合は -fllvm を指定すれば良いし明示的にNCGを指定したい場合は -fasm を指定すれば良い。

9
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
2