Don't try to use the same info if target == host
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 18 Apr 2018 15:00:21 +0000 (18:00 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 18 Apr 2018 15:00:21 +0000 (18:00 +0300)
The info might be different due to RUSTFLAGS, which, in general,
are applied only to target.

src/cargo/core/compiler/context/mod.rs
tests/testsuite/cfg.rs

index faa7a2e67c8dd8325307015985721249cbda8c0d..a3cd0e19f6e8d63887c8d74eb04f2f88d3161519 100644 (file)
@@ -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)
         };
 
index 369f48d165bebd10ca94595d901261e2b753d579..fa86db836307a91af402076f9b0b17afddf5a5b1 100644 (file)
@@ -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),
+    );
+}