Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update wasmedge to 0.14.0 #2928

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 101 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/youki/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
44 changes: 18 additions & 26 deletions crates/youki/src/workload/wasmedge.rs
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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))?;

Expand Down