liveBook · Manning

Wasm-tools

As explained in Server-Side WebAssembly

wasm-tools is a command-line toolkit for inspecting, manipulating, and validating WebAssembly modules and components, including extracting WIT interfaces.

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

How Server-Side WebAssembly covers it

How deep it goes
Explains exact CLI commands and outputs for metadata and WIT inspection, but stops short of implementing host behavior.
Examples
Uses Hello World binaries, metadata output, component conversion, extracted WIT worlds, and Preview 1 adapter commands.
What it assumes
Assumes a WebAssembly binary and basic module-versus-component terminology while demonstrating installation and inspection from zero.
What you can do after
Diagnose/debug with it by identifying binary kinds, reviewing metadata, extracting WIT interfaces, and converting modules into components.
How it connects
Connects WebAssembly modules, WebAssembly components, WIT, WASI 0.2, component adapters, and Wasmtime.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Server-Side WebAssembly. The section links point to the parts of the book it draws on.