Wasmtime
Wasmtime is the reference implementation of the Component Model. It supports running components that implement the wasi:cli/command
world and serving components that implement the wasi:http/proxy
world. Wasmtime can also invoke functions exported from a component.
Running command components with Wasmtime
To run a command component with Wasmtime, execute:
wasmtime run <path-to-wasm-file>
If you are using an older version of
wasmtime
, you may need to add the--wasm component-model
flag to specify that you are running a component rather than a core module.
By default, Wasmtime denies the component access to all system resources. For example, the component cannot access the file system or environment variables. See the Wasmtime guide for information on granting access, and for other Wasmtime features.
Running HTTP components with Wasmtime
You can now execute components that implement the HTTP proxy world with the wasmtime serve
subcommand. The Wasmtime CLI supports serving these components as of v14.0.3
.
To run a HTTP component with Wasmtime, execute:
wasmtime serve <path-to-wasm-file>
Try out building and running HTTP components with one of these tutorials
-
Hello WASI HTTP tutorial - build and serve a simple Rust-based HTTP component
-
HTTP Auth Middleware tutorial - compose a HTTP authentication middleware component with a business logic component
Running components with custom exports
As of Wasmtime Version 33.0.0, there is support for invoking components with custom exports.
As an example, if your component exports a function add
which takes two numeric arguments, you can make use of this feature with the following command.
wasmtime run --invoke 'foo(1, 2)' <path-to-wasm-file>
Make sure to wrap your invocation in single quotes abd to include parentheses, even if your function doesn't take any arguments. For a full list of ways to represent the various wit types when passing arguments to your exported function, visit the WAVE repo.