@@ -17,6 +17,7 @@ use std::ffi::OsStr;
17
17
use std:: fs;
18
18
use std:: io;
19
19
use std:: path:: { Path , PathBuf } ;
20
+ use std:: process:: Command ;
20
21
21
22
fn clippy_driver_path ( ) -> PathBuf {
22
23
if let Some ( path) = option_env ! ( "CLIPPY_DRIVER_PATH" ) {
@@ -42,6 +43,28 @@ fn rustc_lib_path() -> PathBuf {
42
43
option_env ! ( "RUSTC_LIB_PATH" ) . unwrap ( ) . into ( )
43
44
}
44
45
46
+ fn rustc_sysroot_path ( ) -> PathBuf {
47
+ option_env ! ( "SYSROOT" )
48
+ . map ( String :: from)
49
+ . or_else ( || std:: env:: var ( "SYSROOT" ) . ok ( ) )
50
+ . or_else ( || {
51
+ let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
52
+ let toolchain = option_env ! ( "RUSTUP_TOOLCHAIN" ) . or ( option_env ! ( "MULTIRUST_TOOLCHAIN" ) ) ;
53
+ home. and_then ( |home| toolchain. map ( |toolchain| format ! ( "{}/toolchains/{}" , home, toolchain) ) )
54
+ } )
55
+ . or_else ( || {
56
+ Command :: new ( "rustc" )
57
+ . arg ( "--print" )
58
+ . arg ( "sysroot" )
59
+ . output ( )
60
+ . ok ( )
61
+ . and_then ( |out| String :: from_utf8 ( out. stdout ) . ok ( ) )
62
+ . map ( |s| s. trim ( ) . to_owned ( ) )
63
+ } )
64
+ . expect ( "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust" )
65
+ . into ( )
66
+ }
67
+
45
68
fn config ( mode : & str , dir : PathBuf ) -> compiletest:: Config {
46
69
let mut config = compiletest:: Config :: default ( ) ;
47
70
@@ -55,7 +78,7 @@ fn config(mode: &str, dir: PathBuf) -> compiletest::Config {
55
78
config. run_lib_path = rustc_lib_path ( ) ;
56
79
config. compile_lib_path = rustc_lib_path ( ) ;
57
80
}
58
- config. target_rustcflags = Some ( format ! ( "-L {0} -L {0}/deps -Dwarnings" , host_libs( ) . display( ) ) ) ;
81
+ config. target_rustcflags = Some ( format ! ( "-L {0} -L {0}/deps -Dwarnings --sysroot {1} " , host_libs( ) . display ( ) , rustc_sysroot_path ( ) . display( ) ) ) ;
59
82
60
83
config. mode = cfg_mode;
61
84
config. build_base = if rustc_test_suite ( ) . is_some ( ) {
0 commit comments