wasm-tools is a command-line toolkit for examining, converting, validating, and debugging WebAssembly modules and components. It can reveal metadata, extract a component’s WIT world, and wrap a module as a component. section 4.3 section 4.7
Common operations include:
- Inspect a binary with wasm-tools metadata show to identify whether it is a module or component and review build metadata. section 4.3
- Extract a component’s WIT with wasm-tools component wit to inspect imports, exports, worlds, and interface versions. section 4.7 section 4.2.1
- Convert a module with wasm-tools component new, optionally supplying an adapter component for Preview 1 to Preview 2 translation. section 4.3
Inspect and convert a Hello World module
Install the CLI with cargo install wasm-tools@1.227.1 --locked. Check a module using wasm-tools metadata show hello_world_guest.wasm, then create a wrapper with wasm-tools component new hello_world_guest.wasm -o hello_world_guest_component.wasm. Run wasm-tools metadata show on the result to confirm its component kind, and inspect its WIT with wasm-tools component wit hello_world_guest_component.wasm. The generated wrapper exposes an empty world unless the original module was rebuilt with WASI access; an adapter can translate Preview 1 WASI imports when creating the component. section 4.3 section 4.2.1
Listing 4.4 Output of wasm-tools component wit
package root:component {
world root {
import wasi:cli/environment@0.2.0;
import wasi:cli/exit@0.2.0;
import wasi:io/error@0.2.0;
import wasi:io/streams@0.2.0;
import wasi:cli/stdin@0.2.0;
import wasi:cli/stdout@0.2.0;
import wasi:cli/stderr@0.2.0;
import wasi:clocks/wall-clock@0.2.0;
import wasi:filesystem/types@0.2.0;
import wasi:filesystem/preopens@0.2.0;
export wasi:cli/run@0.2.0;
}
}
Use the complete WIT listing to see how a WASI 0.2 CLI component declares environment, filesystem, streams, clocks, and its wasi:cli/run export. section 4.2.1
