Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix required-features using renamed dependencies. #7855

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,11 @@ fn resolve_all_features(

// Include features enabled for use by dependencies so targets can also use them with the
// required-features field when deciding whether to be built or skipped.
for (dep, _) in resolve_with_overrides.deps(package_id) {
for feature in resolve_with_overrides.features(dep) {
features.insert(dep.name().to_string() + "/" + feature);
for (dep_id, deps) in resolve_with_overrides.deps(package_id) {
for feature in resolve_with_overrides.features(dep_id) {
for dep in deps {
features.insert(dep.name_in_toml().to_string() + "/" + feature);
}
}
}

Expand Down
93 changes: 93 additions & 0 deletions tests/testsuite/required_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,3 +1163,96 @@ available binaries: foo1, foo2",
)
.run();
}

#[cargo_test]
fn renamed_required_features() {
// Test that required-features uses renamed package feature names.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2018"

[[bin]]
name = "x"
required-features = ["a1/f1"]

[dependencies]
a1 = {path="a1", package="a"}
a2 = {path="a2", package="a"}
"#,
)
.file(
"src/bin/x.rs",
r#"
fn main() {
a1::f();
a2::f();
}
"#,
)
.file(
"a1/Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"

[features]
f1 = []
"#,
)
.file(
"a1/src/lib.rs",
r#"
pub fn f() {
if cfg!(feature="f1") {
println!("a1 f1");
}
}
"#,
)
.file(
"a2/Cargo.toml",
r#"
[package]
name = "a"
version = "0.2.0"

[features]
f2 = []
"#,
)
.file(
"a2/src/lib.rs",
r#"
pub fn f() {
if cfg!(feature="f2") {
println!("a2 f2");
}
}
"#,
)
.build();

p.cargo("run")
.with_status(101)
.with_stderr(
"\
[ERROR] target `x` in package `foo` requires the features: `a1/f1`
Consider enabling them by passing, e.g., `--features=\"a1/f1\"`
",
)
.run();

p.cargo("build --features a1/f1").run();
p.rename_run("x", "x_with_f1").with_stdout("a1 f1").run();

p.cargo("build --features a1/f1,a2/f2").run();
p.rename_run("x", "x_with_f1_f2")
.with_stdout("a1 f1\na2 f2")
.run();
}