Repository navigation
fix(package): preserve feature metadata in normalized manifests - #17509
Conversation
|
Thanks for the pull request, and welcome! The Rust Project has assigned @Muscraft (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
Thanks!
Would you mind follow the C-TEST commit structure there? The first commit adds/changes tests, and subsequent fix commit will change the test snapshot, whose diff can make the behavior change more obvious.
There was a problem hiding this comment.
@darkraider01
One important point of C-TEST is that tests should passes in both commits. This ensure commits are bisectable, and snapshot diff clearly reflects behavior change.
There was a problem hiding this comment.
thanks! I updated the test commit so it passes with the existing behavior, then the fix commit changes the snapshot along with the packaging code
| b = [] | ||
| c = { enables = ["a", "b"] } | ||
| c = { enables = ["a", "dev-only/feature", "b"], doc = "Enables a and b." } | ||
| empty = { enables = [], doc = "Enables nothing." } |
There was a problem hiding this comment.
Could you add one more feature only with enables without any other metadata fields?
| a = [] | ||
| b = [] |
There was a problem hiding this comment.
Some design questions I am uncertain:
- In a package that has a mix of array and table syntax, how should we serialize features that still use array syntax?
- If a feature with table syntax only has the
enablesfield, should it be serialized with table or keep the array syntax?
cc @Muscraft, any opinions?
There was a problem hiding this comment.
I went with preserving the syntax used for each feature. So if a manifest mixes arrays and tables, they stay arrays and tables in the packaged manifest. An enables-only table also stays a table.
That felt like the simplest rule, and I added a test for the enables-only case. If there’s a compatibility reason to turn those back into arrays, I’m happy to adjust it.
There was a problem hiding this comment.
Yeah, that is indeed simpler. Also another supporiting argument: tools consuming Cargo.toml would anyway need to handle both syntax. Normalizing to new syntax doesn't really move the needle in terms of compatibility .
There was a problem hiding this comment.
Thanks. I kept the syntax for each feature as written in the original manifest, including enables-only tables, and added a test for that case
There was a problem hiding this comment.
@Muscraft pointed out that cargo publish also normalize [dependencies] like
from
[dependencies]
syn = "1"
to
[dependencies.syn]
version = "1"
We might want to do normalized for [features] table as well when this feature is stabilized, to be consistent. (though the normalization may be conditioned on MSRV if it doesn't use new syntax at all)
The downside is that it may make git diff a bit more larger for cargo vendor users that check in vendored crates, even those new crates don't user feature metadata at all.
Let's move on and track this in the tracking issue.
56d0bb5 to
3045296
Compare
3045296 to
90cd92b
Compare
| a = [] | ||
| b = [] |
There was a problem hiding this comment.
@Muscraft pointed out that cargo publish also normalize [dependencies] like
from
[dependencies]
syn = "1"
to
[dependencies.syn]
version = "1"
We might want to do normalized for [features] table as well when this feature is stabilized, to be consistent. (though the normalization may be conditioned on MSRV if it doesn't use new syntax at all)
The downside is that it may make git diff a bit more larger for cargo vendor users that check in vendored crates, even those new crates don't user feature metadata at all.
Let's move on and track this in the tracking issue.
Update cargo submodule 5 commits in 98a09e7e7d62850f14e5b6132101fc1edd19a16f..3d7cf6e937d6127d0f49881bf689c560b36d35c4 2026-09-21 19:03:16 +0000 to 2026-09-25 01:47:29 +0000 - fix(package): preserve feature metadata in normalized manifests (rust-lang/cargo#17509) - fix(diag): Don't report unused normal deps when static libs are skipped (rust-lang/cargo#17515) - test(builtin-deps): Additional manifest regression tests (rust-lang/cargo#17500) - fix(builtin-deps): Builtin dependencies manifest validation (rust-lang/cargo#17499) - feat(builtin-deps): Add builtin dependencies manifest syntax (rust-lang/cargo#17498) r? ghost
Summary
Preserve feature metadata when generating the normalized
Cargo.tomlforcargo packageandcargo publish.Packaging still removes feature references to dependencies that are excluded from the published package, but now filters the existing
enableslist in place instead of converting every feature definition to the legacy array syntax.Motivation
Feature definitions using the
feature-metadatatable syntax were previously rewritten as arrays during packaging. This discarded metadata such asdoc, preventing registry consumers likecargo infoandcargo metadatafrom accessing it.Preserving the metadata table also ensures future feature metadata fields are not lost during packaging.
Fixes #17472.
Testing
Updated the packaging regression test to cover:
enableslistAlso verified the existing dev-dependency stripping test.