This drops the text format (%.wat) and renames InstantiateModuleFromCode to InstantiateModuleFromBinary as it is no longer ambiguous. We decided to stop supporting the text format as it isn't typically used in production, yet costs a lot of work to develop. Given the resources available and the increased work added with WebAssembly 2.0 and soon WASI 2, we can't afford to spend the time on it. The old parser is used only internally and will eventually be moved to its own repository named watzero, possibly towards archival. See #59 Signed-off-by: Adrian Cole <adrian@tetrate.io>
TinyGo allocation example
This example shows how to pass strings in and out of a Wasm function defined
in TinyGo, built with tinygo build -o greet.wasm -scheduler=none -target=wasi greet.go
Ex.
$ go run greet.go wazero
wasm >> Hello, wazero!
go >> Hello, wazero!
Under the covers, greet.go does a few things of interest:
- Uses
unsafe.Pointerto change a Go pointer to a numeric type. - Uses
reflect.StringHeaderto build back a string from a pointer, len pair. - Relies on TinyGo not eagerly freeing pointers returned.
Go does not export allocation functions, but when TinyGo generates WebAssembly, it exports "malloc" and "free", which we use for that purpose. These are not documented, so not necessarily a best practice. See the following issues for updates:
- WebAssembly exports for allocation: https://github.com/tinygo-org/tinygo/issues/2788
- Memory ownership of TinyGo allocated pointers: https://github.com/tinygo-org/tinygo/issues/2787
Note: While folks here are familiar with TinyGo, wazero isn't a TinyGo project. We hope this gets you started. For next steps, consider reading the TinyGo Using WebAssembly Guide or joining the #TinyGo channel on the Gophers Slack.