WebAssembly Toolkit for Go (watgo) to parse WASM text or decode WASM binary into internal data structures, allowing conversions, validation, and testing-oriented execution.
Initially, we aim to support all the finished proposals without any flags or feature selection. Finished proposals are part of the WASM spec.
If there's a request to support active proposals, we'll consider employing explicit feature flags to gate this support.
To install the CLI into your Go bin directory:
go install github.com/eliben/watgo/cmd/watgo@latestTo run it directly from a checkout without installing:
go run ./cmd/watgoTo run it straight from the module path without installing:
go run github.com/eliben/watgo/cmd/watgo@latestThe public Go API is documented on pkg.go.dev,
including runnable examples for the high-level functions in package watgo.
Runtime support is available in package
wasmvm. wasmvm is a
small interpreter for validated wasmir.Module values; it can instantiate
modules, call exported functions and provide Go callbacks for function imports.
It is intended for testing and experimentation, not for high-performance wasm
execution.
watgo currently provides basic parse, print, validate, and
interpret subcommands.
Where applicable, for supported subcommands and flags, the CLI aims to stay
compatible with wasm-tools.
Examples:
# Compile WAT text to a WASM binary file.
watgo parse input.wat -o output.wasm
# Validate a WAT file.
watgo validate input.wat
# Validate a WASM binary.
watgo validate input.wasm
# Instantiate a module and invoke an exported function with wasmvm.
watgo interpret input.wat --invoke add 3 5
# Provide simple numeric host printing imports while interpreting.
# Run 'watgo help interpret' for more details on how this works.
watgo interpret input.wat --host-print --invoke run
# Read WAT from stdin and write WASM to stdout.
cat input.wat | watgo parse > output.wasmFor full command-line help, run:
watgo helpRun the full test suite with:
go test ./...Some of the end-to-end tests execute compiled modules under Node.js, so Node is
required for the full suite (set the env var WATGO_NODE_TESTS=0 to disable
all Node-dependent tests). Selected spec and WABT-style execution coverage
also runs through wasmvm.
For more detail on the different test sets and how to refresh them from
upstream, see tests/README.md.
The source code of watgo is in the public domain. Certain vendored test scripts retain their original licenses:
-
tests/wasmspec- Source: https://github.com/WebAssembly/spec/
- License: Apache License 2.0
- See:
tests/wasmspec/LICENSE
-
tests/wabt-interp- Source: https://github.com/WebAssembly/wabt
- License: Apache License 2.0
- See:
tests/wabt-interp/LICENSE

