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