From b3f14b21f31234de1c0993cbd1b8d640dda4b936 Mon Sep 17 00:00:00 2001 From: Yashodhan Joshi Date: Fri, 20 Sep 2024 20:22:03 +0530 Subject: [PATCH] deps: update wasmedge to 0.14.0 Signed-off-by: Yashodhan Joshi --- Cargo.lock | 115 ++++++++++++++++++++++---- crates/youki/Cargo.toml | 2 +- crates/youki/src/workload/wasmedge.rs | 44 ++++------ 3 files changed, 120 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6b5bda3aa..2fc361669 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,6 +168,26 @@ dependencies = [ "syn 2.0.58", ] +[[package]] +name = "async-wasi" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9abe3a40b90f239a8a9141aff1a1b98befb36d5aa23a89ed33e030e520bfd20" +dependencies = [ + "bitflags 2.6.0", + "cfg-if", + "futures", + "getrandom", + "libc", + "log", + "parking_lot", + "path-absolutize", + "serde", + "slab", + "socket2 0.4.10", + "tokio", +] + [[package]] name = "atomic-polyfill" version = "1.0.3" @@ -1284,6 +1304,20 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "fiber-for-wasmedge" +version = "14.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03d7057d9db6e5266b609656724393781a1d75beb1159134420e0a47a7d1fae6" +dependencies = [ + "cc", + "cfg-if", + "rustix", + "wasmtime-asm-macros 14.0.4", + "wasmtime-versioned-export-macros 14.0.4", + "windows-sys 0.48.0", +] + [[package]] name = "filetime" version = "0.2.23" @@ -1732,7 +1766,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.5.6", "tokio", "tower-service", "tracing", @@ -2532,12 +2566,30 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "path-absolutize" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4af381fe79fa195b4909485d99f73a80792331df0625188e707854f0b3383f5" +dependencies = [ + "path-dedot", +] + [[package]] name = "path-clean" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef" +[[package]] +name = "path-dedot" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07ba0ad7e047712414213ff67533e6dd477af0a4e1d14fb52343e53d30ea9397" +dependencies = [ + "once_cell", +] + [[package]] name = "pentacle" version = "1.0.0" @@ -3674,6 +3726,16 @@ dependencies = [ "serde", ] +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.6" @@ -4073,9 +4135,10 @@ dependencies = [ "libc", "mio", "num_cpus", + "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.6", "tokio-macros", "windows-sys 0.48.0", ] @@ -4750,11 +4813,12 @@ dependencies = [ [[package]] name = "wasmedge-sdk" -version = "0.13.2" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f477f3b515760c6f7fa734dae5b97c030ee443969f1c30ed12d3a09bea783a2" +checksum = "852257498e8524cb0e2e8e9c7f1540afc2f24f2c3dd77806cf583feba8c19e99" dependencies = [ "anyhow", + "async-wasi", "cfg-if", "num-derive", "num-traits", @@ -4766,16 +4830,19 @@ dependencies = [ [[package]] name = "wasmedge-sys" -version = "0.17.5" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32d8e2276d63bb6f0c36871218643d193d2da6da3db36c1c1227547da465ed58" +checksum = "8ebcb49955b8b2e08fe8c3416fe4df61ecf30654db4b8f6f2418a0450cb5ada3" dependencies = [ + "async-wasi", "bindgen", "cfg-if", "cmake", + "fiber-for-wasmedge", "flate2", "lazy_static", "libc", + "log", "parking_lot", "paste", "phf", @@ -4793,9 +4860,9 @@ dependencies = [ [[package]] name = "wasmedge-types" -version = "0.4.4" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d4e7c8aebe2c513bb389beebc148253eb6f5904a6f9327179bbf2014c0efd52" +checksum = "17315f552d26bcfe01fc185b874177592d30aab86a10ed898cc8a3f29815c9c4" dependencies = [ "thiserror", "wat", @@ -5099,7 +5166,7 @@ dependencies = [ "target-lexicon", "wasm-encoder", "wasmparser 0.215.0", - "wasmtime-asm-macros", + "wasmtime-asm-macros 24.0.0", "wasmtime-cache", "wasmtime-component-macro", "wasmtime-component-util", @@ -5109,12 +5176,21 @@ dependencies = [ "wasmtime-jit-debug", "wasmtime-jit-icache-coherence", "wasmtime-slab", - "wasmtime-versioned-export-macros", + "wasmtime-versioned-export-macros 24.0.0", "wasmtime-winch", "wat", "windows-sys 0.52.0", ] +[[package]] +name = "wasmtime-asm-macros" +version = "14.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54984bc0b5689da87a43d7c181d23092b4d5cfcbb7ae3eb6b917dd55865d95e6" +dependencies = [ + "cfg-if", +] + [[package]] name = "wasmtime-asm-macros" version = "24.0.0" @@ -5186,7 +5262,7 @@ dependencies = [ "thiserror", "wasmparser 0.215.0", "wasmtime-environ", - "wasmtime-versioned-export-macros", + "wasmtime-versioned-export-macros 24.0.0", ] [[package]] @@ -5226,8 +5302,8 @@ dependencies = [ "cc", "cfg-if", "rustix", - "wasmtime-asm-macros", - "wasmtime-versioned-export-macros", + "wasmtime-asm-macros 24.0.0", + "wasmtime-versioned-export-macros 24.0.0", "windows-sys 0.52.0", ] @@ -5240,7 +5316,7 @@ dependencies = [ "object 0.36.0", "once_cell", "rustix", - "wasmtime-versioned-export-macros", + "wasmtime-versioned-export-macros 24.0.0", ] [[package]] @@ -5275,6 +5351,17 @@ dependencies = [ "wasmparser 0.215.0", ] +[[package]] +name = "wasmtime-versioned-export-macros" +version = "14.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b5575a75e711ca6c36bb9ad647c93541cdc8e34218031acba5da3f35919dd3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + [[package]] name = "wasmtime-versioned-export-macros" version = "24.0.0" diff --git a/crates/youki/Cargo.toml b/crates/youki/Cargo.toml index 5d04ac1a2..d0d8ce9bf 100644 --- a/crates/youki/Cargo.toml +++ b/crates/youki/Cargo.toml @@ -43,7 +43,7 @@ clap_complete = "4.1.3" caps = "0.5.5" wasmer = { version = "4.0.0", optional = true } wasmer-wasix = { version = "0.9.0", optional = true } -wasmedge-sdk = { version = "0.13.2", optional = true } +wasmedge-sdk = { version = "0.14.0", optional = true } wasmtime = { version = "24.0.0", optional = true } wasi-common = { version = "24.0.0", optional = true } tracing = { version = "0.1.40", features = ["attributes"] } diff --git a/crates/youki/src/workload/wasmedge.rs b/crates/youki/src/workload/wasmedge.rs index 1c2e5a239..7b6a4b439 100644 --- a/crates/youki/src/workload/wasmedge.rs +++ b/crates/youki/src/workload/wasmedge.rs @@ -1,7 +1,9 @@ +use std::collections::HashMap; + use libcontainer::oci_spec::runtime::Spec; use libcontainer::workload::{Executor, ExecutorError, ExecutorValidationError}; -use wasmedge_sdk::config::{CommonConfigOptions, ConfigBuilder, HostRegistrationConfigOptions}; -use wasmedge_sdk::{params, VmBuilder}; +use wasmedge_sdk::wasi::WasiModule; +use wasmedge_sdk::{params, Module, Store, Vm}; const EXECUTOR_NAME: &str = "wasmedge"; @@ -24,36 +26,26 @@ impl Executor for WasmedgeExecutor { } let envs = env_to_wasi(spec); - // create configuration with `wasi` option enabled - let config = ConfigBuilder::new(CommonConfigOptions::default()) - .with_host_registration_config(HostRegistrationConfigOptions::default().wasi(true)) - .build() - .map_err(|err| { - ExecutorError::Other(format!("failed to create wasmedge config: {}", err)) - })?; - - // create a vm with the config settings - let mut vm = VmBuilder::new() - .with_config(config) - .build() - .map_err(|err| ExecutorError::Other(format!("failed to create wasmedge vm: {}", err)))? - .register_module_from_file("main", cmd) - .map_err(|err| { - ExecutorError::Other(format!( - "failed to register wasmedge module from the file: {}", - err - )) - })?; // initialize the wasi module with the parsed parameters - let wasi_instance = vm - .wasi_module_mut() - .expect("config doesn't contain HostRegistrationConfigOptions"); - wasi_instance.initialize( + let mut wasi_module = WasiModule::create( Some(args.iter().map(|s| s as &str).collect()), Some(envs.iter().map(|s| s as &str).collect()), None, + ) + .map_err(|err| ExecutorError::Other(format!("failed to create wasi module: {:?}", err)))?; + + let mut instances = HashMap::new(); + instances.insert(wasi_module.name().to_string(), wasi_module.as_mut()); + + // create a vm + let mut vm = Vm::new( + Store::new(None, instances) + .map_err(|err| ExecutorError::Other(format!("failed to create store: {}", err)))?, ); + let module = Module::from_file(None, cmd).unwrap(); + vm.register_module(Some("main"), module).unwrap(); + vm.run_func(Some("main"), "_start", params!()) .map_err(|err| ExecutorError::Execution(err))?;