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

Add more documentation to cargo::rustc-check-cfg #13869

Merged
merged 3 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
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
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 {
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR. Instead of putting an example here, do you think it's better to just have a link to the conditional compilation build script example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having a example right in the documentation is very valuable, however linking to a more complete example is quite valuable to, so I added a link to it.

```

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