Files
wazero/examples/allocation
Crypt Keeper f0e05fb95b examples: adds rust build and WASI example (#676)
This fixes where our pull requests didn't check the rust source in
examples were valid. It also adds an example of wasi with rust.

This uses cargo-wasi because the default target creates almost 2MB of
wasm for a simple cat program.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-08 10:49:50 +08:00
..
2022-07-06 16:30:31 +08:00

Allocation examples

The examples in this directory deal with memory allocation concerns in WebAssembly, e.g. How to pass strings in and out of WebAssembly functions.

$ go run greet.go wazero
wasm >> Hello, wazero!
go >> Hello, wazero!

While the below examples use strings, they are written in a way that would work for binary serialization.

  • Rust - Calls Wasm built with cargo build --release --target wasm32-unknown-unknown
  • TinyGo - Calls Wasm built with tinygo build -o X.wasm -scheduler=none --no-debug -target=wasi X.go

Note: Each of the above languages differ in both terms of exports and runtime behavior around allocation, because there is no WebAssembly specification for it. For example, TinyGo exports allocation functions while Rust does not. Also, Rust eagerly collects memory before returning from a Wasm function while TinyGo does not.

We still try to keep the examples as close to the same as possible, and highlight things to be aware of in the respective source and README files.