Skip to content

feat(metadata): mirror package features in features_v2 - #17517

Merged
weihanglo merged 3 commits into
rust-lang:masterfrom
darkraider01:metadata-features-v2
Sep 27, 2026
Merged

weihanglo merged 3 commits into
rust-lang:masterfrom
darkraider01:metadata-features-v2

Conversation

@darkraider01

@darkraider01 darkraider01 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR try to resolve?

Closes #17507.

With cargo-features = ["feature-metadata"], cargo metadata --format-version 1 now includes a features_v2 map alongside the existing features map. Each feature has an enables array and, when specified in the manifest, a doc string. The new field is omitted when feature-metadata is not enabled, preserving stable metadata output.

The map includes array-form and table-form features, empty features, and implicit optional-dependency features. Feature documentation is read from the normalized manifest during package serialization; the resolver and Summary remain unchanged.

This branch also preserves feature metadata when a manifest is normalized for packaging, so the metadata remains available after packaging.

How to test and review this PR?

The focused test is metadata::cargo_metadata_features_v2 in tests/testsuite/metadata.rs. Existing metadata snapshots verify that features_v2 is absent without feature-metadata. The output format is documented in doc/book/src/reference/unstable.md.

Validated locally with:

cargo test --test testsuite metadata::
cargo test --test testsuite features_namespaced::json_exposed -- --exact
cargo test --test testsuite script::cargo::
cargo test --test testsuite alt_registry::
cargo fmt --check

@rustbot rustbot added A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 25, 2026
@darkraider01
darkraider01 marked this pull request as draft September 25, 2026 15:04
@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Muscraft, @epage, @weihanglo
  • @Muscraft, @epage, @weihanglo expanded to Muscraft, epage, weihanglo
  • Random selection from Muscraft, epage, weihanglo

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2026
@darkraider01

darkraider01 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

I’ve updated this since the original comment: features_v2 is now emitted only when feature-metadata is enabled, so stable cargo metadata output stays unchanged.
I kept it alongside features to preserve the existing format. When enabled, it mirrors every feature, including empty and implicit optional-dependency features, so tools can use one map without merging in documentation separately.
The doc value comes from the normalized manifest during serialization. Summary and the resolver remain unchanged. The keys match the manifest syntax (enables and doc), and doc is omitted when it isn’t supplied.

Comment thread tests/testsuite/metadata.rs
Comment thread tests/testsuite/script/cargo.rs Outdated
Comment thread tests/testsuite/alt_registry.rs Outdated
Comment thread doc/book/src/commands/cargo-metadata.md Outdated
@darkraider01
darkraider01 force-pushed the metadata-features-v2 branch 3 times, most recently from e04f510 to aa40ace Compare September 25, 2026 20:07
@darkraider01
darkraider01 marked this pull request as ready for review September 25, 2026 20:13
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2026
Comment thread doc/book/src/reference/unstable.md Outdated
Comment thread tests/testsuite/metadata.rs Outdated

@weihanglo weihanglo Sep 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @darkraider01! One small policy-related question before merging this.

Just noticed a codex/ branch among your recent Cargo works. Using LLM for things like understanding codebase is completely fine. However, our policy has some requirements that if PR was originally created by LLM, a pre-arranged reviewer and a disclosure are required. Also, communication shouldn't be LLM generated at all.

Could you let me know roughly how you used Codex/LLM here, and whether any of them was originally generated by LLM? Thanks!

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi yes, sorry that was something very silly, i mostly use LLMS to review my work to find any other gaps left, so that just my lazy work when also asked it to push it after reviewing. That's why it was in draft, im sorry for the troubles!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Just be sure to follow the policy also for future contributions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Just be sure to follow the policy also for future contributions.

@weihanglo
weihanglo added this pull request to the merge queue Sep 27, 2026
Merged via the queue into rust-lang:master with commit 7521c3f Sep 27, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 27, 2026
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Sep 30, 2026
Update cargo submodule

8 commits in 3d7cf6e937d6127d0f49881bf689c560b36d35c4..f3865b2a4d1acc5276f6b3c67d0e057f4dab3928
2026-09-25 01:47:29 +0000 to 2026-09-29 19:58:08 +0000
- fix(config): Proper dotted tuple support with legacy fallback (rust-lang/cargo#17536)
- refactor: Rename internal content from target-triple to target-tuple (rust-lang/cargo#17535)
- docs(changelog): remove duplicate items (rust-lang/cargo#17528)
- chore: bump to 0.102.0; update changelog (rust-lang/cargo#17525)
- feat(metadata): mirror package features in features_v2 (rust-lang/cargo#17517)
- feat(config): Add build.profile, install.profile (rust-lang/cargo#17215)
- feat(builtin-deps): Add `SourceKind::Builtin` (rust-lang/cargo#17513)
- fix(compilation): Preventing OUT_DIR env var from leaking into cargo run after build.rs run (rust-lang/cargo#17503)

r? ghost
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Sep 30, 2026
Update cargo submodule

8 commits in 3d7cf6e937d6127d0f49881bf689c560b36d35c4..f3865b2a4d1acc5276f6b3c67d0e057f4dab3928
2026-09-25 01:47:29 +0000 to 2026-09-29 19:58:08 +0000
- fix(config): Proper dotted tuple support with legacy fallback (rust-lang/cargo#17536)
- refactor: Rename internal content from target-triple to target-tuple (rust-lang/cargo#17535)
- docs(changelog): remove duplicate items (rust-lang/cargo#17528)
- chore: bump to 0.102.0; update changelog (rust-lang/cargo#17525)
- feat(metadata): mirror package features in features_v2 (rust-lang/cargo#17517)
- feat(config): Add build.profile, install.profile (rust-lang/cargo#17215)
- feat(builtin-deps): Add `SourceKind::Builtin` (rust-lang/cargo#17513)
- fix(compilation): Preventing OUT_DIR env var from leaking into cargo run after build.rs run (rust-lang/cargo#17503)

r? ghost
@rustbot rustbot added this to the 1.101.0 milestone Sep 30, 2026
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Oct 1, 2026
Update cargo submodule

8 commits in 3d7cf6e937d6127d0f49881bf689c560b36d35c4..f3865b2a4d1acc5276f6b3c67d0e057f4dab3928
2026-09-25 01:47:29 +0000 to 2026-09-29 19:58:08 +0000
- fix(config): Proper dotted tuple support with legacy fallback (rust-lang/cargo#17536)
- refactor: Rename internal content from target-triple to target-tuple (rust-lang/cargo#17535)
- docs(changelog): remove duplicate items (rust-lang/cargo#17528)
- chore: bump to 0.102.0; update changelog (rust-lang/cargo#17525)
- feat(metadata): mirror package features in features_v2 (rust-lang/cargo#17517)
- feat(config): Add build.profile, install.profile (rust-lang/cargo#17215)
- feat(builtin-deps): Add `SourceKind::Builtin` (rust-lang/cargo#17513)
- fix(compilation): Preventing OUT_DIR env var from leaking into cargo run after build.rs run (rust-lang/cargo#17503)

r? ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo metadata output for feature metadata

3 participants