Skip to content

Commit

Permalink
Merge #301
Browse files Browse the repository at this point in the history
301: fix for changed rustc directory layout r=RalfJung a=RalfJung

This fixes xargo to work with rust-lang/rust#73265.
We should wait until the next nightly is released so that CI tests a nightly with the new directories.

Co-authored-by: Ralf Jung <post@ralfj.de>
  • Loading branch information
bors[bot] and RalfJung authored Jul 29, 2020
2 parents 2223cb5 + 0ec05d0 commit f1b2e41
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
29 changes: 6 additions & 23 deletions src/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::env;
use std::ffi::OsStr;
use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
use std::process::Command;
Expand All @@ -8,7 +7,6 @@ pub use rustc_version::version_meta as version;

use serde_json::Value;
use serde_json;
use walkdir::WalkDir;

use CurrentDirectory;
use errors::*;
Expand Down Expand Up @@ -71,8 +69,8 @@ impl Sysroot {
&self.path
}

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

Expand All @@ -82,25 +80,10 @@ impl Sysroot {
});
}

if src.exists() {
for e in WalkDir::new(src) {
let e = e.chain_err(|| "couldn't walk the sysroot")?;

// Looking for $SRC/libstd/Cargo.toml
if e.file_type().is_file() && e.file_name() == "Cargo.toml" {
let toml = e.path();

if let Some(std) = toml.parent() {
if let Some(src) = std.parent() {
if std.file_name() == Some(OsStr::new("libstd")) {
return Ok(Src {
path: src.to_owned(),
});
}
}
}
}
}
if src.join("rust").join("library").join("std").join("Cargo.toml").is_file() {
return Ok(Src {
path: src.join("rust").join("library"),
});
}

Err(
Expand Down
25 changes: 17 additions & 8 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,13 @@ impl Blueprint {
}

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

Blueprint::add_patch(&mut patch, src.path().join("tools"), "rustc-std-workspace-core")?;
Blueprint::add_patch(&mut patch, src.path().join("tools"), "rustc-std-workspace-alloc")?;
Blueprint::add_patch(&mut patch, src.path().join("tools"), "rustc-std-workspace-std")?;
Blueprint::add_patch(&mut patch, src.path(), "rustc-std-workspace-core")?;
Blueprint::add_patch(&mut patch, src.path(), "rustc-std-workspace-alloc")?;
Blueprint::add_patch(&mut patch, src.path(), "rustc-std-workspace-std")?;

// Compose dependency sections
let deps = match (
Expand Down Expand Up @@ -559,8 +563,13 @@ impl Blueprint {

if !map.contains_key("path") && !map.contains_key("git") {
// 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.
let path = src.path().join(format!("lib{}", k));
if path.exists() {
// Current sysroots call it just "std" (etc), but older sysroots use "libstd" (etc),
// so we check both.
let paths = [
src.path().join(&k),
src.path().join(format!("lib{}", k)),
];
if let Some(path) = paths.iter().find(|p| p.exists()) {
map.insert("path".to_owned(), Value::String(path.display().to_string()));
}
}
Expand Down

0 comments on commit f1b2e41

Please sign in to comment.