-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Allow specifying dependencies per feature #5954
Comments
I think that this may also largely be supported by #5653? May make it a bit easier to specify as well! |
@alexcrichton There might be dependencies that are relevant only for a certain feature. Is there a way to express that? Edit: |
Encountered a similar issue where a workspace is split into multiple sub-crates, and each rely on specifying shared features of the main crate dependency. Something like this doesn't seem to work at all: [features]
default = [ "fwupd", "system76" ]
fwupd = []
system76 = []
[target.'cfg(all(not(feature = "fwupd"), feature = "system76"))'.dependencies]
firmware-manager = { path = "../", default-features = false, features = [ "system76" ] }
[target.'cfg(all(feature = "fwupd", not(feature = "system76")))'.dependencies]
firmware-manager = { path = "../", default-features = false, features = [ "fwupd" ] }
[target.'cfg(all(feature = "fwupd", feature = "system76"))'.dependencies]
firmware-manager = { path = "../", default-features = false, features = [ "fwupd", "system76" ] }
|
Hopefully this will save someone an hour of googling. If you have a library In [dependencies]
b-5 = { package = "b", version = "^5", optional = true }
b-6 = { package = "b", version = "^6", optional = true }
[features]
default = ["use-b-6"]
use-b-5 = ["b-5"]
use-b-6 = ["b-6"] Create a #[cfg(feature = "use-b-5")]
pub use b_5::*;
#[cfg(feature = "use-b-6")]
pub use b_6::*; Instead of Application that uses [dependencies]
b = "^5"
a = { version = "*", default-features = false, features = ["use-b-5"] } This is more work than it should be.... |
With package renaming, we've satisfied the main request and there is a great example just above of that. As for this case [features]
default = [ "fwupd", "system76" ]
fwupd = []
system76 = []
[target.'cfg(all(not(feature = "fwupd"), feature = "system76"))'.dependencies]
firmware-manager = { path = "../", default-features = false, features = [ "system76" ] }
[target.'cfg(all(feature = "fwupd", not(feature = "system76")))'.dependencies]
firmware-manager = { path = "../", default-features = false, features = [ "fwupd" ] }
[target.'cfg(all(feature = "fwupd", feature = "system76"))'.dependencies]
firmware-manager = { path = "../", default-features = false, features = [ "fwupd", "system76" ] } that can be done as [features]
default = [ "fwupd", "system76" ]
fwupd = ["dep:firmware-manager", "firmware-manager/fwupd"]
system76 = ["dep:firmware-manager", "firmware-manager/system76"]
[dependencies]
firmware-manager = { path = "../", default-features = false, optional = true } As this seems resolved, I'm closing it. If there is a reason to re-open this, let us know! |
I need to use something like that but for a different use case. I need to activate a feature flag on a dependency when that dependency is activated and the other feature flag is activated as well: [features]
flag1 = ["crate1"]
flag2 = ["crate2"]
someflag = []
[target.'cfg(all(feature = "flag1", feature = "someflag"))'.dependencies]
crate1 = { ..., features = ["someflag"] }
[target.'cfg(all(feature = "flag1", not(feature = "someflag")))'.dependencies]
crate1 = { ..., features = [] }
[target.'cfg(all(feature = "flag2", feature = "someflag"))'.dependencies]
crate2 = { ..., features = ["someflag"] }
[target.'cfg(all(feature = "flag2", not(feature = "someflag")))'.dependencies]
crate2 = { ..., features = ["someflag"] } If I do something like this: [features]
flag1 = ["crate1"]
flag2 = ["crate2"]
someflag = ["crate1/someflag", "crate2/someflag"] Then both crates are going to be activated when only the flag |
Is weak features what you need? someflag = ["crate1?/someflag", "crate2?/someflag"] |
@epage Yes exactly! I didn't know it even existed, thanks a lot 🙏 |
There is still a use case that is not covered with the weak feature. @epage [features]
default = ["myfeature"]
myfeature = []
simd = []
[target.'cfg(all(feature = "simd", feature = "myfeature"))'.dependencies]
base64-simd = "0.8.0"
[target.'cfg(all(not(feature = "simd"), feature = "myfeature"))'.dependencies]
base64 = "0.22.0" I know you can do |
Note that we have
which in various ways cover that case I believe. |
Most feature-dependency correspondences can currently be modeled by making the dependency optional but having the feature depend on this.
This is not possible (from what I see) if "feature-a" and "feature-b" depend on the same crate but in different versions, as each crate can only be specified once.
A syntax like the following would seem consistent for that case (and could also provide another way of specifying feature-dependant dependencies in general).
The text was updated successfully, but these errors were encountered: