Skip to content

Commit

Permalink
Rename wasi-runtime-config to wasi-config
Browse files Browse the repository at this point in the history
  • Loading branch information
iawia002 committed Oct 9, 2024
1 parent bc6b0fe commit f80bbf2
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 133 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ wasmtime-wast = { workspace = true, optional = true }
wasi-common = { workspace = true, default-features = true, features = ["exit", "tokio"], optional = true }
wasmtime-wasi = { workspace = true, default-features = true, optional = true }
wasmtime-wasi-nn = { workspace = true, optional = true }
wasmtime-wasi-runtime-config = { workspace = true, optional = true }
wasmtime-wasi-config = { workspace = true, optional = true }
wasmtime-wasi-keyvalue = { workspace = true, optional = true }
wasmtime-wasi-threads = { workspace = true, optional = true }
wasmtime-wasi-http = { workspace = true, optional = true }
Expand Down Expand Up @@ -210,7 +210,7 @@ wasmtime-wast = { path = "crates/wast", version = "=27.0.0" }
wasmtime-wasi = { path = "crates/wasi", version = "27.0.0", default-features = false }
wasmtime-wasi-http = { path = "crates/wasi-http", version = "=27.0.0", default-features = false }
wasmtime-wasi-nn = { path = "crates/wasi-nn", version = "27.0.0" }
wasmtime-wasi-runtime-config = { path = "crates/wasi-runtime-config", version = "27.0.0" }
wasmtime-wasi-config = { path = "crates/wasi-config", version = "27.0.0" }
wasmtime-wasi-keyvalue = { path = "crates/wasi-keyvalue", version = "27.0.0" }
wasmtime-wasi-threads = { path = "crates/wasi-threads", version = "27.0.0" }
wasmtime-component-util = { path = "crates/component-util", version = "=27.0.0" }
Expand Down Expand Up @@ -375,7 +375,7 @@ default = [
"wasi-nn",
"wasi-threads",
"wasi-http",
"wasi-runtime-config",
"wasi-config",
"wasi-keyvalue",

# Most features of Wasmtime are enabled by default.
Expand Down Expand Up @@ -424,7 +424,7 @@ disable-logging = ["log/max_level_off", "tracing/max_level_off"]
wasi-nn = ["dep:wasmtime-wasi-nn"]
wasi-threads = ["dep:wasmtime-wasi-threads", "threads"]
wasi-http = ["component-model", "dep:wasmtime-wasi-http", "dep:tokio", "dep:hyper"]
wasi-runtime-config = ["dep:wasmtime-wasi-runtime-config"]
wasi-config = ["dep:wasmtime-wasi-config"]
wasi-keyvalue = ["dep:wasmtime-wasi-keyvalue"]
pooling-allocator = ["wasmtime/pooling-allocator", "wasmtime-cli-flags/pooling-allocator"]
component-model = [
Expand Down
2 changes: 1 addition & 1 deletion ci/vendor-wit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ make_vendor "wasi-http" "
[email protected]
"

make_vendor "wasi-runtime-config" "runtime-config@c667fe6"
make_vendor "wasi-config" "config@f4d699b"

make_vendor "wasi-keyvalue" "keyvalue@219ea36"

Expand Down
8 changes: 4 additions & 4 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ wasmtime_option_group! {
pub threads: Option<bool>,
/// Enable support for WASI HTTP API (experimental)
pub http: Option<bool>,
/// Enable support for WASI runtime config API (experimental)
pub runtime_config: Option<bool>,
/// Enable support for WASI config API (experimental)
pub config: Option<bool>,
/// Enable support for WASI key-value API (experimental)
pub keyvalue: Option<bool>,
/// Inherit environment variables and file descriptors following the
Expand Down Expand Up @@ -346,8 +346,8 @@ wasmtime_option_group! {
///
/// This option can be further overwritten with `--env` flags.
pub inherit_env: Option<bool>,
/// Pass a wasi runtime config variable to the program.
pub runtime_config_var: Vec<KeyValuePair>,
/// Pass a wasi config variable to the program.
pub config_var: Vec<KeyValuePair>,
/// Preset data for the In-Memory provider of WASI key-value API.
pub keyvalue_in_memory_data: Vec<KeyValuePair>,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/test-programs/artifacts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn build_and_generate_tests() {
s if s.starts_with("nn_") => "nn",
s if s.starts_with("piped_") => "piped",
s if s.starts_with("dwarf_") => "dwarf",
s if s.starts_with("runtime_config_") => "runtime_config",
s if s.starts_with("config_") => "config",
s if s.starts_with("keyvalue_") => "keyvalue",
// If you're reading this because you hit this panic, either add it
// to a test suite above or add a new "suite". The purpose of the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use test_programs::proxy;
use test_programs::wasi::{
config::runtime,
config::store,
http::types::{Fields, IncomingRequest, OutgoingBody, OutgoingResponse, ResponseOutparam},
};

Expand All @@ -17,7 +17,7 @@ impl proxy::exports::wasi::http::incoming_handler::Guest for T {
ResponseOutparam::set(outparam, Ok(resp));

let out = body.write().expect("outgoing stream");
let config = runtime::get("hello").unwrap().unwrap();
let config = store::get("hello").unwrap().unwrap();
out.blocking_write_and_flush(config.as_bytes())
.expect("writing response");

Expand Down
8 changes: 8 additions & 0 deletions crates/test-programs/src/bin/config_get.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use test_programs::wasi::config::store;

fn main() {
let v = store::get("hello").unwrap().unwrap();
assert_eq!(v, "world");
let config = store::get_all().unwrap();
assert_eq!(config, [("hello".to_string(), "world".to_string())])
}
8 changes: 0 additions & 8 deletions crates/test-programs/src/bin/runtime_config_get.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/test-programs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ wit_bindgen::generate!({
",
path: [
"../wasi-http/wit",
"../wasi-runtime-config/wit",
"../wasi-config/wit",
"../wasi-keyvalue/wit",
],
world: "wasmtime:test/test",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "wasmtime-wasi-runtime-config"
name = "wasmtime-wasi-config"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository = "https://github.com/bytecodealliance/wasmtime"
license = "Apache-2.0 WITH LLVM-exception"
description = "Wasmtime implementation of the wasi-runtime-config API"
description = "Wasmtime implementation of the wasi-config API"

[lints]
workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! # Wasmtime's [wasi-runtime-config] Implementation
//! # Wasmtime's [wasi-config] Implementation
//!
//! This crate provides a Wasmtime host implementation of the [wasi-runtime-config]
//! 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-runtime-config] and provide configuration variables for the component.
//! [wasi-config] and provide configuration variables for the component.
//!
//! # Examples
//!
Expand All @@ -18,7 +18,7 @@
//! Config, Engine, Result, Store,
//! };
//! use wasmtime_wasi::{WasiCtx, WasiCtxBuilder, WasiView};
//! use wasmtime_wasi_runtime_config::{WasiRuntimeConfig, WasiRuntimeConfigVariables};
//! use wasmtime_wasi_config::{WasiConfig, WasiConfigVariables};
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
Expand All @@ -29,17 +29,17 @@
//! let mut store = Store::new(&engine, Ctx {
//! table: ResourceTable::new(),
//! wasi_ctx: WasiCtxBuilder::new().build(),
//! wasi_runtime_config_vars: WasiRuntimeConfigVariables::from_iter(vec![
//! wasi_config_vars: WasiConfigVariables::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)
//! // 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` ...
Expand All @@ -50,7 +50,7 @@
//! struct Ctx {
//! table: ResourceTable,
//! wasi_ctx: WasiCtx,
//! wasi_runtime_config_vars: WasiRuntimeConfigVariables,
//! wasi_config_vars: WasiConfigVariables,
//! }
//!
//! impl WasiView for Ctx {
Expand All @@ -59,7 +59,7 @@
//! }
//! ```
//!
//! [wasi-runtime-config]: https://github.com/WebAssembly/wasi-runtime-config
//! [wasi-config]: https://github.com/WebAssembly/wasi-config
//! [wasi:cli]: https://docs.rs/wasmtime-wasi/latest
//! [wasi:http]: https://docs.rs/wasmtime-wasi-http/latest

Expand All @@ -75,13 +75,13 @@ mod gen_ {
trappable_imports: true,
});
}
use self::gen_::wasi::config::runtime as generated;
use self::gen_::wasi::config::store as generated;

/// Capture the state necessary for use in the `wasi-runtime-config` API implementation.
/// Capture the state necessary for use in the `wasi-config` API implementation.
#[derive(Default)]
pub struct WasiRuntimeConfigVariables(HashMap<String, String>);
pub struct WasiConfigVariables(HashMap<String, String>);

impl<S: Into<String>> FromIterator<(S, S)> for WasiRuntimeConfigVariables {
impl<S: Into<String>> FromIterator<(S, S)> for WasiConfigVariables {
fn from_iter<I: IntoIterator<Item = (S, S)>>(iter: I) -> Self {
Self(
iter.into_iter()
Expand All @@ -91,7 +91,7 @@ impl<S: Into<String>> FromIterator<(S, S)> for WasiRuntimeConfigVariables {
}
}

impl WasiRuntimeConfigVariables {
impl WasiConfigVariables {
/// Create a new runtime configuration.
pub fn new() -> Self {
Default::default()
Expand All @@ -104,30 +104,30 @@ impl WasiRuntimeConfigVariables {
}
}

/// A wrapper capturing the needed internal `wasi-runtime-config` state.
pub struct WasiRuntimeConfig<'a> {
vars: &'a WasiRuntimeConfigVariables,
/// A wrapper capturing the needed internal `wasi-config` state.
pub struct WasiConfig<'a> {
vars: &'a WasiConfigVariables,
}

impl<'a> From<&'a WasiRuntimeConfigVariables> for WasiRuntimeConfig<'a> {
fn from(vars: &'a WasiRuntimeConfigVariables) -> Self {
impl<'a> From<&'a WasiConfigVariables> for WasiConfig<'a> {
fn from(vars: &'a WasiConfigVariables) -> Self {
Self { vars }
}
}

impl<'a> WasiRuntimeConfig<'a> {
/// Create a new view into the `wasi-runtime-config` state.
pub fn new(vars: &'a WasiRuntimeConfigVariables) -> Self {
impl<'a> WasiConfig<'a> {
/// Create a new view into the `wasi-config` state.
pub fn new(vars: &'a WasiConfigVariables) -> Self {
Self { vars }
}
}

impl generated::Host for WasiRuntimeConfig<'_> {
fn get(&mut self, key: String) -> Result<Result<Option<String>, generated::ConfigError>> {
impl generated::Host for WasiConfig<'_> {
fn get(&mut self, key: String) -> Result<Result<Option<String>, generated::Error>> {
Ok(Ok(self.vars.0.get(&key).map(|s| s.to_owned())))
}

fn get_all(&mut self) -> Result<Result<Vec<(String, String)>, generated::ConfigError>> {
fn get_all(&mut self) -> Result<Result<Vec<(String, String)>, generated::Error>> {
Ok(Ok(self
.vars
.0
Expand All @@ -137,10 +137,10 @@ impl generated::Host for WasiRuntimeConfig<'_> {
}
}

/// Add all the `wasi-runtime-config` world's interfaces to a [`wasmtime::component::Linker`].
/// Add all the `wasi-config` world's interfaces to a [`wasmtime::component::Linker`].
pub fn add_to_linker<T>(
l: &mut wasmtime::component::Linker<T>,
f: impl Fn(&mut T) -> WasiRuntimeConfig<'_> + Send + Sync + Copy + 'static,
f: impl Fn(&mut T) -> WasiConfig<'_> + Send + Sync + Copy + 'static,
) -> Result<()> {
generated::add_to_linker_get_host(l, f)?;
Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use anyhow::{anyhow, Result};
use test_programs_artifacts::{foreach_runtime_config, RUNTIME_CONFIG_GET_COMPONENT};
use test_programs_artifacts::{foreach_config, CONFIG_GET_COMPONENT};
use wasmtime::{
component::{Component, Linker, ResourceTable},
Store,
};
use wasmtime_wasi::{add_to_linker_async, bindings::Command, WasiCtx, WasiCtxBuilder, WasiView};
use wasmtime_wasi_runtime_config::{WasiRuntimeConfig, WasiRuntimeConfigVariables};
use wasmtime_wasi_config::{WasiConfig, WasiConfigVariables};

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

impl WasiView for Ctx {
Expand All @@ -32,8 +32,8 @@ async fn run_wasi(path: &str, ctx: Ctx) -> Result<()> {

let mut linker = Linker::new(&engine);
add_to_linker_async(&mut linker)?;
wasmtime_wasi_runtime_config::add_to_linker(&mut linker, |h: &mut Ctx| {
WasiRuntimeConfig::from(&h.wasi_runtime_config_vars)
wasmtime_wasi_config::add_to_linker(&mut linker, |h: &mut Ctx| {
WasiConfig::from(&h.wasi_config_vars)
})?;

let command = Command::instantiate_async(&mut store, &component, &linker).await?;
Expand All @@ -51,18 +51,16 @@ macro_rules! assert_test_exists {
};
}

foreach_runtime_config!(assert_test_exists);
foreach_config!(assert_test_exists);

#[tokio::test(flavor = "multi_thread")]
async fn runtime_config_get() -> Result<()> {
async fn config_get() -> Result<()> {
run_wasi(
RUNTIME_CONFIG_GET_COMPONENT,
CONFIG_GET_COMPONENT,
Ctx {
table: ResourceTable::new(),
wasi_ctx: WasiCtxBuilder::new().build(),
wasi_runtime_config_vars: WasiRuntimeConfigVariables::from_iter(vec![(
"hello", "world",
)]),
wasi_config_vars: WasiConfigVariables::from_iter(vec![("hello", "world")]),
},
)
.await
Expand Down
Loading

0 comments on commit f80bbf2

Please sign in to comment.