Skip to content

Commit

Permalink
deps: update wasmedge to 0.14.0
Browse files Browse the repository at this point in the history
Signed-off-by: Yashodhan Joshi <[email protected]>
  • Loading branch information
YJDoc2 committed Sep 20, 2024
1 parent 0b92791 commit b3f14b2
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 41 deletions.
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

0 comments on commit b3f14b2

Please sign in to comment.