Skip to content

Commit 67e14be

Browse files
committed
fix(bindeps): target field specified and optional = true coexist
> Adapted from #11183 Previously, `is_dep_activated` depends on `activated_dependencies`, which is a map of `PackageFeaturesKey` to its own activated `DepFeature`s. `PackageFeaturesKey` in feature resolver is always comprised of * A `PackageId` of a given dependency, and * A enum value that helps decoupling activated features for that dependency. Currently depending on the type of given dependency. Looking into issue 10526, it has an `activated_dependencies` of ``` { (mycrate, NormalOrDev) -> [dep:mybindep] } ``` However, this [line][1] accidentally use a parent's `pkgid` and a dependency's `FeaturesFor` to compose a key: ``` (mycrate, ArtifactDep("x86_64-unknown-linux-gnu")) ``` That is never a valid key to query features for artifacts dependency. A valid key should be comprised of components both from the parent: ``` (mycrate, NormalOrDev) ``` Or both from the dependency itself: ``` (mybindep, ArtifactDep("x86_64-unknown-linux-gnu")) ``` This `unit_for` should already contain its own artifact dep information inside `artifact_target_for_features`, so we don't need to map any `dep.artifact()` here. [1]: https://github.com/rust-lang/cargo/blob/a2ea66bea6fe8156444144e98911d073d56c2c0c/src/cargo/core/compiler/unit_dependencies.rs#L1106-L1107
1 parent 98f0577 commit 67e14be

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ impl<'a, 'cfg> State<'a, 'cfg> {
11031103
// If this is an optional dependency, and the new feature resolver
11041104
// did not enable it, don't include it.
11051105
if dep.is_optional() {
1106-
let features_for = unit_for.map_to_features_for(dep.artifact());
1106+
let features_for = unit_for.map_to_features_for(None);
11071107
if !self.is_dep_activated(pkg_id, features_for, dep.name_in_toml()) {
11081108
return false;
11091109
}

tests/testsuite/artifact_dep.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,6 @@ fn calc_bin_artifact_fingerprint() {
23452345

23462346
#[cargo_test]
23472347
fn with_target_and_optional() {
2348-
// This is a incorrect behaviour got to be fixed.
23492348
// See rust-lang/cargo#10526
23502349
if cross_compile::disabled() {
23512350
return;
@@ -2386,12 +2385,15 @@ fn with_target_and_optional() {
23862385

23872386
p.cargo("check -Z bindeps -F d1 -v")
23882387
.masquerade_as_nightly_cargo(&["bindeps"])
2389-
.with_stderr_contains(
2388+
.with_stderr(
23902389
"\
2391-
[ERROR] environment variable `CARGO_BIN_FILE_D1` not defined
2390+
[COMPILING] d1 v0.0.1 [..]
2391+
[RUNNING] `rustc --crate-name d1 [..]--crate-type bin[..]
2392+
[CHECKING] foo v0.0.1 [..]
2393+
[RUNNING] `rustc --crate-name foo [..]--cfg[..]d1[..]
2394+
[FINISHED] dev [..]
23922395
",
23932396
)
2394-
.with_status(101)
23952397
.run();
23962398
}
23972399

0 commit comments

Comments
 (0)