Skip to content
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

RFC: Unblock Cargo feature metadata #3416

Merged
merged 45 commits into from
Jun 27, 2024
Merged
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d58366d
Added feature-descriptions-doc-cfg RFC
tgross35 Apr 15, 2023
c9a9874
Update docs.rs link
tgross35 Apr 15, 2023
37058e1
Add note about argfile
tgross35 Apr 15, 2023
d461faf
Add note about serde
tgross35 Apr 15, 2023
65615b2
Add note on build system tools
tgross35 Apr 15, 2023
35ca770
Rename json-config -> config-json
tgross35 Apr 15, 2023
be9b7c2
Complete all RFC sections
tgross35 Apr 15, 2023
a0966ab
Rename feature, update related links
tgross35 Apr 15, 2023
c5ab809
Add note about overrides
tgross35 Apr 15, 2023
11f696e
Correct toml mistake
tgross35 Apr 15, 2023
381afba
Fix links
tgross35 Apr 15, 2023
64ce8ca
Clean up clean up everybody everywhere
tgross35 Apr 15, 2023
47ad04e
Add note about dependencies
tgross35 Apr 16, 2023
6c6ad6d
Split feature-metadata-doc-config into feature-metadata and rustdoc-c…
tgross35 Apr 20, 2023
4dd05e3
Initial updates based on review
tgross35 Apr 20, 2023
cea7180
Update two from the review round
tgross35 Apr 20, 2023
4ab3a6f
Updates round three from review
tgross35 Apr 20, 2023
5f48f2d
Updates round four
tgross35 Apr 20, 2023
19c3521
Updates round five
tgross35 Apr 20, 2023
32174e8
Updates round six
tgross35 Apr 20, 2023
cbc31d5
Updates regarding parser
tgross35 Jun 10, 2023
97e8301
Clarify markdown status for documentation
tgross35 Jun 10, 2023
fff9af1
Add note about optional dev dependencies
tgross35 Jun 10, 2023
f1fb220
Remove unstable flag
tgross35 Jun 10, 2023
98dbaa1
Add suggestion about rust-version flag
tgross35 Jun 10, 2023
8cab2f0
Move deny deprecated features to future possibilities
tgross35 Jun 30, 2023
fe7767b
Adjust mentions of 'unstable' to 'stable', refactpr sections
tgross35 Jun 30, 2023
b952ce1
Update some links
tgross35 Jun 30, 2023
9b2a044
Add notes about public=true default and index changes
tgross35 Jun 30, 2023
15a2432
Add note about doc in index
tgross35 Jun 30, 2023
88a3447
Add note about naming choice
tgross35 Jul 2, 2023
e36b155
Add markdown vs. plaintext as an unresolved question
tgross35 Jul 2, 2023
397d47e
Rename 'requires' to 'enables'
tgross35 Jul 2, 2023
f3b862b
Update documentation about private feature usage
tgross35 Jul 2, 2023
0c1a00f
Update documentation of the 'since' deprecated key
tgross35 Jul 3, 2023
8ad6c66
Add another note about the index
tgross35 Jul 3, 2023
21b4be2
Rename RFC file
tgross35 Jul 3, 2023
a390e5c
Update index comment
tgross35 Jul 3, 2023
a0f6b0a
More info about the index
tgross35 Jul 3, 2023
b1e9656
Features/2/3 information added
tgross35 Jul 3, 2023
244e9a7
Clarify doc comment example
tgross35 Jul 3, 2023
fcdb26b
Empty content from this RFC that was moved to one of the others
tgross35 Sep 9, 2023
f38d7dc
Capture cargo team meeting notes and clean up
epage Jun 11, 2024
69026e1
Call out impact to third party parsers
epage Jun 11, 2024
a8c6163
Add tracking issue
epage Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions text/3416-feature-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
- 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)
epage marked this conversation as resolved.
Show resolved Hide resolved

# Summary

[summary]: #summary

This RFC adds a "detailed" feature definition:
```toml
[features]
# same as `foo = []`
foo = { enables = [] }
```

This is to unblock the 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.

## General Implementation & Usage

Use cases for these new keys 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.

# 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.

The availability of this new syntax should not require an MSRV bump.
This means we need to make sure that if you use `feature_name = []` in your `Cargo.toml`,
then the published `Cargo.toml` should as well.
However, we leave it as an implementation detail whether using `feature_name = { enables =[] }`
requires an MSRV bump for users of your published package as we have not been
actively streamlining the workflow for maintaining separate development and
published MSRVs.

# 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
- Extending the `Cargo.toml` schema, particularly having a field support
additional types, is disruptive to third-party parsers

# Rationale and alternatives

[rationale-and-alternatives]: #rationale-and-alternatives

This RFC has no impact on the Index Summaries.
Future RFCs will need to work with that.

## Naming

- `enables` reads better on the line than `enable`
- `enables` is likely an easier word for non-native speakers than `activates`
- `required` is used elsewhere to say "this should automatically be available if requirements are met"

## Schema

We could split the special feature syntax (`dep:`, etc) as distinct fields
but we'd prefer trivial conversion from the "simple" schema to the "detailed" schema,
like `dependencies`.
However, we likely would want to prefer using new fields over adding more syntax,
like with [disabling default features](https://github.com/rust-lang/cargo/issues/3126).

# Prior art

[prior-art]: #prior-art

# Unresolved questions

[unresolved-questions]: #unresolved-questions

# Future possibilities

[future-possibilities]: #future-possibilities

- [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)
- [Cargo feature stability](https://github.com/rust-lang/cargo/issues/10881)

[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