Skip to content

Commit

Permalink
Auto merge of #7931 - ehuss:build-std-no-sysroot-probe, r=alexcrichton
Browse files Browse the repository at this point in the history
build-std: remove sysroot probe

Now that RustcTargetData is computed earlier, running `rustc` again is no longer necessary.
  • Loading branch information
bors committed Feb 25, 2020
2 parents 9ac6af8 + 9d98645 commit 44816a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
15 changes: 9 additions & 6 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct TargetInfo {
crate_types: RefCell<HashMap<String, Option<(String, String)>>>,
/// `cfg` information extracted from `rustc --print=cfg`.
cfg: Vec<Cfg>,
/// Path to the sysroot.
pub sysroot: PathBuf,
/// Path to the "lib" or "bin" directory that rustc uses for its dynamic
/// libraries.
pub sysroot_host_libdir: PathBuf,
Expand Down Expand Up @@ -134,13 +136,13 @@ impl TargetInfo {
output_err_info(&process, &output, &error)
),
};
let mut sysroot_host_libdir = PathBuf::from(line);
if cfg!(windows) {
sysroot_host_libdir.push("bin");
let sysroot = PathBuf::from(line);
let sysroot_host_libdir = if cfg!(windows) {
sysroot.join("bin")
} else {
sysroot_host_libdir.push("lib");
}
let mut sysroot_target_libdir = PathBuf::from(line);
sysroot.join("lib")
};
let mut sysroot_target_libdir = sysroot.clone();
sysroot_target_libdir.push("lib");
sysroot_target_libdir.push("rustlib");
sysroot_target_libdir.push(match &kind {
Expand All @@ -162,6 +164,7 @@ impl TargetInfo {
Ok(TargetInfo {
crate_type_process,
crate_types: RefCell::new(map),
sysroot,
sysroot_host_libdir,
sysroot_target_libdir,
// recalculate `rustflags` from above now that we have `cfg`
Expand Down
20 changes: 9 additions & 11 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn resolve_std<'cfg>(
requested_target: CompileKind,
crates: &[String],
) -> CargoResult<(PackageSet<'cfg>, Resolve, ResolvedFeatures)> {
let src_path = detect_sysroot_src_path(ws)?;
let src_path = detect_sysroot_src_path(target_data)?;
let to_patch = [
"rustc-std-workspace-core",
"rustc-std-workspace-alloc",
Expand Down Expand Up @@ -163,21 +163,19 @@ pub fn generate_std_roots<'a>(
.collect::<CargoResult<Vec<_>>>()
}

fn detect_sysroot_src_path(ws: &Workspace<'_>) -> CargoResult<PathBuf> {
fn detect_sysroot_src_path(target_data: &RustcTargetData) -> CargoResult<PathBuf> {
if let Some(s) = env::var_os("__CARGO_TESTS_ONLY_SRC_ROOT") {
return Ok(s.into());
}

// NOTE: This is temporary until we figure out how to acquire the source.
// If we decide to keep the sysroot probe, then BuildConfig will need to
// be restructured so that the TargetInfo is created earlier and passed
// in, so we don't have this extra call to rustc.
let rustc = ws.config().load_global_rustc(Some(ws))?;
let output = rustc.process().arg("--print=sysroot").exec_with_output()?;
let s = String::from_utf8(output.stdout)
.map_err(|e| anyhow::format_err!("rustc didn't return utf8 output: {:?}", e))?;
let sysroot = PathBuf::from(s.trim());
let src_path = sysroot.join("lib").join("rustlib").join("src").join("rust");
let src_path = target_data
.info(CompileKind::Host)
.sysroot
.join("lib")
.join("rustlib")
.join("src")
.join("rust");
let lock = src_path.join("Cargo.lock");
if !lock.exists() {
anyhow::bail!(
Expand Down

0 comments on commit 44816a7

Please sign in to comment.