From 22bba4c6454590824128add29e99bb0eea68cf96 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 28 Sep 2024 17:29:15 -0400 Subject: [PATCH 1/2] Mention `--print cfg` under set configuration options This often serves as the landing page for information about which `target_*` configuration options are available. Mention that `rustc` can print the exact options available for each target. --- src/conditional-compilation.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/conditional-compilation.md b/src/conditional-compilation.md index f73f8354a..9775af559 100644 --- a/src/conditional-compilation.md +++ b/src/conditional-compilation.md @@ -58,6 +58,18 @@ configuration option from within the source code of the crate being compiled. > [!WARNING] > Arbitrarily-set configuration options can clash with compiler-set configuration options. For example, it is possible to do `rustc --cfg "unix" program.rs` while compiling to a Windows target, and have both `unix` and `windows` configuration options set at the same time. Doing this would be unwise. +Some default configuration values can be obtained from `rustc`: + +```text +rustc --print cfg # optionally, a --target can be specified +target_abi="" +target_arch="aarch64" +target_endian="little" +target_env="" +target_family="unix" +... +``` + ### `target_arch` Key-value option set once with the target's CPU architecture. The value is From e7f58b47d866e7f2fe11f8c1f7b1d4da158b7b7b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 22 Oct 2024 14:32:29 -0700 Subject: [PATCH 2/2] Merge `--print cfg` with existing note block --- src/conditional-compilation.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/conditional-compilation.md b/src/conditional-compilation.md index 9775af559..05bd0111b 100644 --- a/src/conditional-compilation.md +++ b/src/conditional-compilation.md @@ -49,7 +49,7 @@ passed to the compiler outside of the code. It is not possible to set a configuration option from within the source code of the crate being compiled. > **Note**: For `rustc`, arbitrary-set configuration options are set using the -> [`--cfg`] flag. +> [`--cfg`] flag. Configuration values for a specified target can be displayed with `rustc --print cfg --target $TARGET`. > **Note**: Configuration options with the key `feature` are a convention used > by [Cargo][cargo-feature] for specifying compile-time options and optional @@ -58,18 +58,6 @@ configuration option from within the source code of the crate being compiled. > [!WARNING] > Arbitrarily-set configuration options can clash with compiler-set configuration options. For example, it is possible to do `rustc --cfg "unix" program.rs` while compiling to a Windows target, and have both `unix` and `windows` configuration options set at the same time. Doing this would be unwise. -Some default configuration values can be obtained from `rustc`: - -```text -rustc --print cfg # optionally, a --target can be specified -target_abi="" -target_arch="aarch64" -target_endian="little" -target_env="" -target_family="unix" -... -``` - ### `target_arch` Key-value option set once with the target's CPU architecture. The value is