Skip to content

Commit

Permalink
doc: add some developer docs on how to build for Wasm
Browse files Browse the repository at this point in the history
Signed-off-by: Drew Hess <src@drewhess.com>
  • Loading branch information
dhess committed Nov 29, 2023
1 parent 5b354a1 commit 22170b2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/development-guide-toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ the various packages' Haddocks.
* [Primitives](primitives.md)
* [Database ops](database.md)
* [Benchmarking](benchmarking.md)
* [WebAssembly support](wasm.md)
39 changes: 39 additions & 0 deletions docs/wasm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# WebAssembly (Wasm) support

**Note**: WebAssembly support is currently very preliminary.

For horizontal scalability reasons, we would like to run the `primer`
and `primer-api` packages in the student's browser, rather than on a
backend server. Therefore, we'd like to compile these packages to a
`wasm32-wasi` target and call the (native) Primer API from TypeScript.

Currently, we can compile these two packages to `wasm32-wasi`, but
with the following caveats:

1. Neither `haskell.nix` nor `nixpkgs.haskellPackages` support the
`wasm32-wasi` cross-target at the moment, so we can only build Wasm
targets directly via `wasm32-wasi-cabal` and `wasm32-wasi-ghc`. For
interactive development, we provide a special `nix develop` shell
which provides the necessary tools:

```sh
nix develop .#wasm
```

2. Once you're in the special Wasm shell, it's advisable to use the
special `wasm32` `Makefile` targets. To build the libraries, run:

```sh
make wasm32-configure
make wasm32-build
```

To build the tests and run them using the `wasmtime` runtime, run:

```sh
make wasm32-test
```

The `wasm32-test`, in particular, needs to run several steps that
you'd otherwise need to run by hand in order to work around
`wasmtime` issues.

0 comments on commit 22170b2

Please sign in to comment.