tobold.org

correct • elegant • free

Building ghcjs with ghc-7.10.1

I've been doing some work recently with the wonderful ghcjs. This is an incredibly exciting project, but it's still early days, and actually building the compiler can be tricky, particularly if you want to use the also-new-and-exciting ghc-7.10.1. I've created this recipe that has worked for me several times, and I hope it may be useful to others too.

Prerequisites

You will need some version of ghc installed (presumably from your distro), happy, alex, and cabal. You will also need gcc and gcc-c++: if you do not have the C++ compiler you will get confusing error messages that /bin/cpp failed sanity check.

I usually create a brand new user to make a test build, so that my usual development user can keep working, even if the build fails. Then I'll copy the ghc binaries to my usual user, and repeat the build of ghcjs and its deps. (It's awkward to copy built packages, as they have paths wired into them. There is a way around this, but I'd rather burn some more CPU cycles.)

Recipe

Download the ghc source.

Unpack, and configure with ./configure --prefix /home/ghcjs (or whatever the correct path is). Build with make -j5 (where 5 is one more than the number of CPU cores you have available). Install with make install

Install cabal:

cabal update
git clone https://github.com/haskell/cabal.git
cabal install ./cabal/Cabal ./cabal/cabal-install

Ensure that ~/.cabal/bin is on path, that cabal install --help includes the --ghcjs option, and that ghc-pkg list Cabal lists Cabal-1.23.0.0.

Install versions of some libraries patched to build with ghc-7.10.1:

git clone https://github.com/seereason/haskell-src-meta
git clone https://github.com/seereason/ansi-wl-pprint --branch pr-base48
git clone https://github.com/seereason/wl-pprint-text
git clone https://github.com/seereason/stringsearch
cabal install  ./haskell-src-meta ./ansi-wl-pprint ./wl-pprint-text ./stringsearch

The tar package specifies old-time by default, which causes problems, so build it with the correct flag:

cabal install -f-old-time tar

I can't quite remember why the lens build needs to be pulled out, but anyway:

cabal install lens

Install development version of haddock: --allow-newer is needed to cure an outdated upper-bound in haddock-api:

git clone https://github.com/haskell/haddock.git
cabal install --allow-newer ./haddock/haddock-api ./haddock/haddock-library

Finally we are ready to install ghcjs itself:

git clone https://github.com/ghcjs/ghcjs-prim.git
git clone https://github.com/ghcjs/ghcjs.git
cabal install ./ghcjs ./ghcjs-prim
ghcjs-boot --dev --ghcjs-boot-dev-branch ghc-7.10

That's all folks!

$ ghcjs -V
The Glorious Glasgow Haskell Compilation System for JavaScript,
version 0.1.0 (GHC 7.10.1)

Notes

I will endeavour to keep this document up to date as packages evolve. If you do encounter any trouble following these instructions, I'd like to hear about it.

An alternative approach to installing ghcjs is to use the Nix package manager: ryantrinkle has been working hard on a Nix ghcjs package. I've not had the chance to look at this yet, but will do so as soon as time permits.