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:
-
Neither
haskell.nix
nornixpkgs.haskellPackages
support thewasm32-wasi
cross-target at the moment, so we can only build Wasm targets directly viawasm32-wasi-cabal
andwasm32-wasi-ghc
. For interactive development, we provide a specialnix develop
shell which provides the necessary tools:nix develop .#wasm
Note that the required tools are currently only available for
x86_64-linux
Nix systems, so the specialwasm
Nix shell only exists for that platform. -
Once you're in the special Wasm shell, it's advisable to use the special
Makefile.wasm32
. To build the WebAssembly targets, run:make -f Makefile.wasm32
And to run the tests using the
wasmtime
runtime, run:make -f Makefile.wasm32 test
-
We now have a very preliminary Wasm frontend for Primer. The goal of this frontend is to eventually replace the existing TypeScript frontend, but it's currently missing quite a bit of that implementation's functionality.
To run the Wasm frontend, use the following command from the special Wasm shell:
make -f Makefile.wasm32 serve-frontend
Then visit http://localhost:8000 in your browser.