A working example demonstrating the use of:
ghc-wasm-meta
for compiling Haskell code to a WASI modulebrowser-wasi-shim
for running the compiled WASI module in the browser
At the moment, the build is based mostly on Brandon Chinn's fourmolu-wasm
setup, in addition to the following resources:
- Haskell Discourse, "Javascript & WebAssembly backend"
ghc-wasm-meta
@ GitLab, Issue #1, "Allow disablinghead.hackage
insetup.sh
" (and this commit, this workflow)- ezyang 2011, "Accessing lazy structures from C"
Install ghc-wasm-meta
according to the "Getting Started without Nix". I am using FLAVOUR=9.8
. Then, populate your environment with source ~/.ghc-wasm/env
.
$ wasm32-wasi-ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.8.0.20230809
$ wasm32-wasi-cabal --version
cabal-install version 3.10.1.0
compiled using version 3.10.1.0 of the Cabal library
Next, follow the instructions to set up head.hackage
, which allows Hackage packages to be used with GHC prereleases (such as ghc-wasm
).
The build scripts are organized as a justfile
.
just build-wasm
Once the Haskell project has been built, you can run the frontend in development mode with:
cd frontend
npm run dev