Skip to content

Commit 206dd31

Browse files
committed
Adjust documentation for newly stabilized -Zcheck-cfg
1 parent fbaea97 commit 206dd31

File tree

2 files changed

+24
-40
lines changed

2 files changed

+24
-40
lines changed

Diff for: src/doc/src/reference/build-scripts.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ one detailed below.
130130
compiler.
131131
* [`cargo::rustc-cfg=KEY[="VALUE"]`](#rustc-cfg) --- Enables compile-time `cfg`
132132
settings.
133+
* [`cargo::rustc-check-cfg=CHECK_CFG`](#rustc-check-cfg) -- Enables compile-time
134+
checking of configs.
133135
* [`cargo::rustc-env=VAR=VALUE`](#rustc-env) --- Sets an environment variable.
134136
* [`cargo::rustc-cdylib-link-arg=FLAG`](#rustc-cdylib-link-arg) --- Passes custom
135137
flags to a linker for cdylib crates.
@@ -233,7 +235,9 @@ equivalent to using [`rustc-link-lib`](#rustc-link-lib) and
233235

234236
The `rustc-cfg` instruction tells Cargo to pass the given value to the
235237
[`--cfg` flag][option-cfg] to the compiler. This may be used for compile-time
236-
detection of features to enable [conditional compilation].
238+
detection of features to enable [conditional compilation]. Each custom cfgs
239+
must **always** be declared using the [`cargo::rustc-check-cfg`](#rustc-check-cfg)
240+
instruction.
237241

238242
Note that this does *not* affect Cargo's dependency resolution. This cannot be
239243
used to enable an optional dependency, or enable other Cargo features.
@@ -250,6 +254,25 @@ identifier, the value should be a string.
250254
[conditional compilation]: ../../reference/conditional-compilation.md
251255
[option-cfg]: ../../rustc/command-line-arguments.md#option-cfg
252256

257+
### `cargo::rustc-check-cfg=CHECK_CFG` {#rustc-check-cfg}
258+
259+
The `rustc-check-cfg` instruction tells Cargo to pass the given expected
260+
configs to the [`--check-cfg` flag][option-check-cfg] to the compiler. This is
261+
used for compile-time detection of unexpected conditional compilation configs.
262+
263+
You can use the instruction like this:
264+
265+
```rust,no_run
266+
// build.rs
267+
println!("cargo::rustc-check-cfg=cfg(foo)");
268+
```
269+
270+
Note that it is expected to **always** pass the full list of custom configs
271+
used in the package. The recommended way to achieve this is put all the
272+
check-cfg instructions at the top of your `build.rs`.
273+
274+
[option-cfg]: ../../rustc/command-line-arguments.md#option-check-cfg
275+
253276
### `cargo::rustc-env=VAR=VALUE` {#rustc-env}
254277

255278
The `rustc-env` instruction tells Cargo to set the given environment variable

Diff for: src/doc/src/reference/unstable.md

-39
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ For the latest nightly, see the [nightly version] of this page.
8383
* [build-std-features](#build-std-features) --- Sets features to use with the standard library.
8484
* [binary-dep-depinfo](#binary-dep-depinfo) --- Causes the dep-info file to track binary dependencies.
8585
* [panic-abort-tests](#panic-abort-tests) --- Allows running tests with the "abort" panic strategy.
86-
* [check-cfg](#check-cfg) --- Compile-time validation of `cfg` expressions.
8786
* [host-config](#host-config) --- Allows setting `[target]`-like configuration settings for host build targets.
8887
* [target-applies-to-host](#target-applies-to-host) --- Alters whether certain flags will be passed to host build targets.
8988
* [gc](#gc) --- Global cache garbage collection.
@@ -1126,44 +1125,6 @@ You can use the flag like this:
11261125
cargo rustdoc -Z unstable-options --output-format json
11271126
```
11281127

1129-
## check-cfg
1130-
1131-
* RFC: [#3013](https://github.com/rust-lang/rfcs/pull/3013)
1132-
* Tracking Issue: [#10554](https://github.com/rust-lang/cargo/issues/10554)
1133-
1134-
`-Z check-cfg` command line enables compile time checking of Cargo features as well as `rustc`
1135-
well known names and values in `#[cfg]`, `cfg!`, `#[link]` and `#[cfg_attr]` with the `rustc`
1136-
and `rustdoc` unstable `--check-cfg` command line.
1137-
1138-
You can use the flag like this:
1139-
1140-
```
1141-
cargo check -Z unstable-options -Z check-cfg
1142-
```
1143-
1144-
### `cargo::rustc-check-cfg=CHECK_CFG`
1145-
1146-
The `rustc-check-cfg` instruction tells Cargo to pass the given value to the
1147-
`--check-cfg` flag to the compiler. This may be used for compile-time
1148-
detection of unexpected conditional compilation name and/or values.
1149-
1150-
This can only be used in combination with `-Zcheck-cfg` otherwise it is ignored
1151-
with a warning.
1152-
1153-
If you want to integrate with Cargo features, only use `-Zcheck-cfg` instead of
1154-
trying to do it manually with this option.
1155-
1156-
You can use the instruction like this:
1157-
1158-
```rust,no_run
1159-
// build.rs
1160-
println!("cargo::rustc-check-cfg=cfg(foo, bar)");
1161-
```
1162-
1163-
```
1164-
cargo check -Z unstable-options -Z check-cfg
1165-
```
1166-
11671128
## codegen-backend
11681129

11691130
The `codegen-backend` feature makes it possible to select the codegen backend used by rustc using a profile.

0 commit comments

Comments
 (0)