(
&self,
store: &mut Store<Host>,
component: &wasmtime::component::Component,
linker: &wasmtime::component::Linker<Host>,
)
| 857 | /// `wasi:cli`-based commands and running their exported `run` function. |
| 858 | #[cfg(feature = "component-model")] |
| 859 | async fn run_command_component( |
| 860 | &self, |
| 861 | store: &mut Store<Host>, |
| 862 | component: &wasmtime::component::Component, |
| 863 | linker: &wasmtime::component::Linker<Host>, |
| 864 | ) -> Result<wasmtime::component::Instance> { |
| 865 | let instance = linker.instantiate_async(&mut *store, component).await?; |
| 866 | |
| 867 | let mut result = None; |
| 868 | let _ = &mut result; |
| 869 | |
| 870 | // If WASIp3 is enabled at compile time, enabled at runtime, and found |
| 871 | // in this component then use that to generate the result. |
| 872 | #[cfg(feature = "component-model-async")] |
| 873 | if self.run.common.wasi.p3.unwrap_or(crate::common::P3_DEFAULT) { |
| 874 | if let Ok(command) = wasmtime_wasi::p3::bindings::Command::new(&mut *store, &instance) { |
| 875 | result = Some( |
| 876 | store |
| 877 | .run_concurrent(async |store| command.wasi_cli_run().call_run(store).await) |
| 878 | .await?, |
| 879 | ); |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | let result = match result { |
| 884 | Some(result) => result, |
| 885 | // If WASIp3 wasn't found then fall back to requiring WASIp2 and |
| 886 | // this'll report an error if the right export doesn't exist. |
| 887 | None => { |
| 888 | wasmtime_wasi::p2::bindings::Command::new(&mut *store, &instance)? |
| 889 | .wasi_cli_run() |
| 890 | .call_run(&mut *store) |
| 891 | .await |
| 892 | } |
| 893 | }; |
| 894 | let wasm_result = result.context("failed to invoke `run` function")?; |
| 895 | |
| 896 | // Translate the `Result<(),()>` produced by wasm into a feigned |
| 897 | // explicit exit here with status 1 if `Err(())` is returned. |
| 898 | match wasm_result { |
| 899 | Ok(()) => Ok(instance), |
| 900 | Err(()) => Err(wasmtime_wasi::I32Exit(1).into()), |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | /// Invoke a debugger component with a debuggee. |
| 905 | /// |
no test coverage detected