@@ -1555,6 +1555,32 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
15551555 self . ensure ( tool:: Rustdoc { target_compiler } )
15561556 }
15571557
1558+ pub fn cargo_miri_cmd ( & self , run_compiler : Compiler ) -> BootstrapCommand {
1559+ assert ! ( run_compiler. stage > 0 , "miri can not be invoked at stage 0" ) ;
1560+
1561+ let compilers =
1562+ RustcPrivateCompilers :: new ( self , run_compiler. stage , self . build . host_target ) ;
1563+ assert_eq ! ( run_compiler, compilers. target_compiler( ) ) ;
1564+
1565+ // Prepare the tools
1566+ let miri = self . ensure ( tool:: Miri :: from_compilers ( compilers) ) ;
1567+ let cargo_miri = self . ensure ( tool:: CargoMiri :: from_compilers ( compilers) ) ;
1568+ // Invoke cargo-miri, make sure it can find miri and cargo.
1569+ let mut cmd = command ( cargo_miri. tool_path ) ;
1570+ cmd. env ( "MIRI" , & miri. tool_path ) ;
1571+ cmd. env ( "CARGO" , & self . initial_cargo ) ;
1572+ // Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`
1573+ // in `tool::ToolBuild` step, so they match the Miri we just built. However this means they
1574+ // are actually living one stage up, i.e. we are running `stage0-tools-bin/miri` with the
1575+ // libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact
1576+ // that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary.
1577+ // We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries
1578+ // added to the PATH due to the stage mismatch.
1579+ // Also see https://github.com/rust-lang/rust/pull/123192#issuecomment-2028901503.
1580+ add_dylib_path ( self . rustc_lib_paths ( run_compiler) , & mut cmd) ;
1581+ cmd
1582+ }
1583+
15581584 /// Create a Cargo command for running Clippy.
15591585 /// The used Clippy is (or in the case of stage 0, already was) built using `build_compiler`.
15601586 pub fn cargo_clippy_cmd ( & self , build_compiler : Compiler ) -> BootstrapCommand {
@@ -1570,11 +1596,10 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
15701596 return cmd;
15711597 }
15721598
1573- let compilers = RustcPrivateCompilers :: from_build_compiler (
1574- self ,
1575- build_compiler,
1576- self . build . host_target ,
1577- ) ;
1599+ // If we're linting something with build_compiler stage N, we want to build Clippy stage N
1600+ // and use that to lint it. That is why we use the `build_compiler` as the target compiler
1601+ // for RustcPrivateCompilers. We will use build compiler stage N-1 to build Clippy stage N.
1602+ let compilers = RustcPrivateCompilers :: from_target_compiler ( self , build_compiler) ;
15781603
15791604 let _ = self . ensure ( tool:: Clippy :: from_compilers ( compilers) ) ;
15801605 let cargo_clippy = self . ensure ( tool:: CargoClippy :: from_compilers ( compilers) ) ;
@@ -1587,32 +1612,6 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
15871612 cmd
15881613 }
15891614
1590- pub fn cargo_miri_cmd ( & self , run_compiler : Compiler ) -> BootstrapCommand {
1591- assert ! ( run_compiler. stage > 0 , "miri can not be invoked at stage 0" ) ;
1592-
1593- let compilers =
1594- RustcPrivateCompilers :: new ( self , run_compiler. stage , self . build . host_target ) ;
1595- assert_eq ! ( run_compiler, compilers. target_compiler( ) ) ;
1596-
1597- // Prepare the tools
1598- let miri = self . ensure ( tool:: Miri :: from_compilers ( compilers) ) ;
1599- let cargo_miri = self . ensure ( tool:: CargoMiri :: from_compilers ( compilers) ) ;
1600- // Invoke cargo-miri, make sure it can find miri and cargo.
1601- let mut cmd = command ( cargo_miri. tool_path ) ;
1602- cmd. env ( "MIRI" , & miri. tool_path ) ;
1603- cmd. env ( "CARGO" , & self . initial_cargo ) ;
1604- // Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`
1605- // in `tool::ToolBuild` step, so they match the Miri we just built. However this means they
1606- // are actually living one stage up, i.e. we are running `stage0-tools-bin/miri` with the
1607- // libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact
1608- // that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary.
1609- // We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries
1610- // added to the PATH due to the stage mismatch.
1611- // Also see https://github.com/rust-lang/rust/pull/123192#issuecomment-2028901503.
1612- add_dylib_path ( self . rustc_lib_paths ( run_compiler) , & mut cmd) ;
1613- cmd
1614- }
1615-
16161615 pub fn rustdoc_cmd ( & self , compiler : Compiler ) -> BootstrapCommand {
16171616 let mut cmd = command ( self . bootstrap_out . join ( "rustdoc" ) ) ;
16181617 cmd. env ( "RUSTC_STAGE" , compiler. stage . to_string ( ) )
0 commit comments