Skip to content

Commit

Permalink
Rename wasi:config/runtime to wasi:config/store (#100)
Browse files Browse the repository at this point in the history
The `wasi:config/runtime` interface was renamed upstream to
`wasi:config/store`. The repository was also renamed from
github.com/WebAssembly/wasi-runtime-config to
github.com/WebAssembly/wasi-config, cementing the shift away from
"runtime".

This commit replaces the support for the runtime interface and replaces
it with the functionally equivalent store interface. It also removes
references to "runtime" config in the readme and CLI help.

Since the interface is still draft and support labeled as experimental,
backwards compatibility is not preserved.

Signed-off-by: Scott Andrews <[email protected]>
  • Loading branch information
scothis authored Nov 20, 2024
1 parent 4ea3e76 commit 0948ede
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 237 deletions.
369 changes: 189 additions & 180 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ clap = { version = "4", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
toml = "0.8"
walrus = "0.22.0"
wasm-compose = "0.218"
wasm-compose = "0.219"
wasm-metadata = "0.217"
wasm-opt = { version = "0.116.1", optional = true }
wit-component = "0.217"
Expand All @@ -46,10 +46,10 @@ anyhow = "1"
cap-std = "3.3.0"
heck = { version = "0.5" }
tokio = { version = "1.40", features = ["macros"] }
wasmtime = { version = "25", features = ["component-model"] }
wasmtime-wasi = "25"
wasmtime-wasi-runtime-config = "25"
wasmparser = "0.218"
wasmtime = { version = "27", features = ["component-model"] }
wasmtime-wasi = { version = "27" }
wasmtime-wasi-config = { version = "27" }
wasmparser = "0.219.1"

[workspace.dependencies]
anyhow = "1"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Supports all of the current WASI subsystems:

- [Clocks](#clocks): Allow / Deny
- [Environment](#env): Set environment variables, configure host environment variable permissions
- [Runtime Config](#runtime-config): Set runtime configuration, configure host property permissions
- [Config](#config): Set configuration, configure host property permissions
- [Exit](#exit): Allow / Deny
- [Filesystem](#filesystem): Mount a read-only filesystem, configure host filesystem preopen remappings or pass-through.
- [HTTP](#http): Allow / Deny
Expand Down Expand Up @@ -83,7 +83,7 @@ wasi-virt component.wasm -e CUSTOM=VAR --allow-env -o virt.wasm
wasi-virt component.wasm -e CUSTOM=VAR --allow-env=SOME,ENV_VARS -o virt.wasm
```

### Runtime Config
### Config

_experimental_

Expand Down
Binary file modified lib/package.wasm
Binary file not shown.
Binary file modified lib/virtual_adapter.debug.wasm
Binary file not shown.
Binary file modified lib/virtual_adapter.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2024-05-22"
channel = "nightly-2024-11-06"
components = ["rust-src"]
targets = ["wasm32-unknown-unknown"]
12 changes: 6 additions & 6 deletions src/bin/wasi-virt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ struct Args {
#[arg(short, long, use_value_delimiter(true), value_name("ENV=VAR"), value_parser = parse_key_val::<String, String>, help_heading = "Env")]
env: Option<Vec<(String, String)>>,

// RUNTIME CONFIG
/// Allow unrestricted access to host runtime configuration properties, or to a comma-separated list of property names.
#[arg(long, num_args(0..), use_value_delimiter(true), require_equals(true), value_name("PROPERTY_NAME"), help_heading = "Runtime Config (experimental)")]
// CONFIG
/// Allow unrestricted access to host configuration properties, or to a comma-separated list of property names.
#[arg(long, num_args(0..), use_value_delimiter(true), require_equals(true), value_name("PROPERTY_NAME"), help_heading = "Config (experimental)")]
allow_config: Option<Vec<String>>,

/// Set runtime config property overrides
#[arg(short, long, use_value_delimiter(true), value_name("NAME=VALUE"), value_parser = parse_key_val::<String, String>, help_heading = "Runtime Config (experimental)")]
/// Set config property overrides
#[arg(short, long, use_value_delimiter(true), value_name("NAME=VALUE"), value_parser = parse_key_val::<String, String>, help_heading = "Config (experimental)")]
config: Option<Vec<(String, String)>>,

// FS
Expand Down Expand Up @@ -185,7 +185,7 @@ fn main() -> Result<()> {
}
None => {
if allow_all {
// TODO enable once wasi:config/runtime is stable
// TODO enable once wasi:config/store is stable
// config.allow_all();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl WasiVirt {
self.exit(true);
self.random(true);
self.env().allow_all();
// TODO enable once wasi:config/runtime is stable
// TODO enable once wasi:config/store is stable
// self.config().allow_all();
self.fs().allow_host_preopens();
self.stdio().allow();
Expand All @@ -99,7 +99,7 @@ impl WasiVirt {
self.exit(false);
self.random(false);
self.env().deny_all();
// TODO enable once wasi:config/runtime is stable
// TODO enable once wasi:config/store is stable
// self.config().deny_all();
self.fs().deny_host_preopens();
self.stdio().ignore();
Expand Down Expand Up @@ -178,7 +178,7 @@ impl WasiVirt {
if !matches("wasi:cli/environment") {
self.env = None;
}
if !matches("wasi:config/runtime") {
if !matches("wasi:config/store") {
self.config = None;
}
if !matches("wasi:filesystem/") {
Expand Down
10 changes: 5 additions & 5 deletions src/virt_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ pub(crate) fn create_config_virt<'a>(module: &'a mut Module, config: &VirtConfig
/// Functions that represent the configuration functionality provided by WASI CLI
const WASI_CONFIG_FNS: [&str; 2] = ["get", "get-all"];

/// Stub imported functions that implement the WASI runtime config functionality
/// Stub imported functions that implement the WASI config functionality
///
/// This function throws an error if any imported functions do not exist
pub(crate) fn stub_config_virt(module: &mut Module) -> Result<()> {
for fn_name in WASI_CONFIG_FNS {
module.replace_imported_func(
module
.imports
.get_func("wasi:config/runtime@0.2.0-draft", fn_name)?,
.get_func("wasi:config/store@0.2.0-draft", fn_name)?,
|(body, _)| {
body.unreachable();
},
Expand All @@ -230,16 +230,16 @@ pub(crate) fn stub_config_virt(module: &mut Module) -> Result<()> {
Ok(())
}

/// Strip exported functions that implement the WASI runtime config functionality
/// Strip exported functions that implement the WASI config functionality
pub(crate) fn strip_config_virt(module: &mut Module) -> Result<()> {
stub_config_virt(module)?;

for fn_name in WASI_CONFIG_FNS {
let Ok(fid) = module
.exports
.get_func(format!("wasi:config/runtime@0.2.0-draft#{fn_name}"))
.get_func(format!("wasi:config/store@0.2.0-draft#{fn_name}"))
else {
bail!("Expected CLI function {fn_name}")
bail!("Expected Config function {fn_name}")
};
module.replace_exported_func(fid, |(body, _)| {
body.unreachable();
Expand Down
2 changes: 1 addition & 1 deletion tests/components/get-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Guest for VirtTestComponent {
unimplemented!();
}
fn test_get_config() -> Vec<(String, String)> {
wasi::config::runtime::get_all().unwrap()
wasi::config::store::get_all().unwrap()
}
fn test_file_read(_path: String) -> String {
unimplemented!();
Expand Down
18 changes: 9 additions & 9 deletions tests/virt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use wasmtime::{
Config, Engine, Store, WasmBacktraceDetails,
};
use wasmtime_wasi::{DirPerms, FilePerms, WasiCtx, WasiCtxBuilder, WasiView};
use wasmtime_wasi_runtime_config::{WasiRuntimeConfig, WasiRuntimeConfigVariables};
use wasmtime_wasi_config::{WasiConfig, WasiConfigVariables};
use wit_component::{ComponentEncoder, DecodedWasm};
use wit_parser::WorldItem;

Expand Down Expand Up @@ -220,8 +220,8 @@ async fn virt_test() -> Result<()> {
builder.env(k, v);
}
}
let runtime_config = {
let mut config = WasiRuntimeConfigVariables::new();
let wasi_config = {
let mut config = WasiConfigVariables::new();
if let Some(host_config) = &test.host_config {
for (k, v) in host_config {
config.insert(k, v);
Expand All @@ -246,7 +246,7 @@ async fn virt_test() -> Result<()> {
struct CommandCtx {
table: ResourceTable,
wasi: WasiCtx,
runtime_config: WasiRuntimeConfigVariables,
wasi_config: WasiConfigVariables,
}
impl WasiView for CommandCtx {
fn table(&mut self) -> &mut ResourceTable {
Expand All @@ -257,21 +257,21 @@ async fn virt_test() -> Result<()> {
}
}
impl CommandCtx {
fn runtime_config(&mut self) -> &mut WasiRuntimeConfigVariables {
&mut self.runtime_config
fn wasi_config(&mut self) -> &mut WasiConfigVariables {
&mut self.wasi_config
}
}

wasmtime_wasi::add_to_linker_async(&mut linker)?;
wasmtime_wasi_runtime_config::add_to_linker(&mut linker, |ctx: &mut CommandCtx| {
WasiRuntimeConfig::new(ctx.runtime_config())
wasmtime_wasi_config::add_to_linker(&mut linker, |ctx: &mut CommandCtx| {
WasiConfig::new(ctx.wasi_config())
})?;
let mut store = Store::new(
&engine,
CommandCtx {
table,
wasi,
runtime_config,
wasi_config,
},
);

Expand Down
20 changes: 10 additions & 10 deletions virtual-adapter/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::exports::wasi::config::runtime::{ConfigError, Guest as Runtime};
use crate::wasi::config::runtime;
use crate::exports::wasi::config::store::{Error, Guest as Store};
use crate::wasi::config::store;
use crate::VirtAdapter;

#[repr(C)]
Expand Down Expand Up @@ -47,8 +47,8 @@ fn read_data_str(offset: &mut isize) -> &'static str {
unsafe { core::str::from_utf8_unchecked(str_data) }
}

impl Runtime for VirtAdapter {
fn get(key: String) -> Result<Option<String>, ConfigError> {
impl Store for VirtAdapter {
fn get(key: String) -> Result<Option<String>, Error> {
let mut data_offset: isize = 0;
for _ in 0..unsafe { config.host_field_cnt } {
let config_key = read_data_str(&mut data_offset);
Expand All @@ -69,13 +69,13 @@ impl Runtime for VirtAdapter {
let is_allow_list = unsafe { config.host_fallback_allow };
let in_list = allow_or_deny.binary_search(&key.as_ref()).is_ok();
if is_allow_list && in_list || !is_allow_list && !in_list {
return runtime::get(&key).map_err(config_err_map);
return store::get(&key).map_err(config_err_map);
}
}
Ok(None)
}

fn get_all() -> Result<Vec<(String, String)>, ConfigError> {
fn get_all() -> Result<Vec<(String, String)>, Error> {
let mut configuration = Vec::new();
let mut data_offset: isize = 0;
for _ in 0..unsafe { config.host_field_cnt } {
Expand All @@ -93,7 +93,7 @@ impl Runtime for VirtAdapter {
}

let is_allow_list = unsafe { config.host_fallback_allow };
for (key, value) in runtime::get_all().map_err(config_err_map)? {
for (key, value) in store::get_all().map_err(config_err_map)? {
if configuration[0..override_len]
.binary_search_by_key(&&key, |(s, _)| s)
.is_ok()
Expand All @@ -110,9 +110,9 @@ impl Runtime for VirtAdapter {
}
}

fn config_err_map(err: runtime::ConfigError) -> ConfigError {
fn config_err_map(err: store::Error) -> Error {
match err {
runtime::ConfigError::Upstream(msg) => ConfigError::Upstream(msg),
runtime::ConfigError::Io(msg) => ConfigError::Io(msg),
store::Error::Upstream(msg) => Error::Upstream(msg),
store::Error::Io(msg) => Error::Io(msg),
}
}
19 changes: 12 additions & 7 deletions wit/deps/config/runtime_config.wit → wit/deps/config/store.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface runtime {
/// An error type that encapsulates the different errors that can occur fetching config
variant config-error {
interface store {
/// An error type that encapsulates the different errors that can occur fetching configuration values.
variant error {
/// This indicates an error from an "upstream" config source.
/// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc),
/// the error message is a string.
Expand All @@ -14,12 +14,17 @@ interface runtime {
io(string),
}

/// Gets a single opaque config value set at the given key if it exists
/// Gets a configuration value of type `string` associated with the `key`.
///
/// The value is returned as an `option<string>`. If the key is not found,
/// `Ok(none)` is returned. If an error occurs, an `Err(error)` is returned.
get: func(
/// A string key to fetch
key: string
) -> result<option<string>, config-error>;
) -> result<option<string>, error>;

/// Gets a list of all set config data
get-all: func() -> result<list<tuple<string, string>>, config-error>;
/// Gets a list of configuration key-value pairs of type `string`.
///
/// If an error occurs, an `Err(error)` is returned.
get-all: func() -> result<list<tuple<string, string>>, error>;
}
6 changes: 3 additions & 3 deletions wit/deps/config/world.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package wasi:config@0.2.0-draft;

world imports {
/// The runtime interface for config
import runtime;
}
/// The interface for wasi:config/store
import store;
}
10 changes: 5 additions & 5 deletions wit/virt.wit
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ world virtual-adapter {
export wasi:sockets/tcp@0.2.1;
import wasi:sockets/udp@0.2.1;
export wasi:sockets/udp@0.2.1;
import wasi:config/runtime@0.2.0-draft;
export wasi:config/runtime@0.2.0-draft;
import wasi:config/store@0.2.0-draft;
export wasi:config/store@0.2.0-draft;
}

world virtual-base {
Expand Down Expand Up @@ -163,8 +163,8 @@ world virtual-exit {
}

world virtual-config {
import wasi:config/runtime@0.2.0-draft;
export wasi:config/runtime@0.2.0-draft;
import wasi:config/store@0.2.0-draft;
export wasi:config/store@0.2.0-draft;
}

world virt-test {
Expand All @@ -184,7 +184,7 @@ world virt-test {
import wasi:io/poll@0.2.1;
import wasi:io/streams@0.2.1;
import wasi:cli/environment@0.2.1;
import wasi:config/runtime@0.2.0-draft;
import wasi:config/store@0.2.0-draft;
import wasi:filesystem/preopens@0.2.1;
import wasi:cli/exit@0.2.1;
import wasi:cli/stdin@0.2.1;
Expand Down

0 comments on commit 0948ede

Please sign in to comment.