62 stable releases (18 major)

Uses new Rust 2024

new 45.0.1 Jun 5, 2026
44.0.2 May 21, 2026
43.0.2 Apr 30, 2026
43.0.0 Mar 20, 2026
27.0.0 Nov 20, 2024

#80 in #linker

Download history 134/week @ 2026-03-03 1364/week @ 2026-03-10 1752/week @ 2026-03-17 1763/week @ 2026-03-24 2625/week @ 2026-03-31 1989/week @ 2026-04-07 2017/week @ 2026-04-14 673/week @ 2026-04-21 371/week @ 2026-04-28 388/week @ 2026-05-05 833/week @ 2026-05-12 8688/week @ 2026-05-19 11882/week @ 2026-05-26 12347/week @ 2026-06-02

33,822 downloads per month
Used in 5 crates (3 directly)

Apache-2.0 WITH LLVM-exception

4.5MB
70K SLoC

Wasmtime's wasi-config Implementation

This crate provides a Wasmtime host implementation of the wasi-config API. With this crate, the runtime can run components that call APIs in wasi-config and provide configuration variables for the component.

Examples

The usage of this crate is very similar to other WASI API implementations such as wasi:cli and wasi:http.

A common scenario is getting runtime-passed configurations in a wasi:cli component. A standalone example of doing all this looks like:

use wasmtime::{
    component::{Linker, ResourceTable},
    Engine, Result, Store,
};
use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView};
use wasmtime_wasi_config::{WasiConfig, WasiConfigVariables};

#[tokio::main]
async fn main() -> Result<()> {
    let engine = Engine::default();

    let mut store = Store::new(&engine, Ctx {
        table: ResourceTable::new(),
        wasi_ctx: WasiCtx::builder().build(),
        wasi_config_vars: WasiConfigVariables::from_iter(vec![
            ("config_key1", "value1"),
            ("config_key2", "value2"),
        ]),
    });

    let mut linker = Linker::<Ctx>::new(&engine);
    wasmtime_wasi::p2::add_to_linker_async(&mut linker)?;
    // add `wasi-config` world's interfaces to the linker
    wasmtime_wasi_config::add_to_linker(&mut linker, |h: &mut Ctx| {
        WasiConfig::from(&h.wasi_config_vars)
    })?;

    // ... use `linker` to instantiate within `store` ...

    Ok(())
}

struct Ctx {
    table: ResourceTable,
    wasi_ctx: WasiCtx,
    wasi_config_vars: WasiConfigVariables,
}

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

Dependencies

~23MB
~496K SLoC