diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index faa7a2e67c8..a3cd0e19f6e 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -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) }; diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 39348facc1b..37ad259f10b 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -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 { diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index 8db1a74e95e..1407f8af31e 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -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; diff --git a/src/cargo/sources/registry/index.rs b/src/cargo/sources/registry/index.rs index 1aef89bed31..f201250c09f 100644 --- a/src/cargo/sources/registry/index.rs +++ b/src/cargo/sources/registry/index.rs @@ -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::>>()?; let summary = Summary::new(pkgid, deps, features, links)?; let summary = summary.set_checksum(cksum.clone()); diff --git a/src/cargo/util/rustc.rs b/src/cargo/util/rustc.rs index 883563d2fd9..c6de81889d9 100644 --- a/src/cargo/util/rustc.rs +++ b/src/cargo/util/rustc.rs @@ -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) => { @@ -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) diff --git a/tests/testsuite/cfg.rs b/tests/testsuite/cfg.rs index 369f48d165b..fa86db83630 100644 --- a/tests/testsuite/cfg.rs +++ b/tests/testsuite/cfg.rs @@ -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), + ); +} diff --git a/tests/testsuite/rustc_info_cache.rs b/tests/testsuite/rustc_info_cache.rs index 28d2c5dc631..b55c84a4de3 100644 --- a/tests/testsuite/rustc_info_cache.rs +++ b/tests/testsuite/rustc_info_cache.rs @@ -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( @@ -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), );