Files
wazero/examples/allocation
Crypt Keeper 429334cf98 Renames ModuleBuilder to HostModuleBuilder and drops memory and globals (#812)
We at one point considered making `ModuleBuilder` create complete
WebAssembly binaries. However, we recently spun out
[wabin](https://github.com/tetratelabs/wabin), which allows this.

Meanwhile, the features in `ModuleBuilder` were confusing and misused.
For example, the only two cases memory was exported on GitHub were done
by accident. This is because host functions act on the guest's memory,
not their own.

Hence, this removes memory and globals from host side definitions, and
renames the type to HostModuleBuilder to clarify this is not ever going
to be used to construct normal Wasm binaries.

Most importantly, this simplifies the API and reduces a lot of code. It
is important to make changes like this, particularly deleting any
experimental things that didn't end up useful.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-09-28 14:42:14 +08:00
..
2022-08-11 16:31:06 +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
  • Zig - Calls Wasm built with zig build

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 and Zig don't. 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.