Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
})
Expand Down
4 changes: 3 additions & 1 deletion tests/all/cli_tests/component-basic.wat
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
)