This is a native Rust CLI application that can run WebAssembly Components of the adder
world,
defined in examples/tutorial/wit/adder/world.wit
, using WebAssembly Interface Types ("WIT").
The adder
world exports an interface called add
which defines an function that takes two unsigned and adds them:
package docs:adder@0.1.0;
interface add {
add: func(x: u32, y: u32) -> u32;
}
world adder {
export add;
}
The application uses WebAssembly ecosystem crates (e.g. wasmtime
) to generate Rust bindings, instantiate WASI worlds, and
executes the exported add
function (docs:adder/add.add
) of a provided component.
This host binary takes in two unsigned 32bit integers (u32
) operands and a path to a component. This host then:
- Loads the component from the given path
- Instantiates it as an implementer of the
adder
world - Executes the
add
function exported by the component - Prints the result
If running with cargo
(part of the Rust toolchain), then you should see output like the following:
$ cargo run --release -- 1 2 add.wasm
1 + 2 = 3
Note
add.wasm
is available in this folder, but can be replaced with your own built WebAssembly component
at any time (written in any language that supports WebAssembly Components), given that it satisfies
the adder
world described above.