Skip to content

Commit f7fa1f2

Browse files
committed
Don't try to use the same info if target == host
The info might be different due to RUSTFLAGS, which, in general, are applied only to target.
1 parent 404970f commit f7fa1f2

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
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

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+
}

0 commit comments

Comments
 (0)