-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(manifest)!: implement feature-metadata RFC3416 #15056
base: master
Are you sure you want to change the base?
feat(manifest)!: implement feature-metadata RFC3416 #15056
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @epage (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
|
||
impl FeatureDefinition { | ||
/// Returns the features that this feature enables. | ||
pub fn enables(&self) -> &[String] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method could also return an impl Iterator<Item = String>
if preferred.
let feature_array = feature_deps | ||
.enables() | ||
.iter() | ||
.filter(|feature_dep| { | ||
let feature_value = FeatureValue::new(InternedString::new(feature_dep)); | ||
match feature_value { | ||
FeatureValue::Dep { dep_name } | ||
| FeatureValue::DepFeature { dep_name, .. } => { | ||
let k = &manifest::PackageName::new(dep_name.to_string()).unwrap(); | ||
dep_name_set.contains(k) | ||
} | ||
_ => true, | ||
} | ||
_ => true, | ||
} | ||
}); | ||
}) | ||
.cloned() | ||
.collect(); | ||
*feature_deps = FeatureDefinition::Array(feature_array); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For compatibility, this uses the array syntax for generating the normalized manifest, even when the table syntax is used by authors (see the corresponding integration test).
790a0e8
to
338281e
Compare
for (feature, feature_definition) in features { | ||
match feature_definition { | ||
FeatureDefinition::Array(..) => {} | ||
FeatureDefinition::Metadata(FeatureMetadata { _unused_keys, .. }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven't got time into full review, though I think the meta field should be behind a nightly feature flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Should there be a Cargo unstable feature for this change?
Yes. Probably behind a cargo-feature "feature-metadata".
- This PR of course introduces a breaking change in the
cargo-util-schemas
crate, is there anything to do regarding this in this PR?
Could add a doc comment on relevant field/variant indicating it is unstable/nightly only.
cargo/crates/cargo-util-schemas/src/manifest/mod.rs
Lines 936 to 937 in f15df8f
/// Unstable feature `-Ztrim-paths`. | |
pub trim_paths: Option<TomlTrimPaths>, |
There is a CI job checking if a member crate needs a version bump. It didn't warn you so I assume it has already been bumped in this release cycle. You do not need to do anything.
- Should this PR also attempt to update
core::Summary
or should this be left to future implementations of RFCs providing other keys (e.g.,doc
)?
Summary is more like a thing for dependency resolution. I think we revisit it in the future. Regardless, see epage's comment #14157 (comment) that the feature itself is not particularly useful until other RFC gets merged. Anyway, thanks for the contribution!
What is your motivation for moving this forward? In #14157 (comment) I was wondering if this was worth it without a feature depending on it. |
I have recently published featurecomb, a crate that allows to define relations between Cargo features in manifests (e.g., mutual exclusion, or a feature requiring another one to be enabled), and to enforce these relations through a proc-macro that reads the manifest and generates I wanted to see how much of this could be introduced into Cargo (I am aware of other existing effort in that direction), and the first step for that was to tackle I have introduced a |
Interesting effort. Some cautions though
|
What does this PR try to resolve?
This PR implements RFC3416:
feature-metadata
.It introduces an alternate syntax to define crate features in manifests: instead of simply being an array of features the feature enables, it can now be a table with, for now, one required array key,
enables
, which is equivalent to the existing array. This lays the groundwork for later supporting additional keys in that table, to provide feature metadata.Related to #14157
How should we test and review this PR?
Integrations tests are included in this PR, including for the normalized manifest used for publishing on a crate registry.
Additional information
Questions
cargo-util-schemas
crate, is there anything to do regarding this in this PR?core::Summary
or should this be left to future implementations of RFCs providing other keys (e.g.,doc
)?