Rollup merge of #125263 - lqd:lld-fallback, r=petrochenkov
rust-lld: fallback to rustc's sysroot if there's no path to the linker in the target sysroot As seen in #125246, some sysroots don't expect to contain `rust-lld` and want to keep it that way, so we fallback to the default rustc sysroot if there is no path to the linker in any of the sysroot tools search paths. This is how we locate codegen-backends' dylibs already. People also have requested an error if none of these search paths contain the self-contained linker directory, so there's also an error in that case. r? `@petrochenkov` cc `@ehuss` `@RalfJung` I'm not sure where we check for `rust-lld`'s existence on the targets where we use it by default, and if we just ignore it when missing or emit a warning (as I assume we don't emit an error), so I just checked for the existence of `gcc-ld`, where `cc` will look for the lld-wrapper binaries. <sub>*Feel free to point out better ways to do this, it's the middle of the night here.*</sub> Fixes #125246
This commit is contained in:
commit
d6a1f1d3fc
5 changed files with 40 additions and 9 deletions
|
@ -51,6 +51,14 @@ pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
|
|||
PathBuf::from_iter([sysroot, Path::new(&rustlib_path), Path::new("lib")])
|
||||
}
|
||||
|
||||
/// Returns a path to the target's `bin` folder within its `rustlib` path in the sysroot. This is
|
||||
/// where binaries are usually installed, e.g. the self-contained linkers, lld-wrappers, LLVM tools,
|
||||
/// etc.
|
||||
pub fn make_target_bin_path(sysroot: &Path, target_triple: &str) -> PathBuf {
|
||||
let rustlib_path = rustc_target::target_rustlib_path(sysroot, target_triple);
|
||||
PathBuf::from_iter([sysroot, Path::new(&rustlib_path), Path::new("bin")])
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn current_dll_path() -> Result<PathBuf, String> {
|
||||
use std::ffi::{CStr, OsStr};
|
||||
|
|
|
@ -449,15 +449,24 @@ impl Session {
|
|||
)
|
||||
}
|
||||
|
||||
/// Returns a list of directories where target-specific tool binaries are located.
|
||||
/// Returns a list of directories where target-specific tool binaries are located. Some fallback
|
||||
/// directories are also returned, for example if `--sysroot` is used but tools are missing
|
||||
/// (#125246): we also add the bin directories to the sysroot where rustc is located.
|
||||
pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> {
|
||||
let rustlib_path = rustc_target::target_rustlib_path(&self.sysroot, config::host_triple());
|
||||
let p = PathBuf::from_iter([
|
||||
Path::new(&self.sysroot),
|
||||
Path::new(&rustlib_path),
|
||||
Path::new("bin"),
|
||||
]);
|
||||
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
|
||||
let bin_path = filesearch::make_target_bin_path(&self.sysroot, config::host_triple());
|
||||
let fallback_sysroot_paths = filesearch::sysroot_candidates()
|
||||
.into_iter()
|
||||
.map(|sysroot| filesearch::make_target_bin_path(&sysroot, config::host_triple()));
|
||||
let search_paths = std::iter::once(bin_path).chain(fallback_sysroot_paths);
|
||||
|
||||
if self_contained {
|
||||
// The self-contained tools are expected to be e.g. in `bin/self-contained` in the
|
||||
// sysroot's `rustlib` path, so we add such a subfolder to the bin path, and the
|
||||
// fallback paths.
|
||||
search_paths.flat_map(|path| [path.clone(), path.join("self-contained")]).collect()
|
||||
} else {
|
||||
search_paths.collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_incr_comp_session(&self, session_dir: PathBuf, lock_file: flock::Lock) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue