wazero has no runtime deps. This updates tools we use as well as dependencies used in comparison with other runtimes. Signed-off-by: Adrian Cole <adrian@tetrate.io>
969 B
969 B
Zig allocation example
This example shows how to pass strings in and out of a Wasm function defined in
Zig, built with zig build.
Ex.
$ go run greet.go wazero
wasm >> Hello, wazero!
go >> Hello, wazero!
greet.zig does a few things of interest:
- Uses
@ptrToIntto change a Zig pointer to a numeric type - Uses
[*]u8as an argument to take a pointer and slices it to build back a string
The Zig code exports "malloc" and "free", which we use for that purpose.
Notes
This example uses @panic() rather than unreachable to handle errors
since unreachable emits a call to panic only in Debug and ReleaseSafe
mode. In ReleaseFast and ReleaseSmall mode, it would lead into undefined
behavior.
If building wasm with a pre-release version of Zig 0.10.0, use -fstage1 to
avoid bugs in the new compiler.