Skip to content

Commit

Permalink
wapm2pirita nests all annotations under a key with the same name as t…
Browse files Browse the repository at this point in the history
…he runner
  • Loading branch information
Michael-F-Bryan committed Mar 28, 2023
1 parent 20085ec commit 83bec09
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
12 changes: 9 additions & 3 deletions lib/wasi/src/runners/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ impl crate::runners::Runner for WasiRunner {
command: &Command,
container: &WapmContainer,
) -> Result<Self::Output, Error> {
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)
Expand All @@ -167,3 +168,8 @@ impl crate::runners::Runner for WasiRunner {
Ok(())
}
}

#[derive(Default, Debug, serde::Deserialize)]
struct Annotations {
wasi: Option<Wasi>,
}
25 changes: 17 additions & 8 deletions lib/wasi/src/runners/wcgi/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -126,11 +129,10 @@ impl WcgiRunner {
&self,
module: Module,
wasi: &Wasi,
wcgi: &Wcgi,
ctx: &RunnerContext<'_>,
) -> Result<Handler, Error> {
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,
};
Expand Down Expand Up @@ -343,6 +345,13 @@ impl Default for Config {
}
}

#[derive(Debug, Default, serde::Deserialize)]
struct Annotations {
wasi: Option<Wasi>,
#[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 {
Expand Down

0 comments on commit 83bec09

Please sign in to comment.