Play around with Ormolu in the browser via the GHC WASM backend!
ATM, the GHC WASM backend only supports emitting WASI binaries, which can be run in the browser via e.g. browser_wasi_shim or the more fully-featured wasmer-wasi.
Hence, Ormolu Live consists of two parts:
- A regular Purescript frontend (in
src/
) that displays input/output and manages options. - A background web worker (in this directory with the source in
app/Main.hs
) that formats Haskell source code via the WASM-compiled Ormolu.
Make sure to be in the .#ormoluLive
Nix shell when entering ./ormolu-live
, e.g. conveniently via nix-direnv.
For building the WASM binary, run
wasm32-wasi-cabal update
and then iterate by running something like
watchexec -w app ./build-wasm.sh
For the Purescript frontend, you can run
watchexec -w src purs-nix compile
and
parcel www/index.html
in parallel. The latter command will display the URL to a dev server, usually http://localhost:1234.
First, build the components:
nix build .#ormoluLive
wasm32-wasi-cabal update
./build-wasm.sh -Oz
Here, -Oz
tells wasm-opt
to aggressively optimize for code size.
Then, combine the two:
cp -r --no-preserve=mode,ownership result/ site
cp src/ormolu.wasm site/ormolu.*.wasm
The self-contained site is now in site
.