Skip to content

Commit 7f19a2d

Browse files
committed
Find codegen backends in more locations
* Search in the sysroot passed using `--sysroot` in addition to the default sysroot. * Search for `librustc_codegen_$name.so` in addition to `librustc_codegen_$name-$release.so`.
1 parent 1fe1fa9 commit 7f19a2d

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

compiler/rustc_driver/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ pub fn version(binary: &str, matches: &getopts::Matches) {
799799
println!("host: {}", config::host_triple());
800800
println!("release: {}", unw(util::release_str()));
801801
if cfg!(feature = "llvm") {
802-
get_builtin_codegen_backend("llvm")().print_version();
802+
get_builtin_codegen_backend(&None, "llvm")().print_version();
803803
}
804804
}
805805
}
@@ -1088,7 +1088,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10881088

10891089
if cg_flags.iter().any(|x| *x == "passes=list") {
10901090
if cfg!(feature = "llvm") {
1091-
get_builtin_codegen_backend("llvm")().print_passes();
1091+
get_builtin_codegen_backend(&None, "llvm")().print_passes();
10921092
}
10931093
return None;
10941094
}

compiler/rustc_interface/src/util.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub fn get_codegen_backend(sopts: &config::Options) -> Box<dyn CodegenBackend> {
241241

242242
let backend = match codegen_name {
243243
filename if filename.contains('.') => load_backend_from_dylib(filename.as_ref()),
244-
codegen_name => get_builtin_codegen_backend(codegen_name),
244+
codegen_name => get_builtin_codegen_backend(&sopts.maybe_sysroot, codegen_name),
245245
};
246246

247247
unsafe {
@@ -366,15 +366,21 @@ fn sysroot_candidates() -> Vec<PathBuf> {
366366
}
367367
}
368368

369-
pub fn get_builtin_codegen_backend(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
369+
pub fn get_builtin_codegen_backend(
370+
maybe_sysroot: &Option<PathBuf>,
371+
backend_name: &str,
372+
) -> fn() -> Box<dyn CodegenBackend> {
370373
match backend_name {
371374
#[cfg(feature = "llvm")]
372375
"llvm" => rustc_codegen_llvm::LlvmCodegenBackend::new,
373-
_ => get_codegen_sysroot(backend_name),
376+
_ => get_codegen_sysroot(maybe_sysroot, backend_name),
374377
}
375378
}
376379

377-
pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
380+
pub fn get_codegen_sysroot(
381+
maybe_sysroot: &Option<PathBuf>,
382+
backend_name: &str,
383+
) -> fn() -> Box<dyn CodegenBackend> {
378384
// For now we only allow this function to be called once as it'll dlopen a
379385
// few things, which seems to work best if we only do that once. In
380386
// general this assertion never trips due to the once guard in `get_codegen_backend`,
@@ -389,8 +395,9 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
389395
let target = session::config::host_triple();
390396
let sysroot_candidates = sysroot_candidates();
391397

392-
let sysroot = sysroot_candidates
398+
let sysroot = maybe_sysroot
393399
.iter()
400+
.chain(sysroot_candidates.iter())
394401
.map(|sysroot| {
395402
let libdir = filesearch::relative_target_lib_path(&sysroot, &target);
396403
sysroot.join(libdir).with_file_name("codegen-backends")
@@ -426,8 +433,10 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
426433

427434
let mut file: Option<PathBuf> = None;
428435

429-
let expected_name =
430-
format!("rustc_codegen_{}-{}", backend_name, release_str().expect("CFG_RELEASE"));
436+
let expected_names = &[
437+
format!("rustc_codegen_{}-{}", backend_name, release_str().expect("CFG_RELEASE")),
438+
format!("rustc_codegen_{}", backend_name),
439+
];
431440
for entry in d.filter_map(|e| e.ok()) {
432441
let path = entry.path();
433442
let filename = match path.file_name().and_then(|s| s.to_str()) {
@@ -438,7 +447,7 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
438447
continue;
439448
}
440449
let name = &filename[DLL_PREFIX.len()..filename.len() - DLL_SUFFIX.len()];
441-
if name != expected_name {
450+
if !expected_names.iter().any(|expected| expected == name) {
442451
continue;
443452
}
444453
if let Some(ref prev) = file {

0 commit comments

Comments
 (0)