mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Auto merge of #7855 - ehuss:fix-required-features-renamed, r=alexcrichton
Fix required-features using renamed dependencies. The dep_name/feat_name syntax in required-features should use the "name in toml" for dep_name, not the actual package name. Otherwise, it is impossible to actually enable the feature (because the `--features` flag expects a "name in toml").
This commit is contained in:
commit
06834dcaf2
@ -903,9 +903,11 @@ fn resolve_all_features(
|
|||||||
|
|
||||||
// Include features enabled for use by dependencies so targets can also use them with the
|
// 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.
|
// required-features field when deciding whether to be built or skipped.
|
||||||
for (dep, _) in resolve_with_overrides.deps(package_id) {
|
for (dep_id, deps) in resolve_with_overrides.deps(package_id) {
|
||||||
for feature in resolve_with_overrides.features(dep) {
|
for feature in resolve_with_overrides.features(dep_id) {
|
||||||
features.insert(dep.name().to_string() + "/" + feature);
|
for dep in deps {
|
||||||
|
features.insert(dep.name_in_toml().to_string() + "/" + feature);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1163,3 +1163,96 @@ available binaries: foo1, foo2",
|
|||||||
)
|
)
|
||||||
.run();
|
.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();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user