Skip to content

Commit

Permalink
Auto merge of #3123 - wimh:platform_versions, r=alexcrichton
Browse files Browse the repository at this point in the history
Don't download dependencies from other platforms

Having a Cargo.toml which looks like this:

            [package]
            name = "a"
            version = "0.0.1"
            authors = []

            [target.'cfg(unix)'.dependencies]
            foo = "0.1.0"

            [target.'cfg(windows)'.dependencies]
            foo = "0.2.0"

This would still download foo version 0.2.0 on unix. I think there is no need to do that, but please correct me if I'm wrong.

This was triggered by [this](http://stackoverflow.com/questions/39709542/why-does-the-last-platform-specific-dependency-take-precedence-in-cargo) stackoverflow question, but that situation is more complicated, as the version is the same, just the features are different. This PR will not solve that bug. If you want me to include that too, I would have to debug a bit more first....
  • Loading branch information
bors authored Sep 27, 2016
2 parents 26dcd3e + 0a4fbbf commit 22bd52d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_rustc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions tests/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 22bd52d

Please sign in to comment.