mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Auto merge of #110281 - ozkanonur:multiarch-compatible-sysroot-finding, r=jackh726
make sysroot finding compatible with multiarch systems Tested on Debian 11 multiarch, worked just fine. resolves #109994
This commit is contained in:
commit
7f94b314ce
@ -227,28 +227,29 @@ pub fn get_or_default_sysroot() -> Result<PathBuf, String> {
|
|||||||
))?;
|
))?;
|
||||||
|
|
||||||
// if `dir` points target's dir, move up to the sysroot
|
// if `dir` points target's dir, move up to the sysroot
|
||||||
if dir.ends_with(crate::config::host_triple()) {
|
let mut sysroot_dir = if dir.ends_with(crate::config::host_triple()) {
|
||||||
dir.parent() // chop off `$target`
|
dir.parent() // chop off `$target`
|
||||||
.and_then(|p| p.parent()) // chop off `rustlib`
|
.and_then(|p| p.parent()) // chop off `rustlib`
|
||||||
.and_then(|p| {
|
.and_then(|p| p.parent()) // chop off `lib`
|
||||||
// chop off `lib` (this could be also $arch dir if the host sysroot uses a
|
|
||||||
// multi-arch layout like Debian or Ubuntu)
|
|
||||||
match p.parent() {
|
|
||||||
Some(p) => match p.file_name() {
|
|
||||||
Some(f) if f == "lib" => p.parent(), // first chop went for $arch, so chop again for `lib`
|
|
||||||
_ => Some(p),
|
|
||||||
},
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map(|s| s.to_owned())
|
.map(|s| s.to_owned())
|
||||||
.ok_or(format!(
|
.ok_or_else(|| {
|
||||||
"Could not move 3 levels upper using `parent()` on {}",
|
format!("Could not move 3 levels upper using `parent()` on {}", dir.display())
|
||||||
dir.display()
|
})?
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(dir.to_owned())
|
dir.to_owned()
|
||||||
|
};
|
||||||
|
|
||||||
|
// On multiarch linux systems, there will be multiarch directory named
|
||||||
|
// with the architecture(e.g `x86_64-linux-gnu`) under the `lib` directory.
|
||||||
|
// Which cause us to mistakenly end up in the lib directory instead of the sysroot directory.
|
||||||
|
if sysroot_dir.ends_with("lib") {
|
||||||
|
sysroot_dir =
|
||||||
|
sysroot_dir.parent().map(|real_sysroot| real_sysroot.to_owned()).ok_or_else(
|
||||||
|
|| format!("Could not move to parent path of {}", sysroot_dir.display()),
|
||||||
|
)?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(sysroot_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use env::args().next() to get the path of the executable without
|
// Use env::args().next() to get the path of the executable without
|
||||||
|
Loading…
Reference in New Issue
Block a user