Skip to content

Commit

Permalink
Auto merge of #5389 - matklad:one-hard-cs-problem, r=alexcrichton
Browse files Browse the repository at this point in the history
One hard cs problem

Closes #5313

r? @alexcrichton

Note that, due to the first commit, this still gives us all the benefits of #5249: if RUSTFLAGS is empty, we will run only a single rustc process, even if we can't cache it across different cargo invocations.
  • Loading branch information
bors committed Apr 18, 2018
2 parents 1fa59ee + f7fa1f2 commit 5ac4ab1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 29 deletions.
11 changes: 1 addition & 10 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
let (host_info, target_info) = {
let _p = profile::start("Context::probe_target_info");
debug!("probe_target_info");
let host_target_same = match build_config.requested_target {
Some(ref s) if s != &build_config.host_triple() => false,
_ => true,
};

let host_info = TargetInfo::new(config, &build_config, Kind::Host)?;
let target_info = if host_target_same {
host_info.clone()
} else {
TargetInfo::new(config, &build_config, Kind::Target)?
};
let target_info = TargetInfo::new(config, &build_config, Kind::Target)?;
(host_info, target_info)
};

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct SerializedPackage<'a> {
categories: &'a [String],
keywords: &'a [String],
readme: Option<&'a str>,
repository: Option<&'a str>
repository: Option<&'a str>,
}

impl ser::Serialize for Package {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use self::types::{RcVecIter, RegistryQueryer};

pub use self::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
pub use self::encode::{Metadata, WorkspaceResolve};
pub use self::resolve::{Resolve, Deps, DepsNotReplaced};
pub use self::resolve::{Deps, DepsNotReplaced, Resolve};
pub use self::types::Method;

mod context;
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ impl<'cfg> RegistryIndex<'cfg> {
links,
} = serde_json::from_str(line)?;
let pkgid = PackageId::new(&name, &vers, &self.source_id)?;
let deps = deps.into_iter().map(|dep| dep.into_dep(&self.source_id))
let deps = deps.into_iter()
.map(|dep| dep.into_dep(&self.source_id))
.collect::<CargoResult<Vec<_>>>()?;
let summary = Summary::new(pkgid, deps, features, links)?;
let summary = summary.set_checksum(cksum.clone());
Expand Down
20 changes: 6 additions & 14 deletions src/cargo/util/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,6 @@ impl Cache {
}

fn cached_output(&mut self, cmd: &ProcessBuilder) -> CargoResult<(String, String)> {
let calculate = || {
let output = cmd.exec_with_output()?;
let stdout = String::from_utf8(output.stdout)
.map_err(|_| internal("rustc didn't return utf8 output"))?;
let stderr = String::from_utf8(output.stderr)
.map_err(|_| internal("rustc didn't return utf8 output"))?;
Ok((stdout, stderr))
};
if self.cache_location.is_none() {
info!("rustc info uncached");
return calculate();
}

let key = process_fingerprint(cmd);
match self.data.outputs.entry(key) {
Entry::Occupied(entry) => {
Expand All @@ -175,7 +162,12 @@ impl Cache {
}
Entry::Vacant(entry) => {
info!("rustc info cache miss");
let output = calculate()?;
let output = cmd.exec_with_output()?;
let stdout = String::from_utf8(output.stdout)
.map_err(|_| internal("rustc didn't return utf8 output"))?;
let stderr = String::from_utf8(output.stderr)
.map_err(|_| internal("rustc didn't return utf8 output"))?;
let output = (stdout, stderr);
entry.insert(output.clone());
self.dirty = true;
Ok(output)
Expand Down
45 changes: 45 additions & 0 deletions tests/testsuite/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,48 @@ fn any_ok() {
.build();
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
}

// https://github.com/rust-lang/cargo/issues/5313
#[test]
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
fn cfg_looks_at_rustflags_for_target() {
let p = project("foo")
.file(
"Cargo.toml",
r#"
[package]
name = "a"
version = "0.0.1"
authors = []
[target.'cfg(with_b)'.dependencies]
b = { path = 'b' }
"#,
)
.file(
"src/main.rs",
r#"
#[cfg(with_b)]
extern crate b;
fn main() { b::foo(); }
"#,
)
.file(
"b/Cargo.toml",
r#"
[package]
name = "b"
version = "0.0.1"
authors = []
"#,
)
.file("b/src/lib.rs", "pub fn foo() {}")
.build();

assert_that(
p.cargo("build --target x86_64-unknown-linux-gnu")
.env("RUSTFLAGS", "--cfg with_b"),
execs().with_status(0),
);
}
2 changes: 0 additions & 2 deletions tests/testsuite/rustc_info_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ fn rustc_info_cache() {

let miss = "[..] rustc info cache miss[..]";
let hit = "[..]rustc info cache hit[..]";
let uncached = "[..]rustc info uncached[..]";
let update = "[..]updated rustc info cache[..]";

assert_that(
Expand Down Expand Up @@ -50,7 +49,6 @@ fn rustc_info_cache() {
execs()
.with_status(0)
.with_stderr_contains("[..]rustc info cache disabled[..]")
.with_stderr_contains(uncached)
.with_stderr_does_not_contain(update),
);

Expand Down

0 comments on commit 5ac4ab1

Please sign in to comment.