Skip to content

Commit

Permalink
Add an auto-detect plugins mechanism for the Wasmedge shim
Browse files Browse the repository at this point in the history
Signed-off-by: vincent <[email protected]>
  • Loading branch information
CaptainVincent committed Sep 20, 2023
1 parent ee70040 commit 19c7489
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions crates/containerd-shim-wasmedge/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use anyhow::{Context, Result};
use containerd_shim_wasm::container::{
Engine, Instance, PathResolve, RuntimeContext, Stdio, WasiEntrypoint,
Expand All @@ -15,13 +17,8 @@ pub struct WasmEdgeEngine {

impl Default for WasmEdgeEngine {
fn default() -> Self {
PluginManager::load(None).unwrap();

let host_options = HostRegistrationConfigOptions::default();
let host_options = host_options.wasi(true);
#[cfg(all(target_os = "linux", feature = "wasi_nn", target_arch = "x86_64"))]
let host_options = host_options.wasi_nn(true);

let config = ConfigBuilder::default()
.with_host_registration_config(host_options)
.build()
Expand All @@ -38,7 +35,15 @@ impl Engine for WasmEdgeEngine {

fn run_wasi(&self, ctx: &impl RuntimeContext, stdio: Stdio) -> Result<i32> {
let args = ctx.args();
let envs: Vec<_> = std::env::vars().map(|(k, v)| format!("{k}={v}")).collect();
let mut wasmedge_plugin_path: Option<PathBuf> = None;
let envs: Vec<_> = std::env::vars()
.map(|(k, v)| {
if k == "WASMEDGE_PLUGIN_PATH" {
wasmedge_plugin_path = Some(PathBuf::from(&v));
}
format!("{k}={v}")
})
.collect();
let WasiEntrypoint { path, func } = ctx.wasi_entrypoint();
let path = path
.resolve_in_path_or_cwd()
Expand All @@ -59,6 +64,8 @@ impl Engine for WasmEdgeEngine {
None => "main".to_string(),
};

PluginManager::load(wasmedge_plugin_path.as_deref())?;
let vm = vm.auto_detect_plugins()?;
let vm = vm
.register_module_from_file(&mod_name, &path)
.context("registering module")?;
Expand Down

0 comments on commit 19c7489

Please sign in to comment.