Wasmtime
Overview
The wasmCloud host serves as a runtime environment and uses Wasmtime as the underlying WebAssembly (Wasm) runtime. The runtime implements the virtual instruction set architecture (ISA) targeted by Wasm binaries.
Wasmtime is an open source WebAssembly runtime hosted by the Bytecode Alliance and designed for use either as part of a larger stack or as a standalone runtime, running across a variety of operating systems and architectures. Wasmtime supports the WebAssembly standard as well as the WebAssembly System Interface (WASI) and the Component Model.
In wasmCloud, Wasmtime provides a flexible production-grade runtime designed for defense-in-depth security.
Wasmtime serves a similar role to a container runtime such as containerd on a Kubernetes node, but don't put too much weight on the analogy: components are not containers, and using a dedicated WebAssembly runtime enables wider ecosystem reuse.
Using Wasmtime for local development
Components that run in wasmCloud will also run in Wasmtime with little or no configuration, since wasmCloud utilizes and maintains compatibility with standards like the Component Model, WASI, and WASI interfaces like wasi-http
. In some cases, developers may wish to test components against standalone Wasmtime.
To install Wasmtime on Linux or macOS run:
curl https://wasmtime.dev/install.sh -sSf | bash
Users on Windows and other operating systems can download Wasmtime from the GitHub repository's Releases page.
For a simple example of running wasmCloud components with Wasmtime, you can create a new component from the "Hello world" template for any language:
wash new component hello
Choose the language for your template, navigate into the project directory with cd hello
, and then run:
wash build
Now that you've built a simple HTTP component, you can run it using Wasmtime's serve
subcommand:
wasmtime serve -S cli=y build/http_hello_world_s.wasm
Serving HTTP on http://0.0.0.0:8080/
The -S
argument enables you to configure Wasmtime's use of WASI, and cli=y
enables support for WASI CLI APIs.
In a new terminal tab, you can curl
against the component:
curl localhost:8080
Hello from Rust!
The component functions exactly the same in Wasmtime as we would expect in wasmCloud.
Composition and the runtime
WebAssembly components can be composed, meaning that they can be combined into a single component. Inside the encapsulating component, the constituent components link imports and exports, fulfilling one another's dependencies and otherwise communicating in order to execute the functionality of the greater application.
Component foo and component bar were composed at build-time into a single component—when the composed component runs, Wasmtime resolves the links between components foo and bar.
For more information, see Linking Components and Linking at Build.
Further reading
- For more information, see the Wasmtime documentation.
- For more WebAssembly ecosystem tooling, see Useful WebAssembly Tools.