@@ -18,11 +18,12 @@ extern crate url;
18
18
#[ cfg( windows) ] extern crate kernel32;
19
19
#[ cfg( windows) ] extern crate winapi;
20
20
21
- use cargo:: util:: Rustc ;
22
21
use std:: ffi:: OsStr ;
23
22
use std:: time:: Duration ;
24
- use std:: path:: PathBuf ;
25
- use std:: env;
23
+ use std:: path:: { Path , PathBuf } ;
24
+
25
+ use cargo:: util:: Rustc ;
26
+ use cargo:: util:: paths;
26
27
27
28
pub mod support;
28
29
pub mod install;
@@ -69,31 +70,21 @@ fn _process(t: &OsStr) -> cargo::util::ProcessBuilder {
69
70
70
71
// We'll need dynamic libraries at some point in this test suite, so ensure
71
72
// that the rustc libdir is somewhere in LD_LIBRARY_PATH as appropriate.
72
- // Note that this isn't needed on Windows as we assume the bindir (with
73
- // dlls) is in PATH.
74
- if cfg ! ( unix) {
75
- let var = if cfg ! ( target_os = "macos" ) {
76
- "DYLD_LIBRARY_PATH"
77
- } else {
78
- "LD_LIBRARY_PATH"
79
- } ;
80
- let rustc = RUSTC . with ( |r| r. path . clone ( ) ) ;
81
- let path = env:: var_os ( "PATH" ) . unwrap_or ( Default :: default ( ) ) ;
82
- let rustc = env:: split_paths ( & path)
83
- . map ( |p| p. join ( & rustc) )
84
- . find ( |p| p. exists ( ) )
85
- . unwrap ( ) ;
86
- let mut libdir = rustc. clone ( ) ;
87
- libdir. pop ( ) ;
88
- libdir. pop ( ) ;
89
- libdir. push ( "lib" ) ;
90
- let prev = env:: var_os ( & var) . unwrap_or ( Default :: default ( ) ) ;
91
- let mut paths = env:: split_paths ( & prev) . collect :: < Vec < _ > > ( ) ;
92
- println ! ( "libdir: {:?}" , libdir) ;
93
- if !paths. contains ( & libdir) {
94
- paths. push ( libdir) ;
95
- p. env ( var, env:: join_paths ( & paths) . unwrap ( ) ) ;
96
- }
73
+ let mut rustc = RUSTC . with ( |r| r. process ( ) ) ;
74
+ let output = rustc. arg ( "--print" ) . arg ( "sysroot" ) . exec_with_output ( ) . unwrap ( ) ;
75
+ let libdir = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
76
+ let libdir = Path :: new ( libdir. trim ( ) ) ;
77
+ let libdir = if cfg ! ( windows) {
78
+ libdir. join ( "bin" )
79
+ } else {
80
+ libdir. join ( "lib" )
81
+ } ;
82
+ let mut paths = paths:: dylib_path ( ) ;
83
+ println ! ( "libdir: {:?}" , libdir) ;
84
+ if !paths. contains ( & libdir) {
85
+ paths. push ( libdir) ;
86
+ p. env ( paths:: dylib_path_envvar ( ) ,
87
+ paths:: join_paths ( & paths, paths:: dylib_path_envvar ( ) ) . unwrap ( ) ) ;
97
88
}
98
89
return p
99
90
}
0 commit comments