Skip to content

Move codegen backend dylibs to a more sensible place #78704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,13 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
"cannot load the default codegen backend twice"
);

let target = session::config::host_triple();
let sysroot_candidates = sysroot_candidates();

let sysroot = sysroot_candidates
.iter()
.map(|sysroot| {
let libdir = filesearch::relative_target_lib_path(&sysroot, &target);
sysroot.join(libdir).with_file_name("codegen-backends")
let libdir = filesearch::find_libdir(&sysroot);
sysroot.join(libdir.as_ref()).with_file_name("codegen-backends")
})
.filter(|f| {
info!("codegen backend candidate: {}", f.display());
Expand Down Expand Up @@ -446,8 +445,14 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend

let mut file: Option<PathBuf> = None;

let expected_name =
format!("rustc_codegen_{}-{}", backend_name, release_str().expect("CFG_RELEASE"));
// We search for both `rustc_codegen_$NAME-$RELEASE` and `rustc_codegen-$NAME`. The former is
// the name used by rustbuild. The second makes it easier for users to add their own codegen
// backend to the sysroot that can be used with `-Zcodegen-backend=foo` instead of
// `-Zcodegen-backend=/path/to/librustc_codegen_foo.so`.
let expected_names = vec![
format!("rustc_codegen_{}-{}", backend_name, release_str().expect("CFG_RELEASE")),
format!("rustc_codegen_{}", backend_name),
];
for entry in d.filter_map(|e| e.ok()) {
let path = entry.path();
let filename = match path.file_name().and_then(|s| s.to_str()) {
Expand All @@ -458,7 +463,7 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
continue;
}
let name = &filename[DLL_PREFIX.len()..filename.len() - DLL_SUFFIX.len()];
if name != expected_name {
if !expected_names.iter().any(|expected_name| name == expected_name) {
continue;
}
if let Some(ref prev) = file {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ pub fn get_or_default_sysroot() -> PathBuf {
}
}

// The name of the directory rustc expects libraries to be located.
fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
/// The name of the directory rustc expects libraries to be located.
pub fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
// FIXME: This is a quick hack to make the rustc binary able to locate
// Rust libraries in Linux environments where libraries might be installed
// to lib64/lib32. This would be more foolproof by basing the sysroot off
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ impl<'a> Builder<'a> {
}

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

/// Returns the compiler's libdir where it stores the dynamic libraries that
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ impl Step for Rustc {
let backends_rel = backends_src
.strip_prefix(&src)
.unwrap()
.strip_prefix(builder.sysroot_libdir_relative(compiler))
.strip_prefix(builder.libdir_relative(compiler))
.unwrap();
// Don't use custom libdir here because ^lib/ will be resolved again with installer
let backends_dst = image.join("lib").join(&backends_rel);
Expand Down