@@ -405,14 +405,13 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
405
405
"cannot load the default codegen backend twice"
406
406
) ;
407
407
408
- let target = session:: config:: host_triple ( ) ;
409
408
let sysroot_candidates = sysroot_candidates ( ) ;
410
409
411
410
let sysroot = sysroot_candidates
412
411
. iter ( )
413
412
. map ( |sysroot| {
414
- let libdir = filesearch:: relative_target_lib_path ( & sysroot, & target ) ;
415
- sysroot. join ( libdir) . with_file_name ( "codegen-backends" )
413
+ let libdir = filesearch:: find_libdir ( & sysroot) ;
414
+ sysroot. join ( libdir. as_ref ( ) ) . with_file_name ( "codegen-backends" )
416
415
} )
417
416
. filter ( |f| {
418
417
info ! ( "codegen backend candidate: {}" , f. display( ) ) ;
@@ -446,8 +445,14 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
446
445
447
446
let mut file: Option < PathBuf > = None ;
448
447
449
- let expected_name =
450
- format ! ( "rustc_codegen_{}-{}" , backend_name, release_str( ) . expect( "CFG_RELEASE" ) ) ;
448
+ // We search for both `rustc_codegen_$NAME-$RELEASE` and `rustc_codegen-$NAME`. The former is
449
+ // the name used by rustbuild. The second makes it easier for users to add their own codegen
450
+ // backend to the sysroot that can be used with `-Zcodegen-backend=foo` instead of
451
+ // `-Zcodegen-backend=/path/to/librustc_codegen_foo.so`.
452
+ let expected_names = vec ! [
453
+ format!( "rustc_codegen_{}-{}" , backend_name, release_str( ) . expect( "CFG_RELEASE" ) ) ,
454
+ format!( "rustc_codegen_{}" , backend_name) ,
455
+ ] ;
451
456
for entry in d. filter_map ( |e| e. ok ( ) ) {
452
457
let path = entry. path ( ) ;
453
458
let filename = match path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
@@ -458,7 +463,7 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
458
463
continue ;
459
464
}
460
465
let name = & filename[ DLL_PREFIX . len ( ) ..filename. len ( ) - DLL_SUFFIX . len ( ) ] ;
461
- if name != expected_name {
466
+ if !expected_names . iter ( ) . any ( |expected_name| name == expected_name) {
462
467
continue ;
463
468
}
464
469
if let Some ( ref prev) = file {
0 commit comments