wit-component is a crate for creating and interacting with WebAssembly
components based on the component model proposal.
wit-component crate is available through the
wasm-tools CLI suite under
# Create a component from the input core wasm module
$ wasm-tools component new core.wasm -o component.wasm
# Extract a `*.wit` interface from a component
$ wasm-tools component wit component.wasm
Creates WebAssembly component binaries from input core WebAssembly modules. Input modules communicate with the canonical ABI to imported and exported interfaces described with
*.witfiles. The wit interface is either embedded directly in the core wasm binary.
Supports "adapters" which can be used to bridge legacy core WebAssembly imported functions into component model functions. Adapters are themselves core wasm binaries which will be embedded into the final component. An adapter's exports can be imported by the main core wasm binary and the adapter can then call component model imports.
*.witinterface can be extracted from an existing component to see the interface that it exports and intends to import.
Note that this crate is intended to be a low-level detail of tooling for
components. Developers will not necessarily interact with this tooling
day-to-day, instead using wrappers such as
will automatically execute
wit-component to produce component binaries.
wit-component supports the wasm-based encoding of a WIT package:
# The output `demo.wasm` is a valid component binary
# The `*.wit` file can be recovered from the `demo.wasm` as well
Toolchain authors can use
wit-component to embed this component types section
into a core wasm binary. For a small demo here a raw
*.wat wasm text file will
be used where the
demo.wit argument is specified manually, however.
# See that there's a new `component-type` custom section
# Convert the core wasm into a component now
# Like before the output `demo.wasm` is a valid component binary
# Additionally like before the `*.wit` interface can still be extracted
demo.component.wasm can now be shipped to a component runtime or
embedded into hosts.