From 99123b8be139f7e139cc7c685dfe99a22939c4c7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 18 Oct 2023 12:16:47 -0700 Subject: [PATCH] Fix tests --- src/commands/run.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index a7fc11f4f94d..dc7c8ab05c71 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -413,26 +413,36 @@ impl RunCommand { let result = match linker { CliLinker::Core(linker) => { - // Use "" as a default module name. let module = module.unwrap_core(); let instance = linker.instantiate(&mut *store, &module).context(format!( "failed to instantiate {:?}", self.module_and_args[0] ))?; - // If a function to invoke was given, invoke it. + // If `_initialize` is present, meaning a reactor, then invoke + // the function. + if let Some(func) = instance.get_func(&mut *store, "_initialize") { + func.typed::<(), ()>(&store)?.call(&mut *store, ())?; + } + + // Look for the specific function provided or otherwise look for + // "" or "_start" exports to run as a "main" function. let func = if let Some(name) = &self.invoke { - instance - .get_func(&mut *store, name) - .ok_or_else(|| anyhow!("no func export named `{}` found", name))? + Some( + instance + .get_func(&mut *store, name) + .ok_or_else(|| anyhow!("no func export named `{}` found", name))?, + ) } else { instance .get_func(&mut *store, "") .or_else(|| instance.get_func(&mut *store, "_start")) - .ok_or_else(|| anyhow!("no `_start` or `` function found"))? }; - self.invoke_func(store, func) + match func { + Some(func) => self.invoke_func(store, func), + None => Ok(()), + } } #[cfg(feature = "component-model")] CliLinker::Component(linker) => {