Stream: wasm

Topic: Resources to learn how to generate WebAssembly directly?


view this post on Zulip Brett Cannon (Jul 04 2024 at 16:55):

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?

This finishes our high-level tour of the major components of the WebAssembly text format and how they get reflected in the WebAssembly JS API.

view this post on Zulip Daniel Macovei (Jul 04 2024 at 17:09):

A friend recently told me they enjoyed this book https://wasmgroundup.com/

A book about WebAssembly โ€” from hand crafting bytecodes to a real compiler for a simple programming language.

view this post on Zulip Daniel Macovei (Jul 04 2024 at 17:09):

I don't think it covers the Component Model though

view this post on Zulip Alex Crichton (Jul 08 2024 at 14:18):

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

view this post on Zulip Brett Cannon (Jul 08 2024 at 18:13):

I'm starting to think targeting WAT isn't a bad idea; I can use wat to then compile to the binary format.

view this post on Zulip Victor Adossi (Jul 09 2024 at 15:33):

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.

Walrus is a WebAssembly transformation library ๐ŸŒŠ๐Ÿ˜. Contribute to rustwasm/walrus development by creating an account on GitHub.
Walrus is a WebAssembly transformation library ๐ŸŒŠ๐Ÿ˜. Contribute to rustwasm/walrus development by creating an account on GitHub.

Last updated: Nov 22 2024 at 16:03 UTC