mirror of
https://github.com/tweag/ormolu.git
synced 2024-08-17 00:40:27 +03:00
.. | ||
app | ||
cbits | ||
src | ||
www | ||
.envrc | ||
.gitignore | ||
build-wasm.sh | ||
cabal.project | ||
default.nix | ||
ormolu-live.cabal | ||
package-lock.json | ||
package.json | ||
README.md |
Ormolu Live
Play around with Ormolu in the browser via the GHC WASM backend!
Overview
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.
Development
Make sure to be in the .#ormoluLive
Nix shell when entering ./ormolu-live
, e.g. conveniently via nix-direnv.
Local interactive development
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.
Building the site for deployment
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
.