Hi :wave:
I’m curious about the state of targeting Wasm with Roc.
I’ve looked at the following example and it seems like the --target=wasm32
flag may be all that’s needed to get started.
However, there’s a host.zig
file in there and I’m unsure how that relates to everything.
Thanks in advance.
host.zig
there defines the platform code. So the main function in that file is ultimately what you could invoke from JS
or anything else that you expose there
that host could also be written in rust/c/... that targets webassembly and has a C FFI
Just to add on here, Roc on wasm works quite well, but there really are no platforms yet. No one has built something equivalent of the elm architecture for Roc targetting wasm.
I, about a month ago, wrote an emulator for a MOS6502 cpu in Roc targeting wasm. Followed along with this post that was benchmarking the same solution in multiple languages. They were unable to get any examples faster than JS. Roc was able to run multiple times faster than JS. My Roc implementation is here, if you are at all interested. Feel free to reach out if you have any specific questions or want some help setting up a wasm platform.
also, if you go down this path, --target=wasm32
uses our wasm dev backend. it is built for fast compile times, and feature-compatible with our main llvm backend. If you runtime performance ever becomes a problem, then we can also target webassembly through llvm. (this also has feature parity with the "normal" backends)
Thank you both!
You also need the --dev
flag to get the Wasm development backend, right?
Unless something changed since I worked on wasm stuff, yes. You need --target=wasm32
and --dev
to get the dev wasm backend
Last updated: Jul 05 2025 at 12:14 UTC