Skip to content

Commit

Permalink
Auto merge of #13869 - Urgau:check-cfg-docs-2, r=weihanglo
Browse files Browse the repository at this point in the history
Add more documentation to `cargo::rustc-check-cfg`

This PR add more documentation to `cargo::rustc-check-cfg` by:
 1. mentioning `cargo:rustc-check-cfg` for MSRV
 2. it also add a link to [the check-cfg blog post](https://blog.rust-lang.org/2024/05/06/check-cfg.html) (since it gives a big overview of the feature in general)
 3. it also adds a link to the build-script-examples page where a more complete example for the use of `cargo::rustc-cfg` and `cargo::rustc-check-cfg` is displayed

Fixes #13868
r? `@weihanglo`
  • Loading branch information
bors committed May 6, 2024
2 parents cfbc4b7 + 1ddc6b6 commit ec35bff
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/doc/src/reference/build-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,16 @@ identifier, the value should be a string.

### `cargo::rustc-check-cfg=CHECK_CFG` {#rustc-check-cfg}

*See the announcement [blog post][check-cfg-blog-post] for more a global view of the feature.*

Add to the list of expected config names and values that is used when checking
the _reachable_ cfg expressions.

For details on the syntax of `CHECK_CFG`, see `rustc` [`--check-cfg` flag][option-check-cfg].
See also the [`unexpected_cfgs`][unexpected-cfgs] lint.

> Note: `cargo:rustc-check-cfg` (single-colon) can be used if your MSRV is below Rust 1.77
The instruction can be used like this:

```rust,no_run
Expand All @@ -288,7 +292,13 @@ if foo_bar_condition {
}
```

For a more complete example see in the [build script examples][build-script-examples] page
the [conditional compilation][conditional-compilation-example] example.

[check-cfg-blog-post]: https://blog.rust-lang.org/2024/05/06/check-cfg.html
[option-check-cfg]: ../../rustc/command-line-arguments.md#option-check-cfg
[build-script-examples]: build-script-examples.md
[conditional-compilation-example]: build-script-examples.md#conditional-compilation

### `cargo::rustc-env=VAR=VALUE` {#rustc-env}

Expand Down

0 comments on commit ec35bff

Please sign in to comment.