1
1
mirror of https://github.com/tweag/ormolu.git synced 2024-08-17 00:40:27 +03:00
ormolu/ormolu-live
2023-10-27 20:55:53 +02:00
..
app Ormolu Live: exclude certain packages with conflicting modules 2023-05-22 09:01:59 +02:00
cbits Improve ormolu live wasm size 2023-10-27 20:55:53 +02:00
src Pre-init Ormolu Live with Wizer 2023-02-17 11:25:44 +01:00
www Add WASM-based Ormolu Live 2023-01-24 18:45:36 +01:00
.envrc Add WASM-based Ormolu Live 2023-01-24 18:45:36 +01:00
.gitignore Add WASM-based Ormolu Live 2023-01-24 18:45:36 +01:00
build-wasm.sh Pre-init Ormolu Live with Wizer 2023-02-17 11:25:44 +01:00
cabal.project ghc-lib-parser 9.8 2023-10-19 15:43:23 +02:00
default.nix Use WASM GHC 9.8 2023-09-04 11:44:12 +02:00
ormolu-live.cabal Ormolu Live: exclude certain packages with conflicting modules 2023-05-22 09:01:59 +02:00
package-lock.json Pre-init Ormolu Live with Wizer 2023-02-17 11:25:44 +01:00
package.json Pre-init Ormolu Live with Wizer 2023-02-17 11:25:44 +01:00
README.md Add WASM-based Ormolu Live 2023-01-24 18:45:36 +01:00

Ormolu Live

Play around with Ormolu in the browser via the GHC WASM backend!

https://ormolu-live.tweag.io

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.

Acknowledgements

https://github.com/monadfix/ormolu-live