Skip to content

Commit 0dfbce1

Browse files
authored
Rollup merge of rust-lang#108376 - liushuyu:fix-sysroot-infer-103660, r=ozkanonur
compiler/rustc_session: fix sysroot detection logic This pull request fixes the sysroot detection logic on systems where `/usr/lib` contains a multi-arch structure (e.g. installs `rustc_driver` into `/usr/lib/x86_64-linux-gnu` folder). This fixes a regression for various Linux systems introduced in rust-lang#103660. On Debian and Ubuntu systems, the logic in the pull request, as mentioned earlier, will resolve the sysroot to `/usr/lib`, making `rustc --print target-libdir` to return `/usr/lib/lib/rustlib/x86_64-unknown-linux-gnu/lib` (notice the extra `lib` at the beginning). The fix is not very "clean" according to the standard. If you have any suggestions on improving the logic, you are more than welcome to comment below!
2 parents 31f858d + 2186358 commit 0dfbce1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

compiler/rustc_session/src/filesearch.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,17 @@ pub fn get_or_default_sysroot() -> Result<PathBuf, String> {
182182
if dir.ends_with(crate::config::host_triple()) {
183183
dir.parent() // chop off `$target`
184184
.and_then(|p| p.parent()) // chop off `rustlib`
185-
.and_then(|p| p.parent()) // chop off `lib`
185+
.and_then(|p| {
186+
// chop off `lib` (this could be also $arch dir if the host sysroot uses a
187+
// multi-arch layout like Debian or Ubuntu)
188+
match p.parent() {
189+
Some(p) => match p.file_name() {
190+
Some(f) if f == "lib" => p.parent(), // first chop went for $arch, so chop again for `lib`
191+
_ => Some(p),
192+
},
193+
None => None,
194+
}
195+
})
186196
.map(|s| s.to_owned())
187197
.ok_or(format!(
188198
"Could not move 3 levels upper using `parent()` on {}",

0 commit comments

Comments
 (0)