15 stable releases (7 major)

Uses new Rust 2024

34.0.1 Jun 24, 2025
33.0.1 Jun 24, 2025
32.0.1 Jun 24, 2025
31.0.0 Mar 20, 2025
27.0.0 Nov 20, 2024

#542 in Configuration

Download history 370/week @ 2025-03-17 141/week @ 2025-03-24 143/week @ 2025-03-31 97/week @ 2025-04-07 62/week @ 2025-04-14 610/week @ 2025-04-21 194/week @ 2025-04-28 214/week @ 2025-05-05 155/week @ 2025-05-12 243/week @ 2025-05-19 74/week @ 2025-05-26 45/week @ 2025-06-02 61/week @ 2025-06-09 262/week @ 2025-06-16 470/week @ 2025-06-23 68/week @ 2025-06-30

867 downloads per month
Used in wasmtime-cli

Apache-2.0 WITH LLVM-exception

3MB
49K 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},
    Config, Engine, Result, Store,
};
use wasmtime_wasi::p2::{IoView, WasiCtx, WasiCtxBuilder, WasiView};
use wasmtime_wasi_config::{WasiConfig, WasiConfigVariables};

#[tokio::main]
async fn main() -> Result<()> {
    let mut config = Config::new();
    config.async_support(true);
    let engine = Engine::new(&config)?;

    let mut store = Store::new(&engine, Ctx {
        table: ResourceTable::new(),
        wasi_ctx: WasiCtxBuilder::new().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 IoView for Ctx {
    fn table(&mut self) -> &mut ResourceTable { &mut self.table }
}
impl WasiView for Ctx {
    fn ctx(&mut self) -> &mut WasiCtx { &mut self.wasi_ctx }
}

Dependencies

~21–37MB
~651K SLoC