@hsyl20 and me have been working to get GHCup up to speed wrt cross compilers and GHC JS backend. You can read more about it here as well: IOG GHC Update #14 | IOG Engineering
This is still experimental, which is why it’s a pre-release, so we can gather some user experience reports.
Here’s how to install GHCJS from a bindist and run a JS hello world:
1. Install emscripten
This is the required JS toolchain.
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
Instructions also here: Download and install — Emscripten 3.1.43-git (dev) documentation
2. Upgrade ghcup to pre-release
ghcup config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/develop/ghcup-prereleases-0.0.7.yaml
ghcup upgrade
3. Install cross bindist
ghcup config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/develop/ghcup-cross-0.0.8.yaml
emconfigure ghcup install ghc --set javascript-unknown-ghcjs-9.6.2
This will leave you with ghc binary called javascript-unknown-ghcjs-ghc
.
3.1 Alternatively, you can also compile cross from source via ghcup:
ghcup install ghc 9.6.2
emconfigure ghcup -v compile ghc -j $(nproc) --git-ref ghc-9.6 -b 9.6.2 --hadrian -x javascript-unknown-ghcjs -o 9.6.2 --flavour=default+native_bignum
ghcup set ghc javascript-unknown-ghcjs-9.6.2
4. Compile hello world
Also see: building · Wiki · Glasgow Haskell Compiler / GHC · GitLab
Create a file HelloJS.hs
with the following contents:
module Main where
main :: IO ()
main = putStrLn "Hello, JavaScript!"
Compile:
javascript-unknown-ghcjs-ghc -fforce-recomp HelloJS.hs
Run:
./HelloJS
Remarks
So far we only have 3 bindists: Index of /ghcup/unofficial-bindists/ghc/javascript-unknown-ghcjs-9.6.2/
These were all built manually by me. I couldn’t make it work on windows, there were build failures and emscripten doesn’t work too well there.