diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 195bcd99b92..9ad2c108f49 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -8,12 +8,12 @@ use crate::suggestions::suggest_function_exports; use crate::warning; use anyhow::{anyhow, Context, Result}; use clap::Parser; -use std::fs::File; use std::io::Write; use std::ops::Deref; use std::path::PathBuf; #[cfg(feature = "cache")] use std::str::FromStr; +use std::{fs::File, net::SocketAddr}; #[cfg(feature = "emscripten")] use wasmer::FunctionEnv; use wasmer::*; @@ -91,6 +91,10 @@ pub struct RunWithoutFile { #[clap(long = "verbose")] pub(crate) verbose: Option, + #[cfg(feature = "webc_runner")] + #[clap(flatten)] + pub(crate) wcgi: WcgiOptions, + /// Enable coredump generation after a WebAssembly trap. #[clap(name = "COREDUMP PATH", long = "coredump-on-trap", parse(from_os_str))] coredump_on_trap: Option, @@ -223,6 +227,7 @@ impl RunWithPathBuf { fn inner_execute(&self) -> Result<()> { #[cfg(feature = "webc_runner")] { + dbg!(&self.path); if let Ok(pf) = WapmContainer::from_path(self.path.clone()) { return self.run_container(pf, self.command_name.as_deref(), &self.args); } @@ -400,7 +405,16 @@ impl RunWithPathBuf { let mut runner = wasmer_wasi::runners::wcgi::WcgiRunner::new(id); let (store, _compiler_type) = self.store.get_store()?; - runner.config().args(args).store(store); + runner + .config() + .args(args) + .store(store) + .addr(self.wcgi.addr) + .envs(self.wasi.env_vars.clone()) + .map_directories(self.wasi.mapped_dirs.iter().map(|(g, h)| (h, g))); + if self.wcgi.forward_host_env { + runner.config().forward_host_env(); + } if runner.can_run_command(id, command).unwrap_or(false) { return runner.run_cmd(&container, id).context("WCGI runner failed"); } @@ -689,3 +703,22 @@ fn generate_coredump( Ok(()) } + +#[derive(Debug, Clone, Parser)] +pub(crate) struct WcgiOptions { + /// The address to serve on. + #[clap(long, short, env, default_value_t = ([127, 0, 0, 1], 8000).into())] + pub(crate) addr: SocketAddr, + /// Forward all host env variables to the wcgi task. + #[clap(long)] + pub(crate) forward_host_env: bool, +} + +impl Default for WcgiOptions { + fn default() -> Self { + Self { + addr: ([127, 0, 0, 1], 8000).into(), + forward_host_env: false, + } + } +} diff --git a/lib/wasi/src/runners/wcgi/runner.rs b/lib/wasi/src/runners/wcgi/runner.rs index eb8cda9be69..bb2b33ccb23 100644 --- a/lib/wasi/src/runners/wcgi/runner.rs +++ b/lib/wasi/src/runners/wcgi/runner.rs @@ -323,6 +323,20 @@ impl Config { self } + pub fn map_directories(&mut self, mappings: I) -> &mut Self + where + I: IntoIterator, + H: Into, + G: Into, + { + let mappings = mappings.into_iter().map(|(h, g)| MappedDirectory { + host: h.into(), + guest: g.into(), + }); + self.mapped_dirs.extend(mappings); + self + } + /// Set callbacks that will be triggered at various points in the runner's /// lifecycle. pub fn callbacks(&mut self, callbacks: impl Callbacks + Send + Sync + 'static) -> &mut Self {