Module bindings

Module bindings 

Source
Available on crate feature p3 only.
Expand description

Auto-generated bindings for WASI interfaces.

This module contains the output of the bindgen! macro when run over the wasi:cli/imports world.

§Examples

If you have a WIT world which refers to WASI interfaces you probably want to use this modules’s bindings rather than generate fresh bindings. That can be done using the with option to bindgen!:

use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView};
use wasmtime::{Result, Engine, Config};
use wasmtime::component::{Linker, HasSelf, ResourceTable};

wasmtime::component::bindgen!({
    inline: "
        package example:wasi;

        // An example of extending the `wasi:cli/command` world with a
        // custom host interface.
        world my-world {
            include wasi:cli/command@0.3.0-rc-2025-09-16;

            import custom-host;
        }

        interface custom-host {
            my-custom-function: func();
        }
    ",
    path: "src/p3/wit",
    with: {
        "wasi": wasmtime_wasi::p3::bindings,
    },
    require_store_data_send: true,
});

struct MyState {
    ctx: WasiCtx,
    table: ResourceTable,
}

impl example::wasi::custom_host::Host for MyState {
    fn my_custom_function(&mut self) {
        // ..
    }
}

impl WasiView for MyState {
    fn ctx(&mut self) -> WasiCtxView<'_> {
        WasiCtxView{
            ctx: &mut self.ctx,
            table: &mut self.table,
        }
    }
}

fn main() -> Result<()> {
    let mut config = Config::default();
    config.async_support(true);
    config.wasm_component_model_async(true);
    let engine = Engine::new(&config)?;
    let mut linker: Linker<MyState> = Linker::new(&engine);
    wasmtime_wasi::p3::add_to_linker(&mut linker)?;
    example::wasi::custom_host::add_to_linker::<_, HasSelf<_>>(&mut linker, |state| state)?;

    // .. use `Linker` to instantiate component ...

    Ok(())
}

Modules§

cli
clocks
exports
filesystem
random
sockets

Structs§

Command
Bindings to execute and run a wasi:cli/command.
CommandIndices
Auto-generated bindings for index of the exports of command.
LinkOptions
Link-time configurations.