Tuesday, January 19, 2021

How to build GHCJS

This is a story of buidling GHCJS in Ubuntu 20.04. The GHC version that GHCJS depends on is 8.6.x. 

 -  https://github.com/ghcjs/ghcjs


Preliminaries: 

 - Download GHC8.6.x binary and Cabal-3.2.0.0 binary in a path accessible by PATH

    : https://www.haskell.org/ghc/download.html

    : https://www.haskell.org/cabal/download.html

 - Install alex and happy by sudo apt-get install alex happy

(According to the Happy web site, the source of happy should be installed by git clone and cabal install happy but it failed due to a reason that I do not know. It seems that building the happy source needs a happy binary. :) If you have any hint, please leave me a message.)


(During the installation of ghc-8-6-x, you may need to install libtinfo.so.5, which is available by sudo apt-get install libtinfo.)


Now you follow the GHCJS installation instruction


1. Getting and preparing the source tree

 - git clone --branch ghc-8.6 https://github.com/ghcjs/ghcjs.git

 - cd ghcjs

 - git submodule update --init --recursive

 - ./utils/makePackages.sh

(You may need to install autoconf by sudo apt-get install autoconf before you run the shell script.)


2. Building the compiler

 - cabal new-configure (When cabal new-configure was failed, you may try cabal configure, but this may be due to some cabal version problem.)

 - cabal new-build  (When cabal new-build was failed, you may try cabal build, but this may be also due to the version problem.)

 (You may need sudo apt-get install libtinfo-dev when the build fails due to the absence of libtinfo.)


It will take long time...


 - cd $YOURBIN

  (I assume that the path $YOURBIN is accessible by $PATH.)


 - ln -s $GHCJSHOME/utils/dist-newstyle-wrapper.sh ghcjs

 - ln -s $GHCJSHOME/utils/dist-newstyle-wrapper.sh ghcjs-pkg

 - ln -s $GHCJSHOME/utils/dist-newstyle-wrapper.sh haddock-ghcjs

 - ln -s $GHCJSHOME/utils/dist-newstyle-wrapper.sh hsc2hs-ghcjs

 - ln -s $GHCJSHOME/utils/dist-newstyle-wrapper.sh ghcjs-boot

 - ln -s $GHCJSHOME/utils/dist-newstyle-wrapper.sh ghcjs-run

 (There is no instruction about ghcjs-run but I attempted to add it after I found a ghcj-run-not-found error on ghcjs-boot in the next stage.)


3. Booting GHCJS


 (You may need node by sudo apt-get install nodejs, and npm by sudo apt-get install npm.)

 - ghcjs-boot --no-haddoc -no-prof -s ./lib/boot

 (In the specified directory, boot.yaml exists. Without -s option, it will get stuck with a boot.yaml-not-found error. The default instruction was without the option. I am wondering when the default one would work. )

(--no-haddoc is given as an option not to get an error, "Haddock's resource directory does not exist!")


It will take long time again...


(Umm... Sorry I switched to Miso who is a layer on top of GHCJS. You don't have to get tangled with the installation of GHCJS any more.)