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.
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.
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.
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.
- 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-schemascrate, 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
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::Summaryor 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
|
This comment has been minimized.
This comment has been minimized.
|
I want to invest some time to drive progress on the whole "feature documentation" topic, And I see we already have some code :) @AudaciousAxiom it looks like this PR stalled, is that something I can help with or even take over? |
905820c to
9b4843c
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I've rebased and squashed the existing fixup commits; the new fixup commit is for the differences in tests, which are just the slightly changed Cargo output. @syphar I haven't been through the previous PR comments yet; feel free to point out any comment that still needs addressing or new changes needed due to the modifications of the codebase in the meantime. |
| ... | ||
|
|
||
| ... | ||
|
|
||
| ... |
There was a problem hiding this comment.
why multiple multiline wildcards?
There was a problem hiding this comment.
I think I was under the impression that might otherwise result in some false negatives; I've replaced them with a single wildcard.
4c785a0 to
7016b1c
Compare
|
@weihanglo Thanks for the review! I've fixed the commit history, moved the test commit after the implementation commit as I see you want each commit to pass the tests, and added the changes from the review as fixup commits. I'll simply autosquash before merging. |
Thanks, though rebasing is easier for us to review. Under most circumstances, we don't need contributors to keep the edit history. Also, the paragraph you quote actually prefers test commits placed before fix commits, so that the git diff can show the behavior change. See those examples in that note, or some newers examples like #17356 and #17337 |
| ``` | ||
|
|
||
| This is equivalent to the array-of-strings syntax. | ||
| Support for other keys should be added later. |
There was a problem hiding this comment.
Look at other unstable for example min-publish-age, we add some doc examples that is meant to be copied verbatim when stabilization.
Above just FYI, docs updates don't block this PR merge.
There was a problem hiding this comment.
Thanks for pointing that out; I didn't include this in this round to not further delay the merge if you want it now.
There was a problem hiding this comment.
I've opened #17446 to update the documentation when this eventually stabilizes; I don't think this can be really be added as a doc snippet to the unstable feature docs as this is not purely additive.
There was a problem hiding this comment.
We can't really merge #17446 now but when stabilizing.
Thanks it for doing it promptly :)
7016b1c to
fcb04c6
Compare
Thanks, I'll keep that in mind, this really depends on the project.
I did look, but all of these are bug fixes; it makes sense to me to first acknowledge the bug with tests, and then fix it and update the tests atomically, but I wasn't sure what to do for this PR, as this is a purely additive feature; adding the tests first wouldn't allow them to pass.
I've autosquashed the fixup commits; feel free to further edit the commits as you want. |
fcb04c6 to
5110662
Compare
I tweaked a bit the tests. Thanks for the contribution anyway! |
Update cargo submodule 26 commits in e8cb624d5701824f46a2ec5873cfd59ee3d2f66c..b2e9d5f9db3fb1c454ab84f10c16508984a266e2 2026-08-22 00:23:45 +0000 to 2026-09-02 14:49:16 +0000 - fix(parser): Resolve theoretical use-after-free (rust-lang/cargo#17428) - fix(trim-paths)!: remove default scope from release profile (rust-lang/cargo#17424) - fix(git): Use git's 429 retry, when available (rust-lang/cargo#17422) - Avoid passing search path (-L) args when they are passed as --extern (rust-lang/cargo#17410) - chore(deps): update crate-ci/typos action to v1.50.0 (rust-lang/cargo#17417) - test: Move -Z onto its own line (rust-lang/cargo#17416) - chore(triagebot): enable `@rustbot merge/delegate` (rust-lang/cargo#17415) - Micro-optimize two package dir functions (rust-lang/cargo#17413) - perf: Do not build SBOM if user has not set build.sbom (rust-lang/cargo#17412) - feat(manifest)!: implement feature-metadata RFC3416 (rust-lang/cargo#15056) - Cargo profiling improvements (rust-lang/cargo#17411) - test(git): Remove gix override run in CI and the mode in code (rust-lang/cargo#17405) - perf(git): Reduce extra work when using git-cli (rust-lang/cargo#17406) - feat(resolver): Stabilize min-publish-age (rust-lang/cargo#17335) - fix(git): Remove ref status update when showing progress (rust-lang/cargo#17400) - revert: refactor: move sysroot lookup to GlobalContext (rust-lang/cargo#17401) - fix(run): Printing a new line to avoid overwriting error code after \r (rust-lang/cargo#17373) - fix(trim-paths): custom workspace-relative member paths remap (rust-lang/cargo#17366) - fix(home): rustdoc lint (rust-lang/cargo#17394) - feat(diag): Stabilize cargo-lints (rust-lang/cargo#17298) - chore(deps): Update partial_ref to v0.3.4 (rust-lang/cargo#17392) - refactor: remove ad-hoc `subslice_range` (rust-lang/cargo#17390) - docs(changelog): move build-dir new layout to Changed (rust-lang/cargo#17387) - chore(deps): update msrv (1 version) to v1.98 (rust-lang/cargo#17386) - docs: Use mdbook admonitions (rust-lang/cargo#17384) - chore(ci): exclude resolver-tests from intra doc link checks (rust-lang/cargo#17385)
View all comments
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-schemascrate, is there anything to do regarding this in this PR?core::Summaryor should this be left to future implementations of RFCs providing other keys (e.g.,doc)?