You can "run" a component by calling one of its exports. In some cases, this requires a custom host. For "command" components, though, you can use the
wasmtime command line. This can be a convenient tool for testing components and exploring the component model. Other runtimes are also available - see the "Runtimes" section of the sidebar for more info.
A "command" component is one that exports the
wasi:cli/runinterface, and imports only interfaces listed in the
You must use a recent version of
v14.0.0 or greater), as earlier releases of the
wasmtime command line do not include component model support.
If you build the
wasmtimeCLI from source, you must pass
--features component-modelto the build command.
To run your component, run:
wasmtime run --wasm component-model <path-to-wasm-file>
If you're writing a library-style component - that is, one that exports a custom API - then you can run it in
wasmtime by writing a "command" component that imports and invokes your custom API. By composing the command and the library, you can exercise the library in
Write your library component. The component's world (
.witfile) must export an interface. (Do not export functions directly, only interfaces.) See the language support guide for how to implement an export.
Build your library component to a
Write your command component. The component's world (
.witfile) must import the interface exported from the library. Write the command to call the library's API. See the language support guide for how to call an imported interface.
Build your command component to a
.wasmfile. You will not be able to run this in
wasmtimeyet, as its imports are not yet satisfied.
Compose your command component with your library component by running
wasm-tools compose <path/to/command.wasm> -d <path/to/library.wasm> -o main.wasm.
Run the composed component using
wasmtime run --wasm component-model main.wasm
See Composing Components for more details.