|
9 | 9 | //! Cargo, and the good news is that it shouldn't be too hard! First determine
|
10 | 10 | //! how the feature should be gated:
|
11 | 11 | //!
|
12 |
| -//! * New syntax in Cargo.toml should use `cargo-features`. |
13 |
| -//! * New CLI options should use `-Z unstable-options`. |
14 |
| -//! * New functionality that may not have an interface, or the interface has |
15 |
| -//! not yet been designed, or for more complex features that affect multiple |
16 |
| -//! parts of Cargo should use a new `-Z` flag. |
| 12 | +//! * Error when the feature is used without the gate |
| 13 | +//! * Required if ignoring the feature violates the users intent in non-superficial ways |
| 14 | +//! * A low-effort / safe way to protect the user from being broken if the format of the feature changes in |
| 15 | +//! incompatible was (can be worked around) |
| 16 | +//! * Good for: CLI (gate: `-Zunstable-options` or `-Z` if combined with other changes), `Cargo.toml` (gate: `cargo-features`) |
| 17 | +//! * Warn that the feature is ignored due to lack of the gate |
| 18 | +//! * For if you could opt-in to the unimplemented feature on Cargo today and Cargo would |
| 19 | +//! operate just fine |
| 20 | +//! * If gate is not enabled, prefer to warn if the format of the feature is incompatible |
| 21 | +//! (instead of error or ignore) |
| 22 | +//! * Good for: `Cargo.toml`, `.cargo/config.toml`, `config.json` index file (gate: `-Z`) |
| 23 | +//! * Ignore the feature that is used without a gate |
| 24 | +//! * For when ignoring the feature has so little impact that annoying the user is not worth it |
| 25 | +//! (e.g. a config field that changes Cargo's terminal output) |
| 26 | +//! * For behavior changes without an interface (e.g. the resolver) |
| 27 | +//! * Good for: `.cargo/config.toml`, `config.json` index file (gate: `-Z`) |
| 28 | +//! |
| 29 | +//! For features that touch multiple parts of Cargo, multiple feature gating strategies (error, |
| 30 | +//! warn, ignore) and mechnisms (`-Z`, `cargo-features`) may be used. |
17 | 31 | //!
|
18 | 32 | //! When adding new tests for your feature, usually the tests should go into a
|
19 |
| -//! new module of the testsuite. See |
| 33 | +//! new module of the testsuite named after the feature. See |
20 | 34 | //! <https://doc.crates.io/contrib/tests/writing.html> for more information on
|
21 | 35 | //! writing tests. Particularly, check out the "Testing Nightly Features"
|
22 |
| -//! section for testing unstable features. |
| 36 | +//! section for testing unstable features. Be sure to test the feature gate itself. |
23 | 37 | //!
|
24 | 38 | //! After you have added your feature, be sure to update the unstable
|
25 | 39 | //! documentation at `src/doc/src/reference/unstable.md` to include a short
|
26 | 40 | //! description of how to use your new feature.
|
27 | 41 | //!
|
28 | 42 | //! And hopefully that's it!
|
29 | 43 | //!
|
30 |
| -//! ## New Cargo.toml syntax |
| 44 | +//! ## `cargo-features` |
31 | 45 | //!
|
32 | 46 | //! The steps for adding new Cargo.toml syntax are:
|
33 | 47 | //!
|
34 |
| -//! 1. Add the cargo-features unstable gate. Search below for "look here" to |
| 48 | +//! 1. Add the cargo-features unstable gate. Search the code below for "look here" to |
35 | 49 | //! find the [`features!`] macro invocation and add your feature to the list.
|
36 | 50 | //!
|
37 | 51 | //! 2. Update the Cargo.toml parsing code to handle your new feature.
|
|
68 | 82 | //! [`Config::cli_unstable`] to get an instance of [`CliUnstable`]
|
69 | 83 | //! and check if the option has been enabled on the [`CliUnstable`] instance.
|
70 | 84 | //! Nightly gating is already handled, so no need to worry about that.
|
71 |
| -//! |
72 |
| -//! ### `-Z` vs `cargo-features` |
73 |
| -//! |
74 |
| -//! In some cases there might be some changes that `cargo-features` is unable |
75 |
| -//! to sufficiently encompass. An example would be a syntax change in |
76 |
| -//! `Cargo.toml` that also impacts the index or resolver. The resolver doesn't |
77 |
| -//! know about `cargo-features`, so it needs a `-Z` flag to enable the |
78 |
| -//! experimental functionality. |
79 |
| -//! |
80 |
| -//! In those cases, you usually should introduce both a `-Z` flag (to enable |
81 |
| -//! the changes outside of the manifest) and a `cargo-features` entry (to |
82 |
| -//! enable the new syntax in `Cargo.toml`). The `cargo-features` entry ensures |
83 |
| -//! that any experimental syntax that gets uploaded to crates.io is clearly |
84 |
| -//! intended for nightly-only builds. Otherwise, users accessing those crates |
85 |
| -//! may get confusing errors, particularly if the syntax changes during the |
86 |
| -//! development cycle, and the user tries to access it with a stable release. |
87 |
| -//! |
88 |
| -//! ### `-Z` with external files |
89 |
| -//! |
90 |
| -//! Some files, such as `config.toml` config files, or the `config.json` index |
91 |
| -//! file, are used in a global location which can make interaction with stable |
92 |
| -//! releases problematic. In general, before the feature is stabilized, stable |
93 |
| -//! Cargo should behave roughly similar to how it behaved *before* the |
94 |
| -//! unstable feature was introduced. If Cargo would normally have ignored or |
95 |
| -//! warned about the introduction of something, then it probably should |
96 |
| -//! continue to do so. |
97 |
| -//! |
98 |
| -//! For example, Cargo generally ignores (or warns) about `config.toml` |
99 |
| -//! entries it doesn't know about. This allows a limited degree of |
100 |
| -//! forwards-compatibility with future versions of Cargo that add new entries. |
101 |
| -//! |
102 |
| -//! Whether or not to warn on stable may need to be decided on a case-by-case |
103 |
| -//! basis. For example, you may want to avoid generating a warning for options |
104 |
| -//! that are not critical to Cargo's operation in order to reduce the |
105 |
| -//! annoyance of constant warnings. However, ignoring some options may prevent |
106 |
| -//! proper operation, so a warning may be valuable for a user trying to |
107 |
| -//! diagnose why it isn't working correctly. |
| 85 | +//! If warning when feature is used without the gate, be sure to gracefully degrade (with a |
| 86 | +//! warning) when the `Cargo.toml` / `.cargo/config.toml` field usage doesn't match the |
| 87 | +//! schema. |
| 88 | +//! 4. For any `Cargo.toml` fields, strip them in [`prepare_for_publish`] if the gate isn't set |
108 | 89 | //!
|
109 | 90 | //! ## Stabilization
|
110 | 91 | //!
|
|
135 | 116 | //! [`fail_if_stable_opt`]: CliUnstable::fail_if_stable_opt
|
136 | 117 | //! [`features!`]: macro.features.html
|
137 | 118 | //! [`unstable_cli_options!`]: macro.unstable_cli_options.html
|
| 119 | +//! [`prepare_for_publish`]: crate::util::toml::prepare_for_publish |
138 | 120 |
|
139 | 121 | use std::collections::BTreeSet;
|
140 | 122 | use std::env;
|
|
0 commit comments