I'm curious to learn how to write "raw"/direct WebAssembly via Rust code (that would target WASI). I found https://crates.io/crates/wasm-encoder , but it talks about the various sections of a .wasm
file w/o explaining the various sections of the file. Is there a tutorial or something like the Rust Book for WebAssembly itself? The best I can find is https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format , but even that doesn't directly talk about things in the example given by wasm-encoder.
Or is the spec the only way to learn what I'm after?
A friend recently told me they enjoyed this book https://wasmgroundup.com/
I don't think it covers the Component Model though
I'd recommend reading over the core wasm spec yeah. You might find wasm-tools dump
on small files useful to help account for all the bytes in the file (it's pretty verbose output though). The wasm-encoder
crate definitely requires background knowledge of the wasm format itself to be useful, it's not written to be a friendly starter crate for sure
I'm starting to think targeting WAT isn't a bad idea; I can use wat
to then compile to the binary format.
Just in case you haven't seen it, walrus
is great for slicing and dicing/transforming modules.
In particular you might benefit from https://github.com/rustwasm/walrus/blob/main/examples/build-wasm-from-scratch.rs , though it's working with a module rather than a component, you could adapt to get where you need to be.
Last updated: Nov 22 2024 at 16:03 UTC