Stream: beginners

Topic: Minimal Wasm example


view this post on Zulip ion (Aug 02 2025 at 20:51):

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.

view this post on Zulip Brendan Hansknecht (Aug 02 2025 at 21:03):

@Luke Boswell do you have a demo wasm project?

view this post on Zulip Luke Boswell (Aug 02 2025 at 21:03):

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.

view this post on Zulip Luke Boswell (Aug 02 2025 at 21:04):

I've got a WASI thing, but my pure WASM platforms are super hacky.

view this post on Zulip Luke Boswell (Aug 02 2025 at 21:05):

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.

view this post on Zulip ion (Aug 02 2025 at 21:16):

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!

view this post on Zulip Gottfried Zojer (Aug 03 2025 at 03:08):

@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