@@ -850,7 +850,40 @@ impl<'a> Builder<'a> {
850
850
cargo. args ( s. split_whitespace ( ) ) ;
851
851
}
852
852
rustflags. env ( "RUSTFLAGS_BOOTSTRAP" ) ;
853
- rustflags. arg ( "--cfg=bootstrap" ) ;
853
+ if cmd == "clippy" {
854
+ // clippy overwrites any sysroot we pass on the command line.
855
+ // Tell it to use the appropriate sysroot instead.
856
+ // NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
857
+ // so it has no way of knowing the sysroot.
858
+ rustflags. arg ( "--sysroot" ) ;
859
+ rustflags. arg (
860
+ self . sysroot ( compiler)
861
+ . as_os_str ( )
862
+ . to_str ( )
863
+ . expect ( "sysroot must be valid UTF-8" ) ,
864
+ ) ;
865
+ // Only run clippy on a very limited subset of crates (in particular, not build scripts).
866
+ cargo. arg ( "-Zunstable-options" ) ;
867
+ // Explicitly does *not* set `--cfg=bootstrap`, since we're using a nightly clippy.
868
+ let host_version = Command :: new ( "rustc" ) . arg ( "--version" ) . output ( ) . map_err ( |_| ( ) ) ;
869
+ if let Err ( _) = host_version. and_then ( |output| {
870
+ if output. status . success ( )
871
+ && t ! ( std:: str :: from_utf8( & output. stdout) ) . contains ( "nightly" )
872
+ {
873
+ Ok ( output)
874
+ } else {
875
+ Err ( ( ) )
876
+ }
877
+ } ) {
878
+ eprintln ! (
879
+ "error: `x.py clippy` requires a nightly host `rustc` toolchain with the `clippy` component"
880
+ ) ;
881
+ eprintln ! ( "help: try `rustup default nightly`" ) ;
882
+ std:: process:: exit ( 1 ) ;
883
+ }
884
+ } else {
885
+ rustflags. arg ( "--cfg=bootstrap" ) ;
886
+ }
854
887
}
855
888
856
889
if self . config . rust_new_symbol_mangling {
@@ -975,7 +1008,6 @@ impl<'a> Builder<'a> {
975
1008
// src/bootstrap/bin/{rustc.rs,rustdoc.rs}
976
1009
cargo
977
1010
. env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
978
- . env ( "RUSTC" , self . out . join ( "bootstrap/debug/rustc" ) )
979
1011
. env ( "RUSTC_REAL" , self . rustc ( compiler) )
980
1012
. env ( "RUSTC_STAGE" , stage. to_string ( ) )
981
1013
. env ( "RUSTC_SYSROOT" , & sysroot)
@@ -991,6 +1023,11 @@ impl<'a> Builder<'a> {
991
1023
)
992
1024
. env ( "RUSTC_ERROR_METADATA_DST" , self . extended_error_dir ( ) )
993
1025
. env ( "RUSTC_BREAK_ON_ICE" , "1" ) ;
1026
+ // Clippy support is a hack and uses the default `cargo-clippy` in path.
1027
+ // Don't override RUSTC so that the `cargo-clippy` in path will be run.
1028
+ if cmd != "clippy" {
1029
+ cargo. env ( "RUSTC" , self . out . join ( "bootstrap/debug/rustc" ) ) ;
1030
+ }
994
1031
995
1032
// Dealing with rpath here is a little special, so let's go into some
996
1033
// detail. First off, `-rpath` is a linker option on Unix platforms
0 commit comments