Is there a minimal example project which exports a Wasm function from Roc to be used by JavaScript on a web page? I'm completely new to Roc; I have been reading the tutorial so far.
I found <https://github.com/lukewilliamboswell/roc-wasm4> but I'm a bit lost with it. I would benefit from a simpler demo project which has a minimal number of files, something similar to <https://www.roc-lang.org/examples/GoPlatform/README>.
I will also need to figure out how to transfer ArrayBuffers from and to JavaScript eventually.
@Luke Boswell do you have a demo wasm project?
TBH it's not easy to do with the current Roc compiler implementation in rust. There's some really hairy parts. My zig template is probably the simplest and closest to what you're looking for, https://github.com/lukewilliamboswell/roc-platform-template-zig. It's not designed for the browser though.
The new Zig compiler will be much nicer for this... and we're very very close now to building platforms again. I'm planning to build a minimal WASM browser platform as the first or second thing out the gate. :smiley:
So if you can wait some weeks/months then that will be a much nicer experience.
I've got a WASI thing, but my pure WASM platforms are super hacky.
Oh, I should mention it's actually doable if you're ok to let Zig do the final linking etc. If you use the roc cli to build the app into an object first, and then use zig to do the linking, it's really easy to do today. But I don't have anything simpler than roc-wasm4 sorry.
Alright, I'm in no hurry. I might prototype the algorithm in slow TypeScript and port it into Roc at a later time. Porting an existing implementation might also end up being an easier way to learn the language. Thanks for the info!
@ion Ion,
Working through the same WASM examples from Luke and I also struggle a bit
https://github.com/lukewilliamboswell/roc-wasm4
But I did see the following and it is great document
https://dusty.phillips.codes/2024/08/11/build-a-wasm-compiler-in-roc-part-1-introduction/
Best regards
Gottfried
Last updated: Aug 17 2025 at 12:14 UTC