diff --git a/crates/runtime/src/instance.rs b/crates/runtime/src/instance.rs index 70babd8ad0..f1ff001950 100644 --- a/crates/runtime/src/instance.rs +++ b/crates/runtime/src/instance.rs @@ -469,37 +469,6 @@ impl Instance { fn invoke_start_function(&mut self) -> Result<(), InstantiationError> { if let Some(start_index) = self.module.start_func { self.invoke_function(start_index) - } else if let Some(start_export) = self.module.exports.get("_start") { - // As a compatibility measure, if the module doesn't have a start - // function but does have a _start function exported, call that. - match *start_export { - wasmtime_environ::Export::Function(func_index) => { - let sig = &self.module.signatures[self.module.functions[func_index]]; - // No wasm params or returns; just the vmctx param. - if sig.params.len() == 1 && sig.returns.is_empty() { - self.invoke_function(func_index) - } else { - Ok(()) - } - } - _ => Ok(()), - } - } else if let Some(main_export) = self.module.exports.get("main") { - // As a further compatibility measure, if the module doesn't have a - // start function or a _start function exported, but does have a main - // function exported, call that. - match *main_export { - wasmtime_environ::Export::Function(func_index) => { - let sig = &self.module.signatures[self.module.functions[func_index]]; - // No wasm params or returns; just the vmctx param. - if sig.params.len() == 1 && sig.returns.is_empty() { - self.invoke_function(func_index) - } else { - Ok(()) - } - } - _ => Ok(()), - } } else { Ok(()) } diff --git a/src/bin/wasmtime.rs b/src/bin/wasmtime.rs index 4bc56d6b2f..f0712b11b3 100644 --- a/src/bin/wasmtime.rs +++ b/src/bin/wasmtime.rs @@ -370,12 +370,27 @@ fn handle_module( args: &Args, path: &Path, ) -> Result<()> { - let (instance, _module, data) = instantiate_module(store, module_registry, path)?; + let (instance, module, data) = instantiate_module(store, module_registry, path)?; // If a function to invoke was given, invoke it. if let Some(f) = &args.flag_invoke { let data = ModuleData::new(&data)?; invoke_export(instance, &data, f, args)?; + } else if module + .borrow() + .exports() + .iter() + .find(|export| export.name().as_str().is_empty()) + .is_some() + { + // Launch the default command export. + let data = ModuleData::new(&data)?; + invoke_export(instance, &data, "", args)?; + } else { + // If the module doesn't have a default command export, launch the + // _start function if one is present, as a compatibility measure. + let data = ModuleData::new(&data)?; + invoke_export(instance, &data, "_start", args)?; } Ok(())