Skip to content

Commit 6740be0

Browse files
committed
Move codegen backend dylibs to a more sensible place
They used to be located at `lib/rustlib/$HOST_TRIPLE/codegen-backends`. Now they are at `lib/codegen-backends`.
1 parent d662f80 commit 6740be0

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

compiler/rustc_interface/src/util.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,13 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
405405
"cannot load the default codegen backend twice"
406406
);
407407

408-
let target = session::config::host_triple();
409408
let sysroot_candidates = sysroot_candidates();
410409

411410
let sysroot = sysroot_candidates
412411
.iter()
413412
.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")
416415
})
417416
.filter(|f| {
418417
info!("codegen backend candidate: {}", f.display());
@@ -446,8 +445,14 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
446445

447446
let mut file: Option<PathBuf> = None;
448447

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+
];
451456
for entry in d.filter_map(|e| e.ok()) {
452457
let path = entry.path();
453458
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
458463
continue;
459464
}
460465
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) {
462467
continue;
463468
}
464469
if let Some(ref prev) = file {

compiler/rustc_session/src/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ pub fn get_or_default_sysroot() -> PathBuf {
134134
}
135135
}
136136

137-
// The name of the directory rustc expects libraries to be located.
138-
fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
137+
/// The name of the directory rustc expects libraries to be located.
138+
pub fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
139139
// FIXME: This is a quick hack to make the rustc binary able to locate
140140
// Rust libraries in Linux environments where libraries might be installed
141141
// to lib64/lib32. This would be more foolproof by basing the sysroot off

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl<'a> Builder<'a> {
637637
}
638638

639639
pub fn sysroot_codegen_backends(&self, compiler: Compiler) -> PathBuf {
640-
self.sysroot_libdir(compiler, compiler.host).with_file_name("codegen-backends")
640+
self.rustc_libdir(compiler).with_file_name("codegen-backends")
641641
}
642642

643643
/// Returns the compiler's libdir where it stores the dynamic libraries that

src/bootstrap/dist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ impl Step for Rustc {
509509
let backends_rel = backends_src
510510
.strip_prefix(&src)
511511
.unwrap()
512-
.strip_prefix(builder.sysroot_libdir_relative(compiler))
512+
.strip_prefix(builder.libdir_relative(compiler))
513513
.unwrap();
514514
// Don't use custom libdir here because ^lib/ will be resolved again with installer
515515
let backends_dst = image.join("lib").join(&backends_rel);

0 commit comments

Comments
 (0)