Skip to content
New issue

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

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

Already on GitHub? # to your account

Feature that affects dev dependencies can't be enabled #6915

Closed
dtolnay opened this issue May 7, 2019 · 4 comments · Fixed by #12907
Closed

Feature that affects dev dependencies can't be enabled #6915

dtolnay opened this issue May 7, 2019 · 4 comments · Fixed by #12907
Labels
A-dependency-resolution Area: dependency resolution and the resolver A-features Area: features — conditional compilation C-bug Category: bug

Comments

@dtolnay
Copy link
Member

dtolnay commented May 7, 2019

Problem

I have crates A, B, C with the following manifests:

[package]
name = "a"
version = "0.0.0"

[features]
f = ["b/f"]

[dependencies]
b = { path = "../b" }
[package]
name = "b"
version = "0.0.0"

[features]
f = ["c/f"]

[dev-dependencies]
c = { path = "../c" }
[package]
name = "c"
version = "0.0.0"

[features]
f = []

Expected behavior: I believe it should be possible to build crate A. Running cargo check in crate A should build crate A without feature f and crate B without feature f. Running cargo check --features f in crate A should build crate A with feature f and crate B with feature f, but not C because that is a dev dependency of a dependency.

Actual behavior: crate A cannot be built, with or without f.

$ cargo check

error: failed to select a version for `b`.
    ... required by package `a v0.0.0 (/path/to/a)`
versions that meet the requirements `= 0.0.0` are: 0.0.0

the package `a` depends on `b`, with features: `c` but `b` does not have these features.


failed to select a version for `b` which could resolve this conflict

Possible objection: "but B/f requires C/f, we can't enable B/f without building C!" I don't think this is valid because cargo check --features f in crate B will already build crate B with feature f enabled without building the dev dependency C.


Notes
cargo 1.36.0-nightly (beb8fcb 2019-04-30)

@dtolnay dtolnay added the C-bug Category: bug label May 7, 2019
dtolnay referenced this issue in serde-rs/serde May 7, 2019
Without this:

    error: failed to select a version for `serde_test_suite`.
        ... required by package `serde_test_suite-tests v0.0.0`
    versions that meet the requirements `= 0.0.0` are: 0.0.0

    the package `serde_test_suite-tests` depends on `serde_test_suite`, with features: `serde` but `serde_test_suite` does not have these features.

    failed to select a version for `serde_test_suite` which could resolve this conflict

Seems like a Cargo bug -- I will minimize and report.
@ehuss ehuss added the A-features Area: features — conditional compilation label May 8, 2019
ExpHP added a commit to ExpHP/rsp2 that referenced this issue May 14, 2019
This should finally fix the nightly configuration on travis
BusyJay added a commit to tikv/grpc-rs that referenced this issue Jul 24, 2019
This PR breaks the circle dependencies between grpcio and grpcio-proto
by adding a new crate named tests and examples. We can bring things back
once rust-lang/cargo#6915 is fixed.

The new structure also fixes a problem that crates.io denies to accept
circle dependencies in dev-dependencies. More see rust-lang/cargo#4242.

This PR also updates protobuf-build to the latest version. Note that
until protobuf-build is released, we can't release grpcio-proto.
BusyJay added a commit to tikv/grpc-rs that referenced this issue Jul 24, 2019
This PR breaks the circle dependencies between grpcio and grpcio-proto
by adding a new crate named tests and examples. We can bring things back
once rust-lang/cargo#6915 is fixed.

The new structure also fixes a problem that crates.io denies to accept
circle dependencies in dev-dependencies. More see rust-lang/cargo#4242.

This PR also updates protobuf-build to the latest version.
BusyJay added a commit to tikv/grpc-rs that referenced this issue Jul 24, 2019
This PR breaks the circle dependencies between grpcio and grpcio-proto
by adding a new crate named tests and examples. We can bring things back
once rust-lang/cargo#6915 is fixed.

The new structure also fixes a problem that crates.io denies to accept
circle dependencies in dev-dependencies. More see rust-lang/cargo#4242.

This PR also updates protobuf-build to the latest version.
@Eh2406 Eh2406 added the A-dependency-resolution Area: dependency resolution and the resolver label Aug 13, 2019
@apopiak
Copy link

apopiak commented Mar 20, 2020

Is there a known workaround for this except moving the deps to the dependencies section?

johnpmayer added a commit to johnpmayer/bevy_networking_turbulence that referenced this issue Feb 14, 2021
near-bulldozer bot pushed a commit to near/nearcore that referenced this issue Jun 2, 2021
We're sort of in a weird spot as it is, we have features within `nearcore` that are required but can't be enabled if they depend on crates listed under `dev-dependencies` (bug in cargo: rust-lang/cargo#6915). Temporarily listing them under `dependencies`, fixed the CI testing failures we had while working on #4292 (same error @ailisp highlighted: #4333 (comment)), but as pointed out in #4331 (comment), this method should be out of the question. If we remove it, however, we can't work with the tests that depend on those features.

This PR moves the _previously top-level_ tests into a new crate to have better dependency and feature handling as @matklad suggested

> * [move tests from `/test` folder somewhere -- either to some of the existing packages (neard perhaps?) or into a new `integration-tests` package](#4292 (comment))

This would ensure we have dependencies like `testlib`, `runtime-params-estimator` and `restored-receipts-verifier` that are only needed for testing and depend on nearcore without cyclic dependency issues while having all features relevant to testing in order.

The features within `neard` have been reduced to proxies to `nearcore` features, which partially resolves #4325 (though the intent for that has morphed a bit). This also makes for a cleaner dependency graph from `neard` perspective, removing extraneous dependencies that were previously required.

I also noticed removed the `old_tests` feature that should've been removed along with the rest of it in #928.

Updated some docs and code comments referencing the old `neard` path too.
vherbert added a commit to vherbert/frost-dalek that referenced this issue Nov 30, 2021
@epage
Copy link
Contributor

epage commented Nov 1, 2023

I ran

$ cargo new --lib a
$ cargo new --lib b
$ cargo new --lib c

And replaced the Cargo.tomls with what was in the Issee.

I then ran

$ cargo check
$ cargo check -F f

And it worked.

Seems like this was fixed (maybe when weak/namespaced features were added?). Closing. If there is something I missed, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2023
@dtolnay
Copy link
Member Author

dtolnay commented Nov 1, 2023

Thank you!

The fix bisects to nightly-2021-11-24. The commit range is rust-lang/rust@936f260...65c55bf, in which the only Cargo update is rust-lang/rust#91144. In there, I bet it was #10103, although the PR description does not directly describe the scenario in this issue.

@dtolnay
Copy link
Member Author

dtolnay commented Nov 1, 2023

Confirmed it was #10103.

Glad this works! Hopefully it stays that way — would it be worth reopening this issue to track adding a dedicated test, or are the tests added by #10103 focused on feature cycles good enough coverage for this case?

I'll take a look through the tests myself and send a PR.

bors added a commit that referenced this issue Nov 1, 2023
Add regression test for issue 6915: features and transitive dev deps

Closes #6915.

That issue was fixed without realizing by #10103. In search of test coverage, I looked through `rg '[a-z0-9_-]+ = \["[a-z0-9_-]+/[a-z0-9_-]+"\]' tests/testsuite/` and did not find any existing test that exercises this situation. The tests added by #10103 are focused on cycles and `cargo tree`, which is substantially different from #6915.

Tested by `cargo test --test testsuite -- features::activating_feature_does_not_activate_transitive_dev_dependency`.
LykxSassinator added a commit to LykxSassinator/tikv that referenced this issue Feb 6, 2024
Ref: rust-lang/cargo#6915.

This pr is used to format relevant `cargo.toml` files and tidy the
test crates in the `[dependencies]` section, by moving them to
`[dev-dependencies]`.

By introducing this pr, the unnecessary compilation on test crates when
building the release output can be ignored.

Signed-off-by: lucasliang <nkcs_lykx@hotmail.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-dependency-resolution Area: dependency resolution and the resolver A-features Area: features — conditional compilation C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants