Wazero's "github.com/tetratelabs/wazero/imports/go" package allows you to run
a %.wasm
file compiled by Go. See https://wazero.io/languages/go/ for more.
When GOOS=js
and GOARCH=wasm
, Go's compiler targets WebAssembly 1.0
Binary format (%.wasm).
Ex.
GOOS=js GOARCH=wasm go build -o cat.wasm .
After compiling cat.wasm
with wazero.Runtime's CompileModule
, Run it.
Under the scenes, the compiled Wasm calls host functions that support the runtime.GOOS. This is similar to what is implemented in wasm_exec.js.
Go defines js "EXPERIMENTAL... exempt from the Go compatibility promise." Accordingly, wazero cannot guarantee this will work from release to release, or that usage will be relatively free of bugs. Due to this and the relatively high implementation overhead, most will choose TinyGo instead.