Stream: platform development

Topic: Targeting Wasm


view this post on Zulip Paul Young (Aug 14 2022 at 20:59):

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.

https://github.com/roc-lang/roc/tree/641daab02c90b446d8dfad302a8c57c6dfab9f0d/examples/platform-switching/web-assembly-platform

Thanks in advance.

view this post on Zulip Folkert de Vries (Aug 14 2022 at 21:01):

host.zig there defines the platform code. So the main function in that file is ultimately what you could invoke from JS

view this post on Zulip Folkert de Vries (Aug 14 2022 at 21:01):

or anything else that you expose there

view this post on Zulip Folkert de Vries (Aug 14 2022 at 21:01):

that host could also be written in rust/c/... that targets webassembly and has a C FFI

view this post on Zulip Brendan Hansknecht (Aug 14 2022 at 21:33):

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.

view this post on Zulip Folkert de Vries (Aug 14 2022 at 21:39):

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)

view this post on Zulip Paul Young (Aug 16 2022 at 04:46):

Thank you both!

view this post on Zulip Brian Carroll (Aug 16 2022 at 19:03):

You also need the --dev flag to get the Wasm development backend, right?

view this post on Zulip Brendan Hansknecht (Aug 16 2022 at 19:22):

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