@@ -1359,9 +1359,36 @@ impl Build {
13591359 /// An example of this would be a WebAssembly runtime when testing the wasm
13601360 /// targets.
13611361 fn runner ( & self , target : TargetSelection ) -> Option < String > {
1362- let target = self . config . target_config . get ( & target) ?;
1363- let runner = target. runner . as_ref ( ) ?;
1364- Some ( runner. to_owned ( ) )
1362+ let configured_runner =
1363+ self . config . target_config . get ( & target) . and_then ( |t| t. runner . as_ref ( ) ) . map ( |p| & * * p) ;
1364+ if let Some ( runner) = configured_runner {
1365+ return Some ( runner. to_owned ( ) ) ;
1366+ }
1367+
1368+ if target. starts_with ( "wasm" ) && target. contains ( "wasi" ) {
1369+ self . default_wasi_runner ( )
1370+ } else {
1371+ None
1372+ }
1373+ }
1374+
1375+ /// When a `runner` configuration is not provided and a WASI-looking target
1376+ /// is being tested this is consulted to prove the environment to see if
1377+ /// there's a runtime already lying around that seems reasonable to use.
1378+ fn default_wasi_runner ( & self ) -> Option < String > {
1379+ let mut finder = crate :: core:: sanity:: Finder :: new ( ) ;
1380+
1381+ // Look for Wasmtime, and for its default options be sure to disable
1382+ // its caching system since we're executing quite a lot of tests and
1383+ // ideally shouldn't pollute the cache too much.
1384+ if let Some ( path) = finder. maybe_have ( "wasmtime" ) {
1385+ if let Ok ( mut path) = path. into_os_string ( ) . into_string ( ) {
1386+ path. push_str ( " run -C cache=n --dir ." ) ;
1387+ return Some ( path) ;
1388+ }
1389+ }
1390+
1391+ None
13651392 }
13661393
13671394 /// Returns the root of the "rootfs" image that this target will be using,
0 commit comments