Hey just seeing this discussion on Wasm. In my Elm-in-Wasm project I originally built a back end that went directly to Wasm. But later I decided to go through C to make it easier to debug, and I could have kernel code in the C too, etc. Anyway I have a good understanding of how the instruction set works and that kind of thing, if that can be of use to people.
Regarding .wasm and .wat formats, there's a WebAssembly Binary Toolkit that has some useful tools including translating back and forth between the two.
There's also an optimizer there
are there rust bindings for that? I thought wasm was pretty rust-centered but maybe not?
The Wasm module is a data structure that I think more or less resembles an executable file like ELF or EXE. It has a data section and code sections and some tables and that kind of thing. Best resource I found for this was the spec itself, although that was a couple of years ago, maybe there's better stuff now. But this page shows you the module structure: https://webassembly.github.io/spec/core/syntax/modules.html
No I definitely wouldn't say Wasm is Rust-centred! If anything maybe the other way around
Rust does have good support for it
But a lot of the actual Wasm development is more geared towards C and C++. And if you're using LLVM anyway then that has a Wasm back end so that would be the way to do it. Zig has a Wasm back end.
I didn't use Rust for my project, only C. I did a tiny amount with Rust and Wasm like 2 or 3 years ago but can't remember now.
I did create a Haskell type definition to represent the Wasm module though
well sure we can go to wasm via llvm, but llvm is very slow
which is why we're also working on direct assembly backends
and would similarly ultimately like to emit wasm directly, for development purposes (a release/optimized build would still probably go via LLVM)
Right, I see
(moved this to its own topic!)
thanks for the wasm tips, Brian! :smiley:
Sure!
Looks like there are indeed Rust bindings for WABT, and it has struct definitions for a Wasm module etc. https://docs.rs/wabt/0.10.0/wabt/
Hey all! Getting started with roc and having trouble with compiling to wasm. Is there a simple (relatively recent) example of this? Is there a dedicated wasm platform?
I have found repos that are 2 years old, using zig, but I think the wasm story is much better now. Any examples / references would be appreciated!
Thanks
I think most wasm platforms have been bespoke made for single apps. I don't think we have any flexible platforms. That said, we may have more recent examples. Oh, I guess, wasm4 is technically slightly flexible and wasm, but it isn't hooked into the browser directly. It is for a game engine.
There is an example of compilation to wasm (frontend stuff though)
https://github.com/lukewilliamboswell/roc-experiment-js-dom/blob/a0bf524d1d80ff8a36128611aa4de21c6d465bf7/run-web.sh#L15
Last updated: Jul 05 2025 at 12:14 UTC