@@ -269,35 +269,37 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
269
269
}
270
270
271
271
let target = session:: config:: host_triple ( ) ;
272
- // get target libdir path based on executable binary path
273
- let sysroot = filesearch:: get_or_default_sysroot ( ) ;
274
- let mut libdir_candidates = vec ! [ filesearch:: make_target_lib_path( & sysroot, & target) ] ;
272
+ let mut sysroot_candidates = vec ! [ filesearch:: get_or_default_sysroot( ) ] ;
275
273
let path = current_dll_path ( )
276
274
. and_then ( |s| s. canonicalize ( ) . ok ( ) ) ;
277
275
if let Some ( dll) = path {
278
- // use `parent` once to chop off the file name
279
- if let Some ( path) = dll. parent ( ) {
276
+ // use `parent` twice to chop off the file name and then also the
277
+ // directory containing the dll which should be either `lib` or `bin`.
278
+ if let Some ( path) = dll. parent ( ) . and_then ( |p| p. parent ( ) ) {
280
279
// The original `path` pointed at the `rustc_driver` crate's dll.
281
280
// Now that dll should only be in one of two locations. The first is
282
- // in the compiler's libdir, for example `$sysroot/$libdir /*.dll`. The
281
+ // in the compiler's libdir, for example `$sysroot/lib /*.dll`. The
283
282
// other is the target's libdir, for example
284
- // `$sysroot/$libdir /rustlib/$target/lib/*.dll`.
283
+ // `$sysroot/lib /rustlib/$target/lib/*.dll`.
285
284
//
286
285
// We don't know which, so let's assume that if our `path` above
287
- // doesn't end in `$target` we *could* be in the main libdir, and always
288
- // assume that we may be in the target libdir.
289
- libdir_candidates. push ( path. to_owned ( ) ) ;
290
-
291
- if !path. parent ( ) . map_or ( false , |p| p. ends_with ( target) ) {
292
- libdir_candidates. push ( path. join ( filesearch:: target_lib_path ( target) ) ) ;
286
+ // ends in `$target` we *could* be in the target libdir, and always
287
+ // assume that we may be in the main libdir.
288
+ sysroot_candidates. push ( path. to_owned ( ) ) ;
289
+
290
+ if path. ends_with ( target) {
291
+ sysroot_candidates. extend ( path. parent ( ) // chop off `$target`
292
+ . and_then ( |p| p. parent ( ) ) // chop off `rustlib`
293
+ . and_then ( |p| p. parent ( ) ) // chop off `lib`
294
+ . map ( |s| s. to_owned ( ) ) ) ;
293
295
}
294
296
}
295
297
}
296
298
297
- let sysroot = libdir_candidates . iter ( )
298
- . map ( |libdir | {
299
- debug ! ( "Trying target libdir: {}" , libdir . display ( ) ) ;
300
- libdir. with_file_name (
299
+ let sysroot = sysroot_candidates . iter ( )
300
+ . map ( |sysroot | {
301
+ let libdir = filesearch :: relative_target_lib_path ( & sysroot , & target ) ;
302
+ sysroot . join ( libdir) . with_file_name (
301
303
option_env ! ( "CFG_CODEGEN_BACKENDS_DIR" ) . unwrap_or ( "codegen-backends" ) )
302
304
} )
303
305
. filter ( |f| {
@@ -306,12 +308,12 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
306
308
} )
307
309
. next ( ) ;
308
310
let sysroot = sysroot. unwrap_or_else ( || {
309
- let candidates = libdir_candidates . iter ( )
311
+ let candidates = sysroot_candidates . iter ( )
310
312
. map ( |p| p. display ( ) . to_string ( ) )
311
313
. collect :: < Vec < _ > > ( )
312
314
. join ( "\n * " ) ;
313
315
let err = format ! ( "failed to find a `codegen-backends` folder \
314
- in the libdir candidates:\n * {}", candidates) ;
316
+ in the sysroot candidates:\n * {}", candidates) ;
315
317
early_error ( ErrorOutputType :: default ( ) , & err) ;
316
318
} ) ;
317
319
info ! ( "probing {} for a codegen backend" , sysroot. display( ) ) ;
0 commit comments