@@ -71,8 +71,17 @@ pub fn main() {
71
71
exit ( 0 ) ;
72
72
}
73
73
74
- let sys_root = option_env ! ( "SYSROOT" )
75
- . map ( String :: from)
74
+ let mut orig_args: Vec < String > = env:: args ( ) . collect ( ) ;
75
+
76
+ // Get the sysroot, looking from most specific to this invocation to the least:
77
+ // - command line
78
+ // - runtime environment
79
+ // - SYSROOT
80
+ // - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
81
+ // - sysroot from rustc in the path
82
+ // - compile-time environment
83
+ let sys_root = arg_value ( & orig_args, "--sysroot" , |_| true )
84
+ . map ( |s| s. to_string ( ) )
76
85
. or_else ( || std:: env:: var ( "SYSROOT" ) . ok ( ) )
77
86
. or_else ( || {
78
87
let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
@@ -88,11 +97,11 @@ pub fn main() {
88
97
. and_then ( |out| String :: from_utf8 ( out. stdout ) . ok ( ) )
89
98
. map ( |s| s. trim ( ) . to_owned ( ) )
90
99
} )
100
+ . or_else ( || option_env ! ( "SYSROOT" ) . map ( String :: from) )
91
101
. expect ( "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust" ) ;
92
102
93
103
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
94
104
// We're invoking the compiler programmatically, so we ignore this/
95
- let mut orig_args: Vec < String > = env:: args ( ) . collect ( ) ;
96
105
if orig_args. len ( ) <= 1 {
97
106
std:: process:: exit ( 1 ) ;
98
107
}
0 commit comments