Skip to content

Incorrect dev-dependency feature resolution #1796

@farcaller

Description

@farcaller

If same crate is used in both dependencies and dev-dependencies with the only change of features, that features leak from dev-dependencies to dependencies.

Here's the smallest test case I managed to generate.

Root crate Cargo.toml:

[package]
name = "test"
version = "0.1.0"
authors = ["Vladimir Pouzanov <farcaller@gmail.com>"]

[lib]
name = "test"
crate-type = ["lib"]

[target.thumbv6-none-eabi.dependencies.core]
git = "https://github.com/hackndev/rust-libcore"

[dev-dependencies]
expectest = "*"

[dev-dependencies.dep]
path = "./dep"
features = ["replayer"]

[dependencies.dep]
path = "./dep"

this crate uses expectest for testing only and a dep crate for either testing or runtime build. It is expected to be a cross-compiled staticlib, so it does not depend on core (neither is dep).

Dep is defined like this:

[package]

name = "dep"
version = "1.0.0"
authors = ["Vladimir Pouzanov <farcaller@gmail.com>"]

[lib]
name = "dep"
path = "lib.rs"
crate-type = ["rlib"]

[features]
replayer = ["expectest"]

[target.thumbv6-none-eabi.dependencies.core]
git = "https://github.com/hackndev/rust-libcore"

[dependencies.expectest]
optional = true

If the replayer feature is used, this crate is being built for test, thus requiring expectest in runtime. Otherwise this crate is std-less as well.

When cross-compiled, the expected outcome is to have test and dep crates being cross-built, where dep is being built without expectest. This is not the case:

% cargo build --target=thumbv6-none-eabi --verbose -j1 --lib
   Compiling rustc-serialize v0.3.15
     Running `rustc /Users/farcaller/.cargo/registry/src/github.com-0a35038f75765ae4/rustc-serialize-0.3.15/src/lib.rs --crate-name rustc_serialize --crate-type lib -g -C metadata=c1e8163a38ed3d54 -C extra-filename=-c1e8163a38ed3d54 --out-dir /Users/farcaller/temp/bug/test/target/thumbv6-none-eabi/debug/deps --emit=dep-info,link --target thumbv6-none-eabi -L dependency=/Users/farcaller/temp/bug/test/target/thumbv6-none-eabi/debug/deps -L dependency=/Users/farcaller/temp/bug/test/target/thumbv6-none-eabi/debug/deps -Awarnings`
/Users/farcaller/.cargo/registry/src/github.com-0a35038f75765ae4/rustc-serialize-0.3.15/src/lib.rs:1:1: 1:1 error: can't find crate for `std`
/Users/farcaller/.cargo/registry/src/github.com-0a35038f75765ae4/rustc-serialize-0.3.15/src/lib.rs:1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT

rustc_serialize is being pulled in as a test dependency through test -> dep -> expectest chain and fails to compile in cross environment.

Metadata

Metadata

Assignees

Labels

A-featuresArea: features — conditional compilationC-bugCategory: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions