Skip to content

Commit 5ac4ab1

Browse files
committed
Auto merge of #5389 - matklad:one-hard-cs-problem, r=alexcrichton
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.
2 parents 1fa59ee + f7fa1f2 commit 5ac4ab1

File tree

7 files changed

+56
-29
lines changed

7 files changed

+56
-29
lines changed

src/cargo/core/compiler/context/mod.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
129129
let (host_info, target_info) = {
130130
let _p = profile::start("Context::probe_target_info");
131131
debug!("probe_target_info");
132-
let host_target_same = match build_config.requested_target {
133-
Some(ref s) if s != &build_config.host_triple() => false,
134-
_ => true,
135-
};
136-
137132
let host_info = TargetInfo::new(config, &build_config, Kind::Host)?;
138-
let target_info = if host_target_same {
139-
host_info.clone()
140-
} else {
141-
TargetInfo::new(config, &build_config, Kind::Target)?
142-
};
133+
let target_info = TargetInfo::new(config, &build_config, Kind::Target)?;
143134
(host_info, target_info)
144135
};
145136

src/cargo/core/package.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct SerializedPackage<'a> {
4646
categories: &'a [String],
4747
keywords: &'a [String],
4848
readme: Option<&'a str>,
49-
repository: Option<&'a str>
49+
repository: Option<&'a str>,
5050
}
5151

5252
impl ser::Serialize for Package {

src/cargo/core/resolver/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use self::types::{RcVecIter, RegistryQueryer};
6868

6969
pub use self::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
7070
pub use self::encode::{Metadata, WorkspaceResolve};
71-
pub use self::resolve::{Resolve, Deps, DepsNotReplaced};
71+
pub use self::resolve::{Deps, DepsNotReplaced, Resolve};
7272
pub use self::types::Method;
7373

7474
mod context;

src/cargo/sources/registry/index.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ impl<'cfg> RegistryIndex<'cfg> {
150150
links,
151151
} = serde_json::from_str(line)?;
152152
let pkgid = PackageId::new(&name, &vers, &self.source_id)?;
153-
let deps = deps.into_iter().map(|dep| dep.into_dep(&self.source_id))
153+
let deps = deps.into_iter()
154+
.map(|dep| dep.into_dep(&self.source_id))
154155
.collect::<CargoResult<Vec<_>>>()?;
155156
let summary = Summary::new(pkgid, deps, features, links)?;
156157
let summary = summary.set_checksum(cksum.clone());

src/cargo/util/rustc.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,6 @@ impl Cache {
154154
}
155155

156156
fn cached_output(&mut self, cmd: &ProcessBuilder) -> CargoResult<(String, String)> {
157-
let calculate = || {
158-
let output = cmd.exec_with_output()?;
159-
let stdout = String::from_utf8(output.stdout)
160-
.map_err(|_| internal("rustc didn't return utf8 output"))?;
161-
let stderr = String::from_utf8(output.stderr)
162-
.map_err(|_| internal("rustc didn't return utf8 output"))?;
163-
Ok((stdout, stderr))
164-
};
165-
if self.cache_location.is_none() {
166-
info!("rustc info uncached");
167-
return calculate();
168-
}
169-
170157
let key = process_fingerprint(cmd);
171158
match self.data.outputs.entry(key) {
172159
Entry::Occupied(entry) => {
@@ -175,7 +162,12 @@ impl Cache {
175162
}
176163
Entry::Vacant(entry) => {
177164
info!("rustc info cache miss");
178-
let output = calculate()?;
165+
let output = cmd.exec_with_output()?;
166+
let stdout = String::from_utf8(output.stdout)
167+
.map_err(|_| internal("rustc didn't return utf8 output"))?;
168+
let stderr = String::from_utf8(output.stderr)
169+
.map_err(|_| internal("rustc didn't return utf8 output"))?;
170+
let output = (stdout, stderr);
179171
entry.insert(output.clone());
180172
self.dirty = true;
181173
Ok(output)

tests/testsuite/cfg.rs

+45
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,48 @@ fn any_ok() {
445445
.build();
446446
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
447447
}
448+
449+
// https://github.com/rust-lang/cargo/issues/5313
450+
#[test]
451+
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
452+
fn cfg_looks_at_rustflags_for_target() {
453+
let p = project("foo")
454+
.file(
455+
"Cargo.toml",
456+
r#"
457+
[package]
458+
name = "a"
459+
version = "0.0.1"
460+
authors = []
461+
462+
[target.'cfg(with_b)'.dependencies]
463+
b = { path = 'b' }
464+
"#,
465+
)
466+
.file(
467+
"src/main.rs",
468+
r#"
469+
#[cfg(with_b)]
470+
extern crate b;
471+
472+
fn main() { b::foo(); }
473+
"#,
474+
)
475+
.file(
476+
"b/Cargo.toml",
477+
r#"
478+
[package]
479+
name = "b"
480+
version = "0.0.1"
481+
authors = []
482+
"#,
483+
)
484+
.file("b/src/lib.rs", "pub fn foo() {}")
485+
.build();
486+
487+
assert_that(
488+
p.cargo("build --target x86_64-unknown-linux-gnu")
489+
.env("RUSTFLAGS", "--cfg with_b"),
490+
execs().with_status(0),
491+
);
492+
}

tests/testsuite/rustc_info_cache.rs

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ fn rustc_info_cache() {
2020

2121
let miss = "[..] rustc info cache miss[..]";
2222
let hit = "[..]rustc info cache hit[..]";
23-
let uncached = "[..]rustc info uncached[..]";
2423
let update = "[..]updated rustc info cache[..]";
2524

2625
assert_that(
@@ -50,7 +49,6 @@ fn rustc_info_cache() {
5049
execs()
5150
.with_status(0)
5251
.with_stderr_contains("[..]rustc info cache disabled[..]")
53-
.with_stderr_contains(uncached)
5452
.with_stderr_does_not_contain(update),
5553
);
5654

0 commit comments

Comments
 (0)