9 stable releases

26.0.1 Nov 5, 2024
26.0.0 Oct 22, 2024
25.0.3 Nov 5, 2024
25.0.2 Oct 9, 2024
24.0.0 Aug 20, 2024

#1439 in WebAssembly

Download history 259/week @ 2024-10-23 232/week @ 2024-10-30 457/week @ 2024-11-06 97/week @ 2024-11-13 71/week @ 2024-11-20 29/week @ 2024-11-27 217/week @ 2024-12-04 120/week @ 2024-12-11 37/week @ 2024-12-18 53/week @ 2024-12-25 53/week @ 2025-01-01 178/week @ 2025-01-08 35/week @ 2025-01-15 15/week @ 2025-01-22 22/week @ 2025-01-29 100/week @ 2025-02-05

177 downloads per month
Used in 4 crates (2 directly)

Apache-2.0 WITH LLVM-exception

3MB
45K SLoC

Wasmtime's wasi-runtime-config Implementation

This crate provides a Wasmtime host implementation of the wasi-runtime-config API. With this crate, the runtime can run components that call APIs in wasi-runtime-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::{WasiCtx, WasiCtxBuilder, WasiView};
use wasmtime_wasi_runtime_config::{WasiRuntimeConfig, WasiRuntimeConfigVariables};

#[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_runtime_config_vars: WasiRuntimeConfigVariables::from_iter(vec![
            ("config_key1", "value1"),
            ("config_key2", "value2"),
        ]),
    });

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

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

    Ok(())
}

struct Ctx {
    table: ResourceTable,
    wasi_ctx: WasiCtx,
    wasi_runtime_config_vars: WasiRuntimeConfigVariables,
}

impl WasiView for Ctx {
    fn table(&mut self) -> &mut ResourceTable { &mut self.table }
    fn ctx(&mut self) -> &mut WasiCtx { &mut self.wasi_ctx }
}

Dependencies

~21–32MB
~619K SLoC