-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Feature enabled, but dependent crate not added #15490
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
Comments
This can be worked around by setting So somehow (note: this is a modified version where $ cargo clean
Removed 867 files, 153.7MiB total
$ cargo test --workspace
Compiling subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
Compiling mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
error[E0463]: can't find crate for `quote`
--> subcrate/build.rs:1:27
|
1 | #[cfg(feature = "quote")] extern crate quote as _;
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
For more information about this error, try `rustc --explain E0463`.
error: could not compile `subcrate` (build script) due to 1 previous error
$ cargo test --workspace -F quote
Compiling proc-macro2 v1.0.95
Compiling unicode-ident v1.0.18
Compiling quote v1.0.40
Compiling subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
Compiling rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
Compiling mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.62s
Running unittests src/lib.rs (target/debug/deps/mid-b6c7b47a02cb0245) $ cargo tree --no-default-features -e features --workspace
mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
[dev-dependencies]
└── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
├── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
├── mid feature "default"
│ └── mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid) (*)
└── mid feature "quote"
├── mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid) (*)
└── subcrate feature "quote"
└── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
$ cargo tree --no-default-features -e features --workspace -F quote
mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
[dev-dependencies]
└── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
[build-dependencies]
└── quote feature "default"
├── quote v1.0.40
│ └── proc-macro2 v1.0.95
│ └── unicode-ident feature "default"
│ └── unicode-ident v1.0.18
└── quote feature "proc-macro"
├── quote v1.0.40 (*)
└── proc-macro2 feature "proc-macro"
└── proc-macro2 v1.0.95 (*)
rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
├── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate) (*)
├── mid feature "default"
│ └── mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid) (*)
└── mid feature "quote" (command-line)
├── mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid) (*)
└── subcrate feature "quote" (command-line)
└── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate) (*)
subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate) (*)
Trying different combinations:
Looking through logs: When we walk the features, the dep is already missingcompare the failing case:
against the success case:
So looking at our walking of dependencies
|
My current reproduction steps $ cargo init --lib
$ cargo new mid --lib
$ cargo new subcrate --lib
[workspace]
resolver = "2"
members = [ "mid","subcrate"]
[package]
name = "rustc-test"
version = "0.1.0"
edition = "2024"
[dependencies]
mid = { version = "0.1.0", path = "mid", features = ["quote"] }
subcrate = { version = "0.1.0", path = "subcrate", default-features = false }
[features]
quote = ["subcrate/quote"]
[package]
name = "mid"
version = "0.1.0"
edition = "2024"
[dev-dependencies]
subcrate = { path = "../subcrate", default-features = false }
[features]
quote = ["subcrate/quote"]
[package]
name = "subcrate"
version = "0.1.0"
edition = "2024"
[dependencies]
quote = { version = "1.0.40", optional = true } |
I think I see the problem. It lies in this line here. The problem is that it is considering dev-dependencies enabled or disabled as a global property. However, there's an interesting interplay of the There needs to be some more nuance there, perhaps differentiating if something is being resolved as a root versus as a dependency. Need to think a little if that makes sense. |
This is a test for rust-lang#15490
I have a WIP up here: https://github.com/ehuss/cargo/commits/feature-dev-deps/ The general idea is that the feature resolver needs to mirror the same behavior in the dependency resolver here. It mostly works except one test is failing. I'm also a little unhappy with the added complexity. It could push this state into |
Problem
Feature enabled, but dependent crate not added
Using build-dependencies, dev-dependencies, and dependencies in the dependency graph
Steps
Run this bash script
Output:
Possible Solution(s)
No response
Notes
About
--no-default-features
on--workspace
Version
The text was updated successfully, but these errors were encountered: