Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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