-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC: Unblock Cargo feature metadata #3416
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
Merged
epage
merged 45 commits into
rust-lang:master
from
tgross35:feature-descriptions-doc-cfg
Jun 27, 2024
Merged
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
d58366d
Added feature-descriptions-doc-cfg RFC
tgross35 c9a9874
Update docs.rs link
tgross35 37058e1
Add note about argfile
tgross35 d461faf
Add note about serde
tgross35 65615b2
Add note on build system tools
tgross35 35ca770
Rename json-config -> config-json
tgross35 be9b7c2
Complete all RFC sections
tgross35 a0966ab
Rename feature, update related links
tgross35 c5ab809
Add note about overrides
tgross35 11f696e
Correct toml mistake
tgross35 381afba
Fix links
tgross35 64ce8ca
Clean up clean up everybody everywhere
tgross35 47ad04e
Add note about dependencies
tgross35 6c6ad6d
Split feature-metadata-doc-config into feature-metadata and rustdoc-c…
tgross35 4dd05e3
Initial updates based on review
tgross35 cea7180
Update two from the review round
tgross35 4ab3a6f
Updates round three from review
tgross35 5f48f2d
Updates round four
tgross35 19c3521
Updates round five
tgross35 32174e8
Updates round six
tgross35 cbc31d5
Updates regarding parser
tgross35 97e8301
Clarify markdown status for documentation
tgross35 fff9af1
Add note about optional dev dependencies
tgross35 f1fb220
Remove unstable flag
tgross35 98dbaa1
Add suggestion about rust-version flag
tgross35 8cab2f0
Move deny deprecated features to future possibilities
tgross35 fe7767b
Adjust mentions of 'unstable' to 'stable', refactpr sections
tgross35 b952ce1
Update some links
tgross35 9b2a044
Add notes about public=true default and index changes
tgross35 15a2432
Add note about doc in index
tgross35 88a3447
Add note about naming choice
tgross35 e36b155
Add markdown vs. plaintext as an unresolved question
tgross35 397d47e
Rename 'requires' to 'enables'
tgross35 f3b862b
Update documentation about private feature usage
tgross35 0c1a00f
Update documentation of the 'since' deprecated key
tgross35 8ad6c66
Add another note about the index
tgross35 21b4be2
Rename RFC file
tgross35 a390e5c
Update index comment
tgross35 a0f6b0a
More info about the index
tgross35 b1e9656
Features/2/3 information added
tgross35 244e9a7
Clarify doc comment example
tgross35 fcdb26b
Empty content from this RFC that was moved to one of the others
tgross35 f38d7dc
Capture cargo team meeting notes and clean up
epage 69026e1
Call out impact to third party parsers
epage a8c6163
Add tracking issue
epage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
- Feature Name: feature-metadata | ||
- Start Date: 2023-04-14 | ||
- RFC PR: [rust-lang/rfcs#3416](https://github.com/rust-lang/rfcs/pull/3416) | ||
- Rust Issue: | ||
[rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) | ||
|
||
# Summary | ||
|
||
[summary]: #summary | ||
|
||
This RFC is just meta tracking information for the three following RFCs: | ||
|
||
- [Cargo feature descriptions](https://github.com/rust-lang/rfcs/pull/3485) | ||
- [Cargo feature deprecation](https://github.com/rust-lang/rfcs/pull/3486) | ||
- [Cargo feature visibility](https://github.com/rust-lang/rfcs/pull/3487) | ||
|
||
# Motivation | ||
|
||
[motivation]: #motivation | ||
|
||
Features are widely used as a way to do things like reduce dependency count, | ||
gate `std` or `alloc`-dependent parts of code, or hide unstable API. Use is so | ||
common that many larger crates wind up with tens of feature gates, such as | ||
[`tokio`] with 24. Despite being a first class component of crate structure, | ||
there are some limitations that don't have elegant solutions: | ||
|
||
- Documentation is difficult, often requiring library authors to manually manage | ||
a table of descriptions | ||
- There is no way to deprecate old features, as a way to help crates maintain | ||
semvar compliance | ||
- Features cannot be hidden from use in any way | ||
|
||
This RFC proposes a plan that add that information to `Cargo.toml`, solving | ||
these problems. | ||
|
||
# Guide-level explanation | ||
|
||
[guide-level-explanation]: #guide-level-explanation | ||
|
||
Usage is simple: features will be able to be specified as a table, instead of | ||
just a dependency array. This sample section of `Cargo.toml` shows new | ||
possibilities: | ||
|
||
```toml | ||
[features] | ||
# Current configuration will continue to work | ||
foo = [] | ||
# New configurations | ||
bar = { enables = ["foo"], doc = "simple docstring here"} | ||
baz = { enables = ["foo"], public = false} | ||
qux = { enables = [], deprecated = true } | ||
quux = { enables = [], deprecated = { since = "1.2.3", note = "don't use this!" } } | ||
|
||
# Features can also be full tables if descriptions are longer | ||
[features.corge] | ||
enables = ["bar", "baz"] | ||
doc = """ | ||
# corge | ||
|
||
This could be a longer description of this feature | ||
""" | ||
``` | ||
|
||
The `enables` key is synonymous with the existing array, describing what other | ||
epage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
features are enabled by a given feature. For example, | ||
`foo = ["dep:serde", "otherfeat"]` will be identical to | ||
`foo = { enables = ["dep:serde", "otherfeat"] }` | ||
|
||
All other keys are described in their individual RFCs. | ||
|
||
# Reference-level explanation | ||
|
||
[reference-level-explanation]: #reference-level-explanation | ||
|
||
`enables` will take the place of the feature dependency array that currently | ||
exists. Semantics will remain unchanged. | ||
|
||
This is a required key. If there are no requirements, an empty list should be | ||
provided (`enables = []`). This content is already in the index. | ||
|
||
# General Implementation & Usage | ||
|
||
Use cases for this information will likely develop with time, but one of the | ||
simplest applications is for information output with `cargo add`: | ||
|
||
```text | ||
crab@rust foobar % cargo add regex | ||
Updating crates.io index | ||
Adding regex v1.7.3 to dependencies. | ||
Features: | ||
+ perf Enables all performance related features | ||
+ perf-dfa Enables the use of a lazy DFA for matching | ||
+ perf-inline Enables the use of aggressive inlining inside | ||
match routines | ||
+ perf-literal Enables the use of literal optimizations for | ||
speeding up matches | ||
+ std When enabled, this will cause regex to use the | ||
standard library | ||
+ unicode Enables all Unicode features | ||
- deprecated (D) Not a real feature, but it could be | ||
|
||
Updating crates.io index | ||
``` | ||
|
||
Features like `aho-corasick`, `memchr`, or `use_std` would likely be | ||
`public = false` since they aren't listed on the crate landing page. | ||
|
||
## Implementation note: sort order | ||
|
||
In general, any tool that renders features (`rustdoc`, `cargo add`) should | ||
attempt to present them in the following way: | ||
|
||
- Display default features first | ||
- Display non-default but stable features next (can be in a separate section) | ||
- Display deprecated features last (can be in a separate section) | ||
- Do not display private features unless receiving a flag saying to do so (e.g. | ||
`--document-private-items` with `rustdoc`) | ||
- If ordering is not preserved, present the features alphabetically | ||
|
||
# Drawbacks | ||
|
||
[drawbacks]: #drawbacks | ||
epage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- Added complexity to Cargo. Parsing is trivial, but exact implementation | ||
details do add test surface area | ||
|
||
# Rationale and alternatives | ||
|
||
[rationale-and-alternatives]: #rationale-and-alternatives | ||
|
||
# Prior art | ||
|
||
[prior-art]: #prior-art | ||
|
||
# Unresolved questions | ||
|
||
[unresolved-questions]: #unresolved-questions | ||
|
||
# Future possibilities | ||
|
||
[future-possibilities]: #future-possibilities | ||
|
||
- A `rust-version` field that could indicate e.g. `rust-version = "nightly"` or | ||
`rust-version = "1.65"` to specify a MSRV for that feature. See: | ||
<https://github.com/rust-lang/rfcs/pull/3416#discussion_r1174478461> | ||
- `cargo add` can show the `doc` and `deprecated` summary with the listed | ||
features. | ||
- [`cargo-info`] can use this information to provide feature descriptions. | ||
|
||
[cargo #12335]: https://github.com/rust-lang/cargo/issues/12235 | ||
[cargo #10882]: https://github.com/rust-lang/cargo/issues/10882 | ||
[`cargo-info`]: https://github.com/rust-lang/cargo/issues/948 | ||
[`deprecated`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute | ||
[`deprecated-suggestions`]: https://github.com/rust-lang/rust/issues/94785 | ||
[discussion on since]: https://github.com/rust-lang/rfcs/pull/3416#discussion_r1172895497 | ||
[`public_private_dependencies`]: https://rust-lang.github.io/rfcs/1977-public-private-dependencies.html | ||
[`rustdoc-cargo-configuration`]: https://github.com/rust-lang/rfcs/pull/3421 | ||
[`tokio`]: https://docs.rs/crate/tokio/latest/features | ||
[visibility attribute]: https://ant.apache.org/ivy/history/latest-milestone/ivyfile/conf.html |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.