Skip to content

eliben/watgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

514 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

watgo

CI pkg.go.dev


Logo

WebAssembly Toolkit for Go (watgo) to parse WASM text or decode WASM binary into internal data structures, allowing conversions, validation, and testing-oriented execution.

WASM feature support and proposals

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.

Installation

To install the CLI into your Go bin directory:

go install github.com/eliben/watgo/cmd/watgo@latest

To run it directly from a checkout without installing:

go run ./cmd/watgo

To run it straight from the module path without installing:

go run github.com/eliben/watgo/cmd/watgo@latest

Go API

The 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.

Logo

CLI

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.wasm

For full command-line help, run:

watgo help

Testing

Run 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.

License

The source code of watgo is in the public domain. Certain vendored test scripts retain their original licenses:

About

WebAssembly Toolkit for Go

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages