diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 46a6c5861d59d..b24f5f16991e3 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -405,14 +405,13 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box fn() -> Box = 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()) { @@ -458,7 +463,7 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box 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 diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index dc4243a76d5da..6c2acb7922f45 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -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 diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 5e3bfd9e9e272..512e00e0695ee 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -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);