Skip to content

Instantly share code, notes, and snippets.

@pasberth
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasberth/10245898 to your computer and use it in GitHub Desktop.
Save pasberth/10245898 to your computer and use it in GitHub Desktop.
GHCJS Install Battle

事前に、GHC 7.8.1 が必要です

$ git clone git@github.com:ghcjs/cabal.git cabal-ghcjs
$ git clone git@github.com:ghcjs/ghcjs.git
$ cd cabal-ghcjs
$ git checkout ghcjs

# ``cabal install ./Cabal ./cabal-install'' だと cabal が上書きされてしまう。
# ``--program-suffix=-ghcjs'' をつけると cabal-ghcjs という名前でインストールされる
# --program-suffix=-ghcjs 
$ cabal install ./Cabal ./cabal-install --program-suffix=-ghcjs
$ mkdir /tmp/bin

# ``cabal'' という名前で cabal-ghcjs がインストールされていることを
# 期待するライブラリがあるので、一時的にラップする
$ echo '#!/bin/sh' >> /tmp/bin/cabal
$ echo 'cabal-ghcjs "$@"' >> /tmp/bin/cabal
$ chmod +x /tmp/bin/cabal
$ export PATH=/tmp/bin:$PATH

$ cd ..
$ cabal-ghcjs install ghcjs
$ ghcjs-boot --init
   :
ghcjs-boot: error running: git submodule update --init --recursive
exit status: 1
stderr: fatal: reference is not a tree: a172709589717865aa2fab5f683839b0aadecb4c
Unable to checkout 'a172709589717865aa2fab5f683839b0aadecb4c' in submodule path 'boot/containers'
   :

# ↑このエラーはもう1回コマンドを走らせたらなぜか問題なく通った

$ ghcjs-boot --init
    :
cbits/popcnt.c:15:0:  error: conflicting types for ‘hs_popcnt8’

/Users/pasberth/.ghcjs/x86_64-darwin-0.1.0-7.8.1/lib/include/../include_native/stg/Prim.h:25:0:
     error: previous declaration of ‘hs_popcnt8’ was here

cbits/popcnt.c:18:0:  error: conflicting types for ‘hs_popcnt8’

/Users/pasberth/.ghcjs/x86_64-darwin-0.1.0-7.8.1/lib/include/../include_native/stg/Prim.h:25:0:
     error: previous declaration of ‘hs_popcnt8’ was here

cbits/popcnt.c:22:0:  error: conflicting types for ‘hs_popcnt16’

/Users/pasberth/.ghcjs/x86_64-darwin-0.1.0-7.8.1/lib/include/../include_native/stg/Prim.h:26:0:
     error: previous declaration of ‘hs_popcnt16’ was here

cbits/popcnt.c:25:0:  error: conflicting types for ‘hs_popcnt16’

/Users/pasberth/.ghcjs/x86_64-darwin-0.1.0-7.8.1/lib/include/../include_native/stg/Prim.h:26:0:
     error: previous declaration of ‘hs_popcnt16’ was here

cbits/popcnt.c:30:0:  error: conflicting types for ‘hs_popcnt32’

/Users/pasberth/.ghcjs/x86_64-darwin-0.1.0-7.8.1/lib/include/../include_native/stg/Prim.h:27:0:
     error: previous declaration of ‘hs_popcnt32’ was here

cbits/popcnt.c:33:0:  error: conflicting types for ‘hs_popcnt32’

/Users/pasberth/.ghcjs/x86_64-darwin-0.1.0-7.8.1/lib/include/../include_native/stg/Prim.h:27:0:
     error: previous declaration of ‘hs_popcnt32’ was here
    :
# ↑ このエラーは
#     ~/.ghcjs/x86_64-darwin-0.1.0-7.8.1/lib/include_native/stg/Prim.h
# というヘッダファイルの
#     /* libraries/ghc-prim/cbits/popcnt.c */
#     StgWord hs_popcnt8(StgWord x);
#     StgWord hs_popcnt16(StgWord x);
#     StgWord hs_popcnt32(StgWord x);
#     StgWord hs_popcnt64(StgWord64 x);
# というコードを
#     /* libraries/ghc-prim/cbits/popcnt.c */
#     StgWord hs_popcnt8(StgWord8 x);
#     StgWord hs_popcnt16(StgWord16 x);
#     StgWord hs_popcnt32(StgWord32 x);
#     StgWord hs_popcnt64(StgWord64 x);
# のように直したら通った

$ cd /tmp
$ echo 'main = putStrLn "hello world"' > hello.hs
$ ghcjs -o hello hello.hs
$ node hello.jsexe/all.js
hello world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment