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
Implicit features out of dependencies #4911
Comments
That's right, cargo will create a feature for each optional dependency in your
Once a dependency has been added to a |
@KodrAus but... why? what's the reason for this? Is it something what it is supposed to do or accidental bug which many developers use? I can't find any docs on this, tbh. |
It's definitely intentional, I'm not actually sure where it first came about though. It's a convenient way to toggle optional dependencies when running a build, but unfortunately means you can't just look at the set of features in the manifest to find the ones available to the crate. You could use a library like extern crate cargo_metadata;
fn main() {
let metadata = cargo_metadata::metadata(Some("/path/to/Cargo.toml".as_ref())).unwrap();
let manifest = &metadata.packages[0];
let features = manifest.dependencies
.iter()
.filter_map(|dep| {
if dep.optional {
Some(&dep.name)
}
else {
None
}
})
.chain(manifest.features.keys())
.collect::<Vec<_>>();
println!("features: {:?}", features);
} With a [dependencies]
rand = "*"
uuid = { version = "*", optional = true }
[features]
a = [] You'll get an output of:
|
@KodrAus at this point, rust2rpm is still written in python, so I am relying on Also, what's the exact rules here? All optional deps? Or only those which are not included in any other feature? What about build/dev-dependencies? |
As far as I know the rules are:
I think you'll have to parse the json from |
@ignatenkobrain Hope that helps. |
@xftroxgpx after reading those sentences for 30 mins I found mention of that... So I think from this issue I want improvement of those words to mark that optional deps are also "features". |
EDIT: hey look, I found the last time something like this happened to me, right here: rust-lang/rust#34444 :) |
References: rust-lang/cargo#4911 Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
As there hasn't been any activity here in over 6 months I've marked this as stale and if no further activity happens for 7 days I will close it. I'm a bot so this may be in error! If this issue should remain open, could someone (the author, a team member, or any interested party) please comment to that effect? The team would be especially grateful if such a comment included details such as:
Thank you for contributing! (The cargo team is currently evaluating the use of Stale bot, and using #6035 as the tracking issue to gather feedback.) If you're reading this comment from the distant future, fear not if this was closed automatically. If you believe it's still an issue please leave a comment and a team member can reopen this issue. Opening a new issue is also acceptable! |
As I didn't see any updates in 30 days I'm going to close this. Please see the previous comment for more information! |
Let's take rand's Cargo.toml, it has
So strictly speaking it doesn't have
serde
andrustc-serialize
" features, right?There is tool called stratisd which has
in it. Cargo doesn't reject this, but happily passes that feature (serde) and code in uuid handles that just fine.
Does cargo automatically create feature for each dependency (only optional ones?, only non-dev/non-build?), is it expected or should we force people to explicitly specify them? What are the rules here?
This came out of my RPM packaging efforts where we do Provides for each feature crate provides and Requires for everything what is mentioned on the other side. So in this case we get unsatisfied requirement.
The text was updated successfully, but these errors were encountered: