diff --git a/crates/containerd-shim-wasmedge/src/instance.rs b/crates/containerd-shim-wasmedge/src/instance.rs index e2757ac81..e4d1b05b2 100644 --- a/crates/containerd-shim-wasmedge/src/instance.rs +++ b/crates/containerd-shim-wasmedge/src/instance.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use anyhow::{Context, Result}; use containerd_shim_wasm::container::{ Engine, Instance, PathResolve, RuntimeContext, Stdio, WasiEntrypoint, @@ -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() @@ -38,7 +35,15 @@ impl Engine for WasmEdgeEngine { fn run_wasi(&self, ctx: &impl RuntimeContext, stdio: Stdio) -> Result { let args = ctx.args(); - let envs: Vec<_> = std::env::vars().map(|(k, v)| format!("{k}={v}")).collect(); + let mut wasmedge_plugin_path: Option = 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() @@ -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")?;