@@ -13,7 +13,7 @@ use std::process::Command;
1313use std:: time:: { Duration , Instant } ;
1414
1515use crate :: cache:: { Cache , Interned , INTERNER } ;
16- use crate :: config:: { SplitDebuginfo , TargetSelection } ;
16+ use crate :: config:: { SplitDebuginfo , TargetSelection , DryRun } ;
1717use crate :: doc;
1818use crate :: flags:: { Color , Subcommand } ;
1919use crate :: install;
@@ -1171,7 +1171,12 @@ impl<'a> Builder<'a> {
11711171 target : TargetSelection ,
11721172 cmd : & str ,
11731173 ) -> Command {
1174- let mut cargo = Command :: new ( & self . initial_cargo ) ;
1174+ let mut cargo = if cmd == "clippy" {
1175+ Command :: new ( self . initial_rustc . parent ( ) . unwrap ( ) . join ( "cargo-clippy" ) )
1176+ } else {
1177+ Command :: new ( & self . initial_cargo )
1178+ } ;
1179+
11751180 // Run cargo from the source root so it can find .cargo/config.
11761181 // This matters when using vendoring and the working directory is outside the repository.
11771182 cargo. current_dir ( & self . src ) ;
@@ -1293,6 +1298,24 @@ impl<'a> Builder<'a> {
12931298 compiler. stage
12941299 } ;
12951300
1301+ // We synthetically interpret a stage0 compiler used to build tools as a
1302+ // "raw" compiler in that it's the exact snapshot we download. Normally
1303+ // the stage0 build means it uses libraries build by the stage0
1304+ // compiler, but for tools we just use the precompiled libraries that
1305+ // we've downloaded
1306+ let use_snapshot = mode == Mode :: ToolBootstrap ;
1307+ assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
1308+
1309+ let maybe_sysroot = self . sysroot ( compiler) ;
1310+ let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
1311+ let libdir = self . rustc_libdir ( compiler) ;
1312+
1313+ let sysroot_str = sysroot. as_os_str ( ) . to_str ( ) . expect ( "sysroot should be UTF-8" ) ;
1314+ if !matches ! ( self . config. dry_run, DryRun :: SelfCheck ) {
1315+ self . verbose_than ( 0 , & format ! ( "using sysroot {sysroot_str}" ) ) ;
1316+ self . verbose_than ( 1 , & format ! ( "running cargo with mode {mode:?}" ) ) ;
1317+ }
1318+
12961319 let mut rustflags = Rustflags :: new ( target) ;
12971320 if stage != 0 {
12981321 if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
@@ -1310,35 +1333,12 @@ impl<'a> Builder<'a> {
13101333 // NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
13111334 // so it has no way of knowing the sysroot.
13121335 rustflags. arg ( "--sysroot" ) ;
1313- rustflags. arg (
1314- self . sysroot ( compiler)
1315- . as_os_str ( )
1316- . to_str ( )
1317- . expect ( "sysroot must be valid UTF-8" ) ,
1318- ) ;
1336+ rustflags. arg ( sysroot_str) ;
13191337 // Only run clippy on a very limited subset of crates (in particular, not build scripts).
13201338 cargo. arg ( "-Zunstable-options" ) ;
1321- // Explicitly does *not* set `--cfg=bootstrap`, since we're using a nightly clippy.
1322- let host_version = Command :: new ( "rustc" ) . arg ( "--version" ) . output ( ) . map_err ( |_| ( ) ) ;
1323- let output = host_version. and_then ( |output| {
1324- if output. status . success ( ) {
1325- Ok ( output)
1326- } else {
1327- Err ( ( ) )
1328- }
1329- } ) . unwrap_or_else ( |_| {
1330- eprintln ! (
1331- "error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
1332- ) ;
1333- eprintln ! ( "help: try `rustup component add clippy`" ) ;
1334- crate :: detail_exit_macro!( 1 ) ;
1335- } ) ;
1336- if !t ! ( std:: str :: from_utf8( & output. stdout) ) . contains ( "nightly" ) {
1337- rustflags. arg ( "--cfg=bootstrap" ) ;
1338- }
1339- } else {
1340- rustflags. arg ( "--cfg=bootstrap" ) ;
13411339 }
1340+
1341+ rustflags. arg ( "--cfg=bootstrap" ) ;
13421342 }
13431343
13441344 let use_new_symbol_mangling = match self . config . rust_new_symbol_mangling {
@@ -1470,6 +1470,10 @@ impl<'a> Builder<'a> {
14701470 Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => String :: new ( ) ,
14711471 } ;
14721472
1473+ if self . jobs ( ) > 1 {
1474+ //panic!("TESTING: Run with one job only!");
1475+ }
1476+
14731477 cargo. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
14741478
14751479 // FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
@@ -1520,18 +1524,6 @@ impl<'a> Builder<'a> {
15201524
15211525 let want_rustdoc = self . doc_tests != DocTests :: No ;
15221526
1523- // We synthetically interpret a stage0 compiler used to build tools as a
1524- // "raw" compiler in that it's the exact snapshot we download. Normally
1525- // the stage0 build means it uses libraries build by the stage0
1526- // compiler, but for tools we just use the precompiled libraries that
1527- // we've downloaded
1528- let use_snapshot = mode == Mode :: ToolBootstrap ;
1529- assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
1530-
1531- let maybe_sysroot = self . sysroot ( compiler) ;
1532- let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
1533- let libdir = self . rustc_libdir ( compiler) ;
1534-
15351527 // Clear the output directory if the real rustc we're using has changed;
15361528 // Cargo cannot detect this as it thinks rustc is bootstrap/debug/rustc.
15371529 //
@@ -1554,6 +1546,11 @@ impl<'a> Builder<'a> {
15541546 . env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
15551547 . env ( "RUSTC_REAL" , self . rustc ( compiler) )
15561548 . env ( "RUSTC_STAGE" , stage. to_string ( ) )
1549+
1550+ // set for clippy to know the sysroot
1551+ . env ( "SYSROOT" , & sysroot)
1552+ . env ( "RUSTC_COMMAND" , cmd)
1553+
15571554 . env ( "RUSTC_SYSROOT" , & sysroot)
15581555 . env ( "RUSTC_LIBDIR" , & libdir)
15591556 . env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -1567,11 +1564,8 @@ impl<'a> Builder<'a> {
15671564 )
15681565 . env ( "RUSTC_ERROR_METADATA_DST" , self . extended_error_dir ( ) )
15691566 . env ( "RUSTC_BREAK_ON_ICE" , "1" ) ;
1570- // Clippy support is a hack and uses the default `cargo-clippy` in path.
1571- // Don't override RUSTC so that the `cargo-clippy` in path will be run.
1572- if cmd != "clippy" {
1573- cargo. env ( "RUSTC" , self . bootstrap_out . join ( "rustc" ) ) ;
1574- }
1567+
1568+ cargo. env ( "RUSTC" , self . bootstrap_out . join ( "rustc" ) ) ;
15751569
15761570 // Dealing with rpath here is a little special, so let's go into some
15771571 // detail. First off, `-rpath` is a linker option on Unix platforms
0 commit comments