@@ -23,7 +23,7 @@ use std::path::{PathBuf, Path};
2323use std:: process:: Command ;
2424use std:: io:: Read ;
2525
26- use build_helper:: { self , output} ;
26+ use build_helper:: { self , output, BuildExpectation } ;
2727
2828use builder:: { Kind , RunConfig , ShouldRun , Builder , Compiler , Step } ;
2929use cache:: { INTERNER , Interned } ;
@@ -33,6 +33,7 @@ use native;
3333use tool:: { self , Tool } ;
3434use util:: { self , dylib_path, dylib_path_var} ;
3535use { Build , Mode } ;
36+ use toolstate:: ToolState ;
3637
3738const ADB_TEST_DIR : & str = "/data/tmp/work" ;
3839
@@ -64,17 +65,21 @@ impl fmt::Display for TestKind {
6465 }
6566}
6667
67- fn try_run ( build : & Build , cmd : & mut Command ) {
68+ fn try_run_expecting ( build : & Build , cmd : & mut Command , expect : BuildExpectation ) {
6869 if !build. fail_fast {
69- if !build. try_run ( cmd) {
70+ if !build. try_run ( cmd, expect ) {
7071 let failures = build. delayed_failures . get ( ) ;
7172 build. delayed_failures . set ( failures + 1 ) ;
7273 }
7374 } else {
74- build. run ( cmd) ;
75+ build. run_expecting ( cmd, expect ) ;
7576 }
7677}
7778
79+ fn try_run ( build : & Build , cmd : & mut Command ) {
80+ try_run_expecting ( build, cmd, BuildExpectation :: None )
81+ }
82+
7883fn try_run_quiet ( build : & Build , cmd : & mut Command ) {
7984 if !build. fail_fast {
8085 if !build. try_run_quiet ( cmd) {
@@ -294,6 +299,56 @@ impl Step for Rustfmt {
294299 }
295300}
296301
302+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
303+ pub struct Miri {
304+ host : Interned < String > ,
305+ }
306+
307+ impl Step for Miri {
308+ type Output = ( ) ;
309+ const ONLY_HOSTS : bool = true ;
310+ const DEFAULT : bool = true ;
311+
312+ fn should_run ( run : ShouldRun ) -> ShouldRun {
313+ let test_miri = run. builder . build . config . test_miri ;
314+ run. path ( "src/tools/miri" ) . default_condition ( test_miri)
315+ }
316+
317+ fn make_run ( run : RunConfig ) {
318+ run. builder . ensure ( Miri {
319+ host : run. target ,
320+ } ) ;
321+ }
322+
323+ /// Runs `cargo test` for miri.
324+ fn run ( self , builder : & Builder ) {
325+ let build = builder. build ;
326+ let host = self . host ;
327+ let compiler = builder. compiler ( 1 , host) ;
328+
329+ let miri = builder. ensure ( tool:: Miri { compiler, target : self . host } ) ;
330+ let mut cargo = builder. cargo ( compiler, Mode :: Tool , host, "test" ) ;
331+ cargo. arg ( "--manifest-path" ) . arg ( build. src . join ( "src/tools/miri/Cargo.toml" ) ) ;
332+
333+ // Don't build tests dynamically, just a pain to work with
334+ cargo. env ( "RUSTC_NO_PREFER_DYNAMIC" , "1" ) ;
335+ // miri tests need to know about the stage sysroot
336+ cargo. env ( "MIRI_SYSROOT" , builder. sysroot ( compiler) ) ;
337+ cargo. env ( "RUSTC_TEST_SUITE" , builder. rustc ( compiler) ) ;
338+ cargo. env ( "RUSTC_LIB_PATH" , builder. rustc_libdir ( compiler) ) ;
339+ cargo. env ( "MIRI_PATH" , miri) ;
340+
341+ builder. add_rustc_lib_path ( compiler, & mut cargo) ;
342+
343+ try_run_expecting (
344+ build,
345+ & mut cargo,
346+ builder. build . config . toolstate . miri . passes ( ToolState :: Testing ) ,
347+ ) ;
348+ }
349+ }
350+
351+
297352fn path_for_cargo ( builder : & Builder , compiler : Compiler ) -> OsString {
298353 // Configure PATH to find the right rustc. NB. we have to use PATH
299354 // and not RUSTC because the Cargo test suite has tests that will
0 commit comments