|
1 |
| -From 337e3a5cbc1e92538f02f50baa971f46d235d20e Mon Sep 17 00:00:00 2001 |
| 1 | +From f13f9eb30c76108ef60782399daffaedc81ee012 Mon Sep 17 00:00:00 2001 |
2 | 2 | From: Trevor Gross < [email protected]>
|
3 |
| -Date: Tue, 5 Aug 2025 18:48:23 +0000 |
4 |
| -Subject: [PATCH] Debug builtins output |
| 3 | +Date: Tue, 5 Aug 2025 20:56:27 +0000 |
| 4 | +Subject: [PATCH] configure: Use `CARGO_CFG_*_{F16,F128}` rather than invoking |
| 5 | + rustc |
5 | 6 |
|
| 7 | +Currently we run `rustc` from the `RUSTC` environment variable to figure |
| 8 | +out whether or not to enable `f16` and `f128`, based on the |
| 9 | +`target_has_reliable_{f16,f128}` config. However, this does not know |
| 10 | +about the codegen backend used, and the backend isn't trivial to check |
| 11 | +in a build script (usually the backend gets set via `RUSTFLAGS`). |
| 12 | + |
| 13 | +It turns out we don't actually need to run `rustc` here: Cargo |
| 14 | +unconditionally emits all config from the relevant compiler as |
| 15 | +`CARGO_CFG_*` variables, regardless of whether or not they are known |
| 16 | +options. Switch to checking these to set config rather than invoking |
| 17 | +`rustc`. |
| 18 | + |
| 19 | +As an added advantage, we don't need any special handling for |
| 20 | +target.json files. |
| 21 | + |
| 22 | +Fixes: ed17b95715dd ("Use the compiler to determine whether or not to enable `f16` and `f128`") |
6 | 23 | ---
|
7 |
| - .../compiler-builtins/configure.rs | 13 +++++++++++-- |
8 |
| - 1 file changed, 11 insertions(+), 2 deletions(-) |
| 24 | + compiler-builtins/configure.rs | 27 ++++----------------------- |
| 25 | + libm/configure.rs | 30 ++++++------------------------ |
| 26 | + 2 files changed, 10 insertions(+), 47 deletions(-) |
9 | 27 |
|
10 | 28 | diff --git a/library/compiler-builtins/compiler-builtins/configure.rs b/library/compiler-builtins/compiler-builtins/configure.rs
|
11 |
| -index 9721ddf090c..19a7886f496 100644 |
12 |
| ---- a/library/compiler-builtins/compiler-builtins/configure.rs |
13 |
| -+++ b/library/compiler-builtins/compiler-builtins/configure.rs |
14 |
| -@@ -47,6 +47,12 @@ pub fn from_env() -> Self { |
15 |
| - .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); |
16 |
| - let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); |
| 29 | +index caedc034d..79e238abc 100644 |
| 30 | +--- a/compiler-builtins/configure.rs |
| 31 | ++++ b/compiler-builtins/configure.rs |
| 32 | +@@ -1,6 +1,5 @@ |
| 33 | + // Configuration that is shared between `compiler_builtins` and `builtins_test`. |
| 34 | + |
| 35 | +-use std::process::{Command, Stdio}; |
| 36 | + use std::{env, str}; |
17 | 37 |
|
18 |
| -+ println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); println!("cargo::warning=rustflags: {:?}", env::var("RUSTFLAGS")); |
19 |
| -+ for line in rustc_cfg.lines() { |
20 |
| -+ println!("cargo::warning=cfg: {line}"); |
21 |
| -+ } |
22 |
| -+ // println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); |
23 |
| -+ |
24 |
| - // If we couldn't query `rustc` (e.g. a custom JSON target was used), make the safe |
25 |
| - // choice and leave `f16` and `f128` disabled. |
26 |
| - let rustc_output_ok = out.status.success(); |
27 |
| -@@ -55,7 +61,7 @@ pub fn from_env() -> Self { |
28 |
| - let reliable_f16 = |
29 |
| - rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f16"); |
| 38 | + #[derive(Debug)] |
| 39 | +@@ -35,26 +34,6 @@ impl Target { |
| 40 | + .map(|s| s.to_lowercase().replace("_", "-")) |
| 41 | + .collect(); |
30 | 42 |
|
31 |
| -- Self { |
32 |
| -+ let ret = Self { |
| 43 | +- // Query rustc for options that Cargo does not provide env for. The bootstrap hack is used |
| 44 | +- // to get consistent output regardless of channel (`f16`/`f128` config options are hidden |
| 45 | +- // on stable otherwise). |
| 46 | +- let mut cmd = Command::new(env::var("RUSTC").unwrap()); |
| 47 | +- cmd.args(["--print=cfg", "--target", &triple]) |
| 48 | +- .env("RUSTC_BOOTSTRAP", "1") |
| 49 | +- .stderr(Stdio::inherit()); |
| 50 | +- let out = cmd |
| 51 | +- .output() |
| 52 | +- .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); |
| 53 | +- let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); |
| 54 | +- |
| 55 | +- // If we couldn't query `rustc` (e.g. a custom JSON target was used), make the safe |
| 56 | +- // choice and leave `f16` and `f128` disabled. |
| 57 | +- let rustc_output_ok = out.status.success(); |
| 58 | +- let reliable_f128 = |
| 59 | +- rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f128"); |
| 60 | +- let reliable_f16 = |
| 61 | +- rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f16"); |
| 62 | +- |
| 63 | + Self { |
33 | 64 | triple,
|
34 | 65 | triple_split,
|
35 |
| - os: env::var("CARGO_CFG_TARGET_OS").unwrap(), |
36 |
| -@@ -76,7 +82,10 @@ pub fn from_env() -> Self { |
| 66 | +@@ -74,8 +53,10 @@ impl Target { |
| 67 | + .split(",") |
| 68 | + .map(ToOwned::to_owned) |
37 | 69 | .collect(),
|
38 |
| - reliable_f128, |
39 |
| - reliable_f16, |
40 |
| -- } |
41 |
| -+ }; |
42 |
| -+ |
43 |
| -+ println!("cargo::warning=target: {ret:?}"); |
44 |
| -+ ret |
| 70 | +- reliable_f128, |
| 71 | +- reliable_f16, |
| 72 | ++ // Note that these are unstable options, so only show up with the nightly compiler or |
| 73 | ++ // with `RUSTC_BOOTSTRAP=1` (which is required to use the types anyway). |
| 74 | ++ reliable_f128: env::var_os("CARGO_CFG_TARGET_HAS_RELIABLE_F128").is_some(), |
| 75 | ++ reliable_f16: env::var_os("CARGO_CFG_TARGET_HAS_RELIABLE_F16").is_some(), |
| 76 | + } |
45 | 77 | }
|
46 | 78 |
|
47 |
| - #[allow(dead_code)] |
| 79 | +diff --git a/library/compiler-builtins/libm/configure.rs b/library/compiler-builtins/libm/configure.rs |
| 80 | +index f9100d2d5..76186e636 100644 |
| 81 | +--- a/libm/configure.rs |
| 82 | ++++ b/libm/configure.rs |
| 83 | +@@ -1,9 +1,9 @@ |
| 84 | + // Configuration shared with both libm and libm-test |
| 85 | + |
| 86 | ++use std::env; |
| 87 | + use std::path::PathBuf; |
| 88 | +-use std::process::{Command, Stdio}; |
| 89 | +-use std::{env, str}; |
| 90 | + |
| 91 | ++#[derive(Debug)] |
| 92 | + #[allow(dead_code)] |
| 93 | + pub struct Config { |
| 94 | + pub manifest_dir: PathBuf, |
| 95 | +@@ -33,26 +33,6 @@ impl Config { |
| 96 | + .map(|s| s.to_lowercase().replace("_", "-")) |
| 97 | + .collect(); |
| 98 | + |
| 99 | +- // Query rustc for options that Cargo does not provide env for. The bootstrap hack is used |
| 100 | +- // to get consistent output regardless of channel (`f16`/`f128` config options are hidden |
| 101 | +- // on stable otherwise). |
| 102 | +- let mut cmd = Command::new(env::var("RUSTC").unwrap()); |
| 103 | +- cmd.args(["--print=cfg", "--target", &target_triple]) |
| 104 | +- .env("RUSTC_BOOTSTRAP", "1") |
| 105 | +- .stderr(Stdio::inherit()); |
| 106 | +- let out = cmd |
| 107 | +- .output() |
| 108 | +- .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); |
| 109 | +- let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); |
| 110 | +- |
| 111 | +- // If we couldn't query `rustc` (e.g. a custom JSON target was used), make the safe |
| 112 | +- // choice and leave `f16` and `f128` disabled. |
| 113 | +- let rustc_output_ok = out.status.success(); |
| 114 | +- let reliable_f128 = |
| 115 | +- rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f128"); |
| 116 | +- let reliable_f16 = |
| 117 | +- rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f16"); |
| 118 | +- |
| 119 | + Self { |
| 120 | + target_triple, |
| 121 | + manifest_dir: PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()), |
| 122 | +@@ -66,8 +46,10 @@ impl Config { |
| 123 | + target_string: env::var("TARGET").unwrap(), |
| 124 | + target_vendor: env::var("CARGO_CFG_TARGET_VENDOR").unwrap(), |
| 125 | + target_features, |
| 126 | +- reliable_f128, |
| 127 | +- reliable_f16, |
| 128 | ++ // Note that these are unstable options, so only show up with the nightly compiler or |
| 129 | ++ // with `RUSTC_BOOTSTRAP=1` (which is required to use the types anyway). |
| 130 | ++ reliable_f128: env::var_os("CARGO_CFG_TARGET_HAS_RELIABLE_F128").is_some(), |
| 131 | ++ reliable_f16: env::var_os("CARGO_CFG_TARGET_HAS_RELIABLE_F16").is_some(), |
| 132 | + } |
| 133 | + } |
| 134 | + } |
48 | 135 | --
|
49 | 136 | 2.48.1
|
0 commit comments