[ANN] Wasicaml - code emitter for WebAssembly


just want to repeat here what I already wrote in caml-list ([Caml-list] [ANN] wasicaml - a code emitter for OCaml targeting WebAssembly) - there is now a code generator for WebAssembly at

which is highly experimental. Any feedback welcome.



This looks extremely cool. Does this support (or plan to support) calling into the generated module from js, or calling external functions from OCaml?

I went ahead and made a minimal demo for browsers (copy-pasting the JavaScript from the repository plus a small wasi shim): GitHub - copy/wasicaml-demo

You can see it in action here: https://copy.sh/wasicaml-demo/

1 Like

For interfacing with JS (or the host environment in general) it is best to have some minimal C wrapper, e.g. put this into mylib.c:

value myFunction(value arg1);

and then declare on the OCaml side as usual, e.g. external myFunction : int -> int = "myFunction".

You can link mylib.o into the final executable, e.g. wasicaml ... -cclib mylib.o.

If you want to call OCaml from JS, you’d have to register callbacks.

Hope this helps (I can make a bigger and more complete example if needed).

Nice demo - but it took a while until I understood that the only effect is that it writes something into the console.