From 341215c51daf9db2281e989dd559ab0fcc6c73f1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 6 Mar 2024 12:41:46 -0800 Subject: [PATCH] Configure a default `runner` for WASI targets If one is not explicitly configured look in the system environment to try and find one. For now just probing for `wasmtime` is implemented. --- src/bootstrap/src/lib.rs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 938b95cc60e..39bdece8127 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1360,9 +1360,36 @@ fn remote_tested(&self, target: TargetSelection) -> bool { /// An example of this would be a WebAssembly runtime when testing the wasm /// targets. fn runner(&self, target: TargetSelection) -> Option { - let target = self.config.target_config.get(&target)?; - let runner = target.runner.as_ref()?; - Some(runner.to_owned()) + let configured_runner = + self.config.target_config.get(&target).and_then(|t| t.runner.as_ref()).map(|p| &**p); + if let Some(runner) = configured_runner { + return Some(runner.to_owned()); + } + + if target.starts_with("wasm") && target.contains("wasi") { + self.default_wasi_runner() + } else { + None + } + } + + /// When a `runner` configuration is not provided and a WASI-looking target + /// is being tested this is consulted to prove the environment to see if + /// there's a runtime already lying around that seems reasonable to use. + fn default_wasi_runner(&self) -> Option { + let mut finder = crate::core::sanity::Finder::new(); + + // Look for Wasmtime, and for its default options be sure to disable + // its caching system since we're executing quite a lot of tests and + // ideally shouldn't pollute the cache too much. + if let Some(path) = finder.maybe_have("wasmtime") { + if let Ok(mut path) = path.into_os_string().into_string() { + path.push_str(" run -C cache=n --dir ."); + return Some(path); + } + } + + None } /// Returns the root of the "rootfs" image that this target will be using,