diff --git a/src/commands/run.rs b/src/commands/run.rs index f500844b9d8b..89a050e1b105 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -620,26 +620,27 @@ impl RunCommand { } #[cfg(feature = "component-model")] CliLinker::Component(linker) => { - let component = module.unwrap_component(); - let instance = linker.instantiate(&mut *store, component)?; - if self.invoke.is_some() { bail!("using `--invoke` with components is not supported"); } - // TODO: use the actual world - let func = instance - .get_typed_func::<(), (Result<(), ()>,)>(&mut *store, "run") - .context("failed to load `run` function")?; + let component = module.unwrap_component(); + + let (command, _instance) = preview2::command::sync::Command::instantiate( + &mut *store, + &component, + &linker, + )?; - let result = func - .call(&mut *store, ()) + let result = command + .wasi_cli_run() + .call_run(&mut *store) .context("failed to invoke `run` function") .map_err(|e| self.handle_coredump(e)); // Translate the `Result<(),()>` produced by wasm into a feigned // explicit exit here with status 1 if `Err(())` is returned. - result.and_then(|(wasm_result,)| match wasm_result { + result.and_then(|wasm_result| match wasm_result { Ok(()) => Ok(()), Err(()) => Err(wasmtime_wasi::I32Exit(1).into()), }) diff --git a/tests/all/cli_tests/component-basic.wat b/tests/all/cli_tests/component-basic.wat index 2b7f54a7af75..19a5fb2c6f50 100644 --- a/tests/all/cli_tests/component-basic.wat +++ b/tests/all/cli_tests/component-basic.wat @@ -4,7 +4,9 @@ i32.const 0) ) (core instance $i (instantiate $m)) - (func (export "run") (result (result)) + (func $run (result (result)) (canon lift (core func $i "run"))) + (instance (export (interface "wasi:cli/run")) + (export "run" (func $run))) )