diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2024-03-06 12:41:46 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2024-03-11 09:36:35 -0700 |
| commit | 341215c51daf9db2281e989dd559ab0fcc6c73f1 (patch) | |
| tree | dd1865eac22faca02d3e52202a49bd7c00abc827 | |
| parent | 7d9690a3bcb4ce57165341e5f5d0a2161283076d (diff) | |
| download | rust-341215c51daf9db2281e989dd559ab0fcc6c73f1.tar.gz rust-341215c51daf9db2281e989dd559ab0fcc6c73f1.zip | |
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.
| -rw-r--r-- | src/bootstrap/src/lib.rs | 33 |
1 files 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 @@ impl Build { /// An example of this would be a WebAssembly runtime when testing the wasm /// targets. fn runner(&self, target: TargetSelection) -> Option<String> { - 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<String> { + 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, |
