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

Clarify conditional compilation #1338

Merged
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
8 changes: 5 additions & 3 deletions src/attribute/cfg.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# `cfg`

Conditional compilation is possible through two different operators:
Configuration conditional checks are possible through two different operators:

* the `cfg` attribute: `#[cfg(...)]` in attribute position
* the `cfg!` macro: `cfg!(...)` in boolean expressions

Both utilize identical argument syntax.
While the former enables conditional compilation, the latter conditionally
evaluates to `true` or `false` literals allowing for checks at run-time. Both
utilize identical argument syntax.

```rust,editable
// This function only gets compiled if the target OS is linux
Expand All @@ -22,7 +24,7 @@ fn are_you_on_linux() {

fn main() {
are_you_on_linux();

println!("Are you sure?");
if cfg!(target_os = "linux") {
println!("Yes. It's definitely linux!");
Expand Down