Skip to content

Commit 0ec05d0

Browse files
committed
fix for changed rustc directory layout
1 parent 28d8a5f commit 0ec05d0

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

src/rustc.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::env;
2-
use std::ffi::OsStr;
32
use std::hash::{Hash, Hasher};
43
use std::path::{Path, PathBuf};
54
use std::process::Command;
@@ -8,7 +7,6 @@ pub use rustc_version::version_meta as version;
87

98
use serde_json::Value;
109
use serde_json;
11-
use walkdir::WalkDir;
1210

1311
use CurrentDirectory;
1412
use errors::*;
@@ -69,8 +67,8 @@ impl Sysroot {
6967
&self.path
7068
}
7169

72-
/// Returns the path to Rust source, `$SRC`, where `$SRC/libstd/Carg.toml`
73-
/// exists
70+
/// Returns the path to Rust source, `$SRC`, where `$SRC/libstd/Cargo.toml`
71+
/// or `$SRC/std/Cargo.toml` exists.
7472
pub fn src(&self) -> Result<Src> {
7573
let src = self.path().join("lib").join("rustlib").join("src");
7674

@@ -80,25 +78,10 @@ impl Sysroot {
8078
});
8179
}
8280

83-
if src.exists() {
84-
for e in WalkDir::new(src) {
85-
let e = e.chain_err(|| "couldn't walk the sysroot")?;
86-
87-
// Looking for $SRC/libstd/Cargo.toml
88-
if e.file_type().is_file() && e.file_name() == "Cargo.toml" {
89-
let toml = e.path();
90-
91-
if let Some(std) = toml.parent() {
92-
if let Some(src) = std.parent() {
93-
if std.file_name() == Some(OsStr::new("libstd")) {
94-
return Ok(Src {
95-
path: src.to_owned(),
96-
});
97-
}
98-
}
99-
}
100-
}
101-
}
81+
if src.join("rust").join("library").join("std").join("Cargo.toml").is_file() {
82+
return Ok(Src {
83+
path: src.join("rust").join("library"),
84+
});
10285
}
10386

10487
Err(

src/sysroot.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,13 @@ impl Blueprint {
412412
}
413413

414414
/// Add $CRATE to `patch` section, as needed to build libstd.
415-
fn add_patch(patch: &mut Table, mut path: PathBuf, crate_: &str) -> Result<()> {
416-
path.push(crate_);
417-
if path.exists() {
415+
fn add_patch(patch: &mut Table, src_path: &Path, crate_: &str) -> Result<()> {
416+
// Old sysroots have this in `src/tools/$CRATE`, new sysroots in `library/$CRATE`.
417+
let paths = [
418+
src_path.join(crate_),
419+
src_path.join("tools").join(crate_),
420+
];
421+
if let Some(path) = paths.iter().find(|p| p.exists()) {
418422
// add crate to patch section (if not specified)
419423
fn table_entry<'a>(table: &'a mut Table, key: &str) -> Result<&'a mut Table> {
420424
table
@@ -479,9 +483,9 @@ impl Blueprint {
479483
}
480484
}
481485

482-
Blueprint::add_patch(&mut patch, src.path().join("tools"), "rustc-std-workspace-core")?;
483-
Blueprint::add_patch(&mut patch, src.path().join("tools"), "rustc-std-workspace-alloc")?;
484-
Blueprint::add_patch(&mut patch, src.path().join("tools"), "rustc-std-workspace-std")?;
486+
Blueprint::add_patch(&mut patch, src.path(), "rustc-std-workspace-core")?;
487+
Blueprint::add_patch(&mut patch, src.path(), "rustc-std-workspace-alloc")?;
488+
Blueprint::add_patch(&mut patch, src.path(), "rustc-std-workspace-std")?;
485489

486490
// Compose dependency sections
487491
let deps = match (
@@ -559,8 +563,13 @@ impl Blueprint {
559563

560564
if !map.contains_key("path") && !map.contains_key("git") {
561565
// No path and no git given. This might be in the sysroot, but if we don't find it there we assume it comes from crates.io.
562-
let path = src.path().join(format!("lib{}", k));
563-
if path.exists() {
566+
// Current sysroots call it just "std" (etc), but older sysroots use "libstd" (etc),
567+
// so we check both.
568+
let paths = [
569+
src.path().join(&k),
570+
src.path().join(format!("lib{}", k)),
571+
];
572+
if let Some(path) = paths.iter().find(|p| p.exists()) {
564573
map.insert("path".to_owned(), Value::String(path.display().to_string()));
565574
}
566575
}

0 commit comments

Comments
 (0)