From 8fb53025469778491ea5c3135992491327a6f55a Mon Sep 17 00:00:00 2001 From: Wim Hueskes Date: Tue, 27 Sep 2016 00:46:10 +0200 Subject: [PATCH 1/2] add test cfg/ignore_version_from_other_platform if different platforms have a dependency to a different version of a crate, only the correct dependency should be downloaded and used --- tests/cfg.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/cfg.rs b/tests/cfg.rs index e8de0101beb..6712af6d869 100644 --- a/tests/cfg.rs +++ b/tests/cfg.rs @@ -228,6 +228,38 @@ fn works_through_the_registry() { ")); } +#[test] +fn ignore_version_from_other_platform() { + let this_family = if cfg!(unix) {"unix"} else {"windows"}; + let other_family = if cfg!(unix) {"windows"} else {"unix"}; + Package::new("foo", "0.1.0").publish(); + Package::new("foo", "0.2.0").publish(); + + let p = project("a") + .file("Cargo.toml", &format!(r#" + [package] + name = "a" + version = "0.0.1" + authors = [] + + [target.'cfg({})'.dependencies] + foo = "0.1.0" + + [target.'cfg({})'.dependencies] + foo = "0.2.0" + "#, this_family, other_family)) + .file("src/lib.rs", "extern crate foo;"); + + assert_that(p.cargo_process("build"), + execs().with_status(0).with_stderr("\ +[UPDATING] registry [..] +[DOWNLOADING] [..] +[COMPILING] foo v0.1.0 +[COMPILING] a v0.0.1 ([..]) +[FINISHED] debug [unoptimized + debuginfo] target(s) in [..] +")); +} + #[test] fn bad_target_spec() { let p = project("a") From 0a4fbbf25b3590df5564a97040df433bf2b3b65f Mon Sep 17 00:00:00 2001 From: Wim Hueskes Date: Tue, 27 Sep 2016 00:55:58 +0200 Subject: [PATCH 2/2] Do not download dependencies from other platforms --- src/cargo/ops/cargo_rustc/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 922da9ccdf8..fe0a9424141 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -454,7 +454,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { let deps = self.resolve.deps(id); let mut ret = try!(deps.filter(|dep| { unit.pkg.dependencies().iter().filter(|d| { - d.name() == dep.name() + d.name() == dep.name() && d.version_req().matches(dep.version()) }).any(|d| { // If this target is a build command, then we only want build // dependencies, otherwise we want everything *other than* build