wa-lang.org/wazero@v1.0.2/examples/allocation/zig/README.md (about) 1 ## Zig allocation example 2 3 This example shows how to pass strings in and out of a Wasm function defined in 4 Zig, built with `zig build`. 5 6 ```bash 7 $ go run greet.go wazero 8 wasm >> Hello, wazero! 9 go >> Hello, wazero! 10 ``` 11 12 [greet.zig](testdata/greet.zig) does a few things of interest: 13 * Uses `@ptrToInt` to change a Zig pointer to a numeric type 14 * Uses `[*]u8` as an argument to take a pointer and slices it to build back a 15 string 16 17 The Zig code exports "malloc" and "free", which we use for that purpose. 18 19 ### Notes 20 21 This example uses `@panic()` rather than `unreachable` to handle errors 22 since `unreachable` emits a call to panic only in `Debug` and `ReleaseSafe` 23 mode. In `ReleaseFast` and `ReleaseSmall` mode, it would lead into undefined 24 behavior. 25 26 If building wasm with a pre-release version of Zig 0.10.0, use `-fstage1` to 27 avoid [bugs in the new compiler][1]. 28 29 [1]: https://github.com/ziglang/zig/wiki/Self-Hosted-Compiler-Upgrade-Guide#is-it-time-to-upgrade