Home

Awesome

<div align="center"> <h1><code>wasm-tools</code></h1>

<strong>A <a href="https://bytecodealliance.org/">Bytecode Alliance</a> project</strong>

<p> <strong>CLI and Rust libraries for low-level manipulation of WebAssembly modules</strong> </p> </div>

Installation

Precompiled artifacts built on CI are available for download for each release.

To build from source first install Rust for your platform and then use the included Cargo package manager to install:

$ cargo install --locked wasm-tools

Alternatively if you use cargo binstall then that can be used to install the precompiled artifacts instead:

$ cargo binstall wasm-tools

Installation can be confirmed with:

$ wasm-tools --version

Subcommands can be explored with:

$ wasm-tools help

Examples

Basic validation/printing/parsing:

# Validate a WebAssembly file
$ wasm-tools validate foo.wasm

# Validate a WebAssembly module in the text format, automatically converting to
# binary.
$ wasm-tools validate foo.wat

# Validate a WebAssembly file enabling an off-by-default feature
$ wasm-tools validate foo.wasm --features=exception-handling

# Validate a WebAssembly file with a default-enabled feature disabled
$ wasm-tools validate foo.wasm --features=-simd

# Print the text format of a module to stdout
$ wasm-tools print foo.wasm

# Convert a binary module to text
$ wasm-tools print foo.wasm -o foo.wat

# Convert a text module to binary
$ wasm-tools parse foo.wat -o foo.wasm

Simple mutation as well as piping commands together:

# Mutate a WebAssembly module and print its text representation to stdout
$ wasm-tools mutate foo.wasm -t

# Mutate a WebAssembly module with a non-default seed and validate that the
# output is a valid module.
$ wasm-tools mutate foo.wasm --seed 192 | wasm-tools validate

# Demangle Rust/C++ symbol names in the `name` section, strip all other custom
# sections, and then print out what binary sections remain.
$ wasm-tools demangle foo.wasm | wasm-tools strip | wasm-tools objdump

Working with components:

# Print the WIT interface of a component
$ wasm-tools component wit component.wasm

# Convert WIT text files to a binary-encoded WIT package, printing the result to
# stdout
$ wasm-tools component wit ./wit -t

# Convert a WIT document to JSON
$ wasm-tools component wit ./wit --json

# Round trip WIT through the binary-encoded format to stdout.
$ wasm-tools component wit ./wit --wasm | wasm-tools component wit

# Convert a core WebAssembly binary into a component. Note that this requires
# WIT metadata having previously been embedded in the core wasm module.
$ wasm-tools component new my-core.wasm -o my-component.wasm

# Convert a core WebAssembly binary which uses WASI to a component.
$ wasm-tools component new my-core.wasm -o my-component.wasm --adapt wasi_snapshot_preview1.reactor.wasm

CLI Conventions

There are a few conventions that all CLI commands adhere to:

Tools included

The wasm-tools binary internally contains a number of subcommands for working with wasm modules and component. Many subcommands also come with Rust crates that can be use programmatically as well:

CLIRust CratePlaygroundDescription
wasm-tools validatewasmparserValidate a WebAssembly file
wasm-tools parsewat and wastparseTranslate the WebAssembly text format to binary
wasm-tools printwasmprinterprintTranslate the WebAssembly binary format to text
wasm-tools smithwasm-smithGenerate a valid WebAssembly module from an input seed
wasm-tools mutatewasm-mutateMutate an input wasm file into a new valid wasm file
wasm-tools shrinkwasm-shrinkShrink a wasm file while preserving a predicate
wasm-tools dumpPrint debugging information about the binary format
wasm-tools objdumpPrint debugging information about section headers
wasm-tools stripRemove custom sections from a WebAssembly file
wasm-tools demangleDemangle Rust and C++ symbol names in the name section
wasm-tools composewasm-composeCompose wasm components together (deprecated)
wasm-tools component newwit-componentCreate a component from a core wasm binary
wasm-tools component witExtract a *.wit interface from a component
wasm-tools component embedEmbed a component-type custom section in a core wasm binary
wasm-tools component unbundleExtract core wasm modules from a component
wasm-tools metadata showwasm-metadataShow name and producer metadata in a component or module
wasm-tools metadata addAdd name or producer metadata to a component or module
wasm-tools addr2lineTranslate wasm offsets to filename/line numbers with DWARF
wasm-tools completionGenerate shell completion scripts for wasm-tools
wasm-tools json-from-wastConvert a *.wast file into JSON commands

The wasm-tools CLI contains useful tools for debugging WebAssembly modules and components. The various subcommands all have --help explainer texts to describe more about their functionality as well.

WebAssembly proposals

This repository strives to implement any standardized proposal to WebAssembly. All proposals that are Stage 4+ are enabled by default in validation. Support in the text format is always enabled at all times for all proposals.

Currently implemented proposals in this repository that are stage 4+ are:

These proposals are implemented but have not yet reached stage 4. This means they are disabled by default in validation and their implementation may change over time as the proposal evolves. Additionally the proposal may also have changed since these proposals were implemented, so there may be a mismatch too.

Libraries

As mentioned above many of the tools of the wasm-tools CLI have libraries implemented in this repository as well. These libraries are:

It's recommended to use the libraries directly rather than the CLI tooling when embedding into a separate project.

C/C++ bindings

Using the CMakeLists.txt in crates/c-api, wasm-tools can be used from the wasm-tools.h header. Note that these bindings do not comprehensively cover all the functionality of this repository at this time, but please feel free to contribute more if you find functions useful!

Versioning and Releases

This repository has both a CLI and a suite of crates that is published to crates.io (Rust's package manager). The versioning scheme used by this repository looks like:

Note that the Y of all the versions above will also match for any release of this repository. This versioning scheme is intended to reflect the stable nature of the CLI and the wat crate in terms of API stability. Other crates, however, all receive a major version bump that are not automatically considered API compatible on all releases. This reflects how WebAssembly itself is an evolving standard which is not an unchanging foundation. All of the crates in this repository are suitable for "production use" but be aware that API stability is not guaranteed over time. If you have difficulty upgrading versions please feel free to file an issue and we can help out.

Also, this repository does not currently have a strict release cadence. Releases are done on an as-needed basis. If you'd like a release done please feel free to reach out on Zulip, file an issue, leave a comment on a PR, or otherwise contact a maintainer.

For maintainers, the release process looks like:

That should be it, but be sure to keep an eye on CI in case anything goes wrong.

Contributing

See CONTRIBUTING.md for more information about contributing to this repository.

License

This project is triple licenced under the Apache 2/ Apache 2 with LLVM exceptions/ MIT licences. The reasoning for this is:

For more details see

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache 2/ Apache 2 with LLVM exceptions/ MIT licenses, shall be licensed as above, without any additional terms or conditions.