@@ -363,11 +363,9 @@ pub struct Miri {
363363impl Step for Miri {
364364 type Output = ( ) ;
365365 const ONLY_HOSTS : bool = true ;
366- const DEFAULT : bool = true ;
367366
368367 fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
369- let test_miri = run. builder . config . test_miri ;
370- run. path ( "src/tools/miri" ) . default_condition ( test_miri)
368+ run. path ( "src/tools/miri" )
371369 }
372370
373371 fn make_run ( run : RunConfig < ' _ > ) {
@@ -389,26 +387,92 @@ impl Step for Miri {
389387 extra_features : Vec :: new ( ) ,
390388 } ) ;
391389 if let Some ( miri) = miri {
392- let mut cargo = tool:: prepare_tool_cargo ( builder,
393- compiler,
394- Mode :: ToolRustc ,
395- host,
396- "test" ,
397- "src/tools/miri" ,
398- SourceType :: Submodule ,
399- & [ ] ) ;
390+ // # Run `cargo miri setup`.
391+ // As a side-effect, this will install xargo.
392+ let mut cargo = tool:: prepare_tool_cargo (
393+ builder,
394+ compiler,
395+ Mode :: ToolRustc ,
396+ host,
397+ "run" ,
398+ "src/tools/miri" ,
399+ SourceType :: Submodule ,
400+ & [ ] ,
401+ ) ;
402+ cargo
403+ . arg ( "--bin" )
404+ . arg ( "cargo-miri" )
405+ . arg ( "--" )
406+ . arg ( "miri" )
407+ . arg ( "setup" ) ;
408+
409+ // Tell `cargo miri` not to worry about the sysroot mismatch (we built with
410+ // stage1 but run with stage2).
411+ cargo. env ( "MIRI_SKIP_SYSROOT_CHECK" , "1" ) ;
412+ // Tell `cargo miri setup` where to find the sources.
413+ cargo. env ( "XARGO_RUST_SRC" , builder. src . join ( "src" ) ) ;
414+ // Debug things.
415+ cargo. env ( "RUST_BACKTRACE" , "1" ) ;
416+ // Configure `cargo install` path, and let cargo-miri know that that's where
417+ // xargo ends up.
418+ cargo. env ( "CARGO_INSTALL_ROOT" , & builder. out ) ; // cargo adds a `bin/`
419+ cargo. env ( "XARGO" , builder. out . join ( "bin" ) . join ( "xargo" ) ) ;
420+
421+ if !try_run ( builder, & mut cargo) {
422+ return ;
423+ }
424+
425+ // # Determine where Miri put its sysroot.
426+ // To this end, we run `cargo miri setup --env` and capture the output.
427+ // (We do this separately from the above so that when the setup actually
428+ // happens we get some output.)
429+ // We re-use the `cargo` from above.
430+ cargo. arg ( "--env" ) ;
431+
432+ // FIXME: Is there a way in which we can re-use the usual `run` helpers?
433+ let miri_sysroot = if builder. config . dry_run {
434+ String :: new ( )
435+ } else {
436+ builder. verbose ( & format ! ( "running: {:?}" , cargo) ) ;
437+ let out = cargo. output ( )
438+ . expect ( "We already ran `cargo miri setup` before and that worked" ) ;
439+ assert ! ( out. status. success( ) , "`cargo miri setup` returned with non-0 exit code" ) ;
440+ // Output is "MIRI_SYSROOT=<str>\n".
441+ let stdout = String :: from_utf8 ( out. stdout )
442+ . expect ( "`cargo miri setup` stdout is not valid UTF-8" ) ;
443+ let stdout = stdout. trim ( ) ;
444+ builder. verbose ( & format ! ( "`cargo miri setup --env` returned: {:?}" , stdout) ) ;
445+ let sysroot = stdout. splitn ( 2 , '=' )
446+ . nth ( 1 ) . expect ( "`cargo miri setup` stdout did not contain '='" ) ;
447+ sysroot. to_owned ( )
448+ } ;
449+
450+ // # Run `cargo test`.
451+ let mut cargo = tool:: prepare_tool_cargo (
452+ builder,
453+ compiler,
454+ Mode :: ToolRustc ,
455+ host,
456+ "test" ,
457+ "src/tools/miri" ,
458+ SourceType :: Submodule ,
459+ & [ ] ,
460+ ) ;
400461
401462 // miri tests need to know about the stage sysroot
402- cargo. env ( "MIRI_SYSROOT" , builder . sysroot ( compiler ) ) ;
463+ cargo. env ( "MIRI_SYSROOT" , miri_sysroot ) ;
403464 cargo. env ( "RUSTC_TEST_SUITE" , builder. rustc ( compiler) ) ;
404465 cargo. env ( "RUSTC_LIB_PATH" , builder. rustc_libdir ( compiler) ) ;
405466 cargo. env ( "MIRI_PATH" , miri) ;
406467
407468 builder. add_rustc_lib_path ( compiler, & mut cargo) ;
408469
409- if try_run ( builder, & mut cargo) {
410- builder . save_toolstate ( "miri" , ToolState :: TestPass ) ;
470+ if ! try_run ( builder, & mut cargo) {
471+ return ;
411472 }
473+
474+ // # Done!
475+ builder. save_toolstate ( "miri" , ToolState :: TestPass ) ;
412476 } else {
413477 eprintln ! ( "failed to test miri: could not build" ) ;
414478 }
0 commit comments