@@ -66,8 +66,7 @@ impl<'a> FileSearch<'a> {
66
66
if !found {
67
67
let rustpath = rust_path ( ) ;
68
68
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 ) ;
71
70
debug ! ( "is {} in visited_dirs? {}" , tlib_path. display( ) ,
72
71
visited_dirs. contains( & tlib_path. as_vec( ) . to_vec( ) ) ) ;
73
72
@@ -149,16 +148,16 @@ impl<'a> FileSearch<'a> {
149
148
// Returns a list of directories where target-specific tool binaries are located.
150
149
pub fn get_tools_search_paths ( & self ) -> Vec < Path > {
151
150
let mut p = Path :: new ( self . sysroot ) ;
152
- p. push ( find_libdir ( self . sysroot ) ) ;
151
+ p. push ( libdir_str ( ) ) ;
153
152
p. push ( rustlibdir ( ) ) ;
154
153
p. push ( self . triple ) ;
155
154
p. push ( "bin" ) ;
156
155
vec ! [ p]
157
156
}
158
157
}
159
158
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 ( ) ) ;
162
161
assert ! ( p. is_relative( ) ) ;
163
162
p. push ( rustlibdir ( ) ) ;
164
163
p. push ( target_triple) ;
@@ -168,17 +167,24 @@ pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path {
168
167
169
168
fn make_target_lib_path ( sysroot : & Path ,
170
169
target_triple : & str ) -> Path {
171
- sysroot. join ( & relative_target_lib_path ( sysroot , target_triple) )
170
+ sysroot. join ( & relative_target_lib_path ( target_triple) )
172
171
}
173
172
174
- fn make_rustpkg_lib_path ( sysroot : & Path ,
175
- dir : & Path ,
173
+ fn make_rustpkg_lib_path ( dir : & Path ,
176
174
triple : & str ) -> Path {
177
- let mut p = dir. join ( find_libdir ( sysroot ) ) ;
175
+ let mut p = dir. join ( libdir_str ( ) ) ;
178
176
p. push ( triple) ;
179
177
p
180
178
}
181
179
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
+
182
188
pub fn get_or_default_sysroot ( ) -> Path {
183
189
// Follow symlinks. If the resolved path is relative, make it absolute.
184
190
fn canonicalize ( path : Option < Path > ) -> Option < Path > {
@@ -190,7 +196,17 @@ pub fn get_or_default_sysroot() -> Path {
190
196
}
191
197
192
198
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
+ }
194
210
None => panic ! ( "can't determine value for sysroot" )
195
211
}
196
212
}
@@ -248,40 +264,9 @@ pub fn rust_path() -> Vec<Path> {
248
264
env_rust_path
249
265
}
250
266
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" )
285
270
}
286
271
287
272
// The name of rustc's own place to organize libraries.
0 commit comments