@@ -66,8 +66,7 @@ impl<'a> FileSearch<'a> {
6666 if !found {
6767 let rustpath = rust_path ( ) ;
6868 for path in rustpath. iter ( ) {
69- let tlib_path = make_rustpkg_lib_path (
70- self . sysroot , path, self . triple ) ;
69+ let tlib_path = make_rustpkg_lib_path ( path, self . triple ) ;
7170 debug ! ( "is {} in visited_dirs? {}" , tlib_path. display( ) ,
7271 visited_dirs. contains( & tlib_path. as_vec( ) . to_vec( ) ) ) ;
7372
@@ -149,16 +148,16 @@ impl<'a> FileSearch<'a> {
149148 // Returns a list of directories where target-specific tool binaries are located.
150149 pub fn get_tools_search_paths ( & self ) -> Vec < Path > {
151150 let mut p = Path :: new ( self . sysroot ) ;
152- p. push ( find_libdir ( self . sysroot ) ) ;
151+ p. push ( libdir_str ( ) ) ;
153152 p. push ( rustlibdir ( ) ) ;
154153 p. push ( self . triple ) ;
155154 p. push ( "bin" ) ;
156155 vec ! [ p]
157156 }
158157}
159158
160- pub fn relative_target_lib_path ( sysroot : & Path , target_triple : & str ) -> Path {
161- let mut p = Path :: new ( find_libdir ( sysroot ) ) ;
159+ pub fn relative_target_lib_path ( target_triple : & str ) -> Path {
160+ let mut p = Path :: new ( libdir_str ( ) ) ;
162161 assert ! ( p. is_relative( ) ) ;
163162 p. push ( rustlibdir ( ) ) ;
164163 p. push ( target_triple) ;
@@ -168,17 +167,24 @@ pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path {
168167
169168fn make_target_lib_path ( sysroot : & Path ,
170169 target_triple : & str ) -> Path {
171- sysroot. join ( & relative_target_lib_path ( sysroot , target_triple) )
170+ sysroot. join ( & relative_target_lib_path ( target_triple) )
172171}
173172
174- fn make_rustpkg_lib_path ( sysroot : & Path ,
175- dir : & Path ,
173+ fn make_rustpkg_lib_path ( dir : & Path ,
176174 triple : & str ) -> Path {
177- let mut p = dir. join ( find_libdir ( sysroot ) ) ;
175+ let mut p = dir. join ( libdir_str ( ) ) ;
178176 p. push ( triple) ;
179177 p
180178}
181179
180+ pub fn bindir_relative_str ( ) -> & ' static str {
181+ env ! ( "CFG_BINDIR_RELATIVE" )
182+ }
183+
184+ pub fn bindir_relative_path ( ) -> Path {
185+ Path :: new ( bindir_relative_str ( ) )
186+ }
187+
182188pub fn get_or_default_sysroot ( ) -> Path {
183189 // Follow symlinks. If the resolved path is relative, make it absolute.
184190 fn canonicalize ( path : Option < Path > ) -> Option < Path > {
@@ -190,7 +196,17 @@ pub fn get_or_default_sysroot() -> Path {
190196 }
191197
192198 match canonicalize ( os:: self_exe_name ( ) ) {
193- Some ( mut p) => { p. pop ( ) ; p. pop ( ) ; p }
199+ Some ( mut p) => {
200+ // Remove the exe name
201+ p. pop ( ) ;
202+ let mut rel = bindir_relative_path ( ) ;
203+ // Remove a number of elements equal to the number of elements in the bindir relative
204+ // path
205+ while rel. pop ( ) {
206+ p. pop ( ) ;
207+ }
208+ p
209+ }
194210 None => panic ! ( "can't determine value for sysroot" )
195211 }
196212}
@@ -248,40 +264,9 @@ pub fn rust_path() -> Vec<Path> {
248264 env_rust_path
249265}
250266
251- // The name of the directory rustc expects libraries to be located.
252- // On Unix should be "lib", on windows "bin"
253- #[ cfg( unix) ]
254- fn find_libdir ( sysroot : & Path ) -> String {
255- // FIXME: This is a quick hack to make the rustc binary able to locate
256- // Rust libraries in Linux environments where libraries might be installed
257- // to lib64/lib32. This would be more foolproof by basing the sysroot off
258- // of the directory where librustc is located, rather than where the rustc
259- // binary is.
260-
261- if sysroot. join ( primary_libdir_name ( ) ) . join ( rustlibdir ( ) ) . exists ( ) {
262- return primary_libdir_name ( ) ;
263- } else {
264- return secondary_libdir_name ( ) ;
265- }
266-
267- #[ cfg( target_word_size = "64" ) ]
268- fn primary_libdir_name ( ) -> String {
269- "lib64" . to_string ( )
270- }
271-
272- #[ cfg( target_word_size = "32" ) ]
273- fn primary_libdir_name ( ) -> String {
274- "lib32" . to_string ( )
275- }
276-
277- fn secondary_libdir_name ( ) -> String {
278- "lib" . to_string ( )
279- }
280- }
281-
282- #[ cfg( windows) ]
283- fn find_libdir ( _sysroot : & Path ) -> String {
284- "bin" . to_string ( )
267+ // The name of the directory rustc expects libraries to be located, relative to the sysroot
268+ fn libdir_str ( ) -> & ' static str {
269+ env ! ( "CFG_LIBDIR_RELATIVE" )
285270}
286271
287272// The name of rustc's own place to organize libraries.
0 commit comments