diff --git a/Cargo.lock b/Cargo.lock index 958ce2c2cf1..499f1d6de0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1661,7 +1661,7 @@ dependencies = [ "atomic-polyfill", "hash32", "rustc_version 0.4.0", - "spin 0.9.6", + "spin 0.9.7", "stable_deref_trait", ] @@ -3902,9 +3902,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5d6e0250b93c8427a177b849d144a96d5acc57006149479403d7861ab721e34" +checksum = "c0959fd6f767df20b231736396e4f602171e00d95205676286e79d4a4eb67bef" dependencies = [ "lock_api", ] diff --git a/lib/wasi/src/runners/wasi.rs b/lib/wasi/src/runners/wasi.rs index 03b36436bf1..c4f1339cd06 100644 --- a/lib/wasi/src/runners/wasi.rs +++ b/lib/wasi/src/runners/wasi.rs @@ -144,15 +144,17 @@ impl crate::runners::Runner for WasiRunner { .starts_with(webc::metadata::annotations::WASI_RUNNER_URI)) } + #[tracing::instrument(skip(self, command, container))] fn run_command( &mut self, command_name: &str, command: &Command, container: &WapmContainer, ) -> Result { - let wasi = command - .get_annotation("wasi")? - .unwrap_or_else(|| Wasi::new(command_name)); + let Annotations { wasi } = command + .get_annotation(webc::metadata::annotations::WASI_RUNNER_URI)? + .unwrap_or_default(); + let wasi = wasi.unwrap_or_else(|| Wasi::new(command_name)); let atom_name = &wasi.atom; let atom = container .get_atom(atom_name) @@ -167,3 +169,8 @@ impl crate::runners::Runner for WasiRunner { Ok(()) } } + +#[derive(Default, Debug, serde::Deserialize)] +struct Annotations { + wasi: Option, +} diff --git a/lib/wasi/src/runners/wcgi/handler.rs b/lib/wasi/src/runners/wcgi/handler.rs index e04e23e0517..2c182a5343d 100644 --- a/lib/wasi/src/runners/wcgi/handler.rs +++ b/lib/wasi/src/runners/wcgi/handler.rs @@ -40,6 +40,11 @@ impl Handler { tracing::debug!("Creating the WebAssembly instance"); let mut request_specific_env = HashMap::new(); + + if self.dialect == CgiDialect::Rfc3875 { + // HACK(Michael-F-Bryan): this belongs in the wcgi-host crate + request_specific_env.insert("SCRIPT_NAME".to_string(), parts.uri.to_string()); + } self.dialect .prepare_environment_variables(parts, &mut request_specific_env); @@ -59,7 +64,10 @@ impl Handler { let module = self.module.clone(); - tracing::debug!("Calling into the WCGI executable"); + tracing::debug!( + dialect=%self.dialect, + "Calling into the WCGI executable", + ); let done = self .task_manager diff --git a/lib/wasi/src/runners/wcgi/runner.rs b/lib/wasi/src/runners/wcgi/runner.rs index de1f1c80238..892a53b63dc 100644 --- a/lib/wasi/src/runners/wcgi/runner.rs +++ b/lib/wasi/src/runners/wcgi/runner.rs @@ -41,17 +41,20 @@ impl WcgiRunner { #[tracing::instrument(skip(self, ctx))] fn run(&mut self, command_name: &str, ctx: &RunnerContext<'_>) -> Result<(), Error> { - let wasi: Wasi = ctx + let key = webc::metadata::annotations::WCGI_RUNNER_URI; + let Annotations { wasi, wcgi } = ctx .command() - .get_annotation("wasi") - .context("Unable to retrieve the WASI metadata")? - .unwrap_or_else(|| Wasi::new(command_name)); + .get_annotation(key) + .with_context(|| format!("Unable to deserialize the \"{key}\" annotations"))? + .unwrap_or_default(); + + let wasi = wasi.unwrap_or_else(|| Wasi::new(command_name)); let module = self .load_module(&wasi, ctx) .context("Couldn't load the module")?; - let handler = self.create_handler(module, &wasi, ctx)?; + let handler = self.create_handler(module, &wasi, &wcgi, ctx)?; let task_manager = Arc::clone(&handler.task_manager); let callbacks = Arc::clone(&self.config.callbacks); @@ -126,11 +129,10 @@ impl WcgiRunner { &self, module: Module, wasi: &Wasi, + wcgi: &Wcgi, ctx: &RunnerContext<'_>, ) -> Result { - let Wcgi { dialect, .. } = ctx.command().get_annotation("wcgi")?.unwrap_or_default(); - - let dialect = match dialect { + let dialect = match &wcgi.dialect { Some(d) => d.parse().context("Unable to parse the CGI dialect")?, None => CgiDialect::Wcgi, }; @@ -343,6 +345,13 @@ impl Default for Config { } } +#[derive(Debug, Default, serde::Deserialize)] +struct Annotations { + wasi: Option, + #[serde(default)] + wcgi: Wcgi, +} + /// Callbacks that are triggered at various points in the lifecycle of a runner /// and any WebAssembly instances it may start. pub trait Callbacks: Send + Sync + 'static {