Generate wat in Rust

I'm not asking about compiling Rust to wasm or compiling Rust to wat.

I want my rust code to generate Wat.

I want to generate the exprs in https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format

Is there some Rust crate for generating this? To clarify: I'm not asking about parsing/loading/compilingto wasm. I literally just want to generate wat on the fly.

One option for generating wat is Wasmtime which uses compilers to generate wat from Rust, C/C++ and AssemblyScript.

What WAT code you want to generate from Rust? WAT is a textual format and you can easily write it by hand on your favorite text editor.

It looks like binaryen-sys has a method for transforming a module AST into WAT: https://docs.rs/binaryen-sys/0.10.1/binaryen_sys/fn.BinaryenModuleWriteText.html

It's an unsafe interface, but it's the only thing I've found that writes WAT.

1 Like

Lucet has a rust api to compile and link code.
https://crates.io/crates/lucet-wasi-sdk

Example use in their tests:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.