From 6a7ae71380c23fe8d0437b5d2e946b3cfe596cb5 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 25 Jul 2025 17:02:21 -0500 Subject: [PATCH 01/10] ci: Don't set `compiler-builtins-no-f16-f128` Since rust-lang/rust be35d37d8b6c ("Use the compiler to determine whether or not to enable f16 and f128"), `compiler-builtins` relies on `rustc` to report whether or not `f16` and `f128` are supported, which is reported by the backend. This means that there should no longer be any need to set this config in CI. Backend config: https://github.com/rust-lang/rustc_codegen_gcc/blob/f682d09eefc6700b9e5851ef193847959acf4fac/src/lib.rs#L499-L510 --- .github/workflows/m68k.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/m68k.yml b/.github/workflows/m68k.yml index 176ee8628b0..90c3c695679 100644 --- a/.github/workflows/m68k.yml +++ b/.github/workflows/m68k.yml @@ -82,14 +82,14 @@ jobs: - name: Build sample project with target defined as JSON spec run: | ./y.sh prepare --only-libcore --cross - ./y.sh build --sysroot --features compiler-builtins-no-f16-f128 --target-triple m68k-unknown-linux-gnu --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json + ./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ./y.sh cargo build --manifest-path=./tests/hello-world/Cargo.toml --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json ./y.sh clean all - name: Build run: | ./y.sh prepare --only-libcore --cross - ./y.sh build --sysroot --features compiler-builtins-no-f16-f128 --target-triple m68k-unknown-linux-gnu + ./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu ./y.sh test --mini-tests --target-triple m68k-unknown-linux-gnu CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu ./y.sh test --cargo-tests --target-triple m68k-unknown-linux-gnu ./y.sh clean all @@ -102,7 +102,7 @@ jobs: - name: Run tests run: | - ./y.sh test --target-triple m68k-unknown-linux-gnu --release --clean --build-sysroot --sysroot-features compiler-builtins-no-f16-f128 ${{ matrix.commands }} + ./y.sh test --target-triple m68k-unknown-linux-gnu --release --clean --build-sysroot --sysroot-features ${{ matrix.commands }} - name: Run Hello World! run: | From d0a88b8072a92c004771ff49f34b80ee103ca7a6 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 5 Aug 2025 18:24:59 +0000 Subject: [PATCH 02/10] DROPME debugging --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b11f11d38e3..da20c53b5ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -480,6 +480,9 @@ fn target_config(sess: &Session, target_info: &LockedTargetInfo) -> TargetConfig let has_reliable_f16 = target_info.supports_target_dependent_type(CType::Float16); let has_reliable_f128 = target_info.supports_target_dependent_type(CType::Float128); + eprintln!("reliable f16: {has_reliable_f16}"); + eprintln!("reliable f128: {has_reliable_f128}"); + TargetConfig { target_features, unstable_target_features, From ec6ff434acdf4d5c70450270c54ed1bcf48c5e18 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 5 Aug 2025 18:49:32 +0000 Subject: [PATCH 03/10] dump some info from builtins cfg --- patches/0001-Debug-builtins-output.patch | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 patches/0001-Debug-builtins-output.patch diff --git a/patches/0001-Debug-builtins-output.patch b/patches/0001-Debug-builtins-output.patch new file mode 100644 index 00000000000..fe0a9618621 --- /dev/null +++ b/patches/0001-Debug-builtins-output.patch @@ -0,0 +1,50 @@ +From 337e3a5cbc1e92538f02f50baa971f46d235d20e Mon Sep 17 00:00:00 2001 +From: Trevor Gross +Date: Tue, 5 Aug 2025 18:48:23 +0000 +Subject: [PATCH] Debug builtins output + +--- + .../compiler-builtins/configure.rs | 13 +++++++++++-- + 1 file changed, 11 insertions(+), 2 deletions(-) + +diff --git a/library/compiler-builtins/compiler-builtins/configure.rs b/library/compiler-builtins/compiler-builtins/configure.rs +index 9721ddf090c..19a7886f496 100644 +--- a/library/compiler-builtins/compiler-builtins/configure.rs ++++ b/library/compiler-builtins/compiler-builtins/configure.rs +@@ -47,6 +47,12 @@ pub fn from_env() -> Self { + .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); + let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); + ++ println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); ++ for line in rustc_cfg { ++ println!("cargo::warning=cfg: {line}"); ++ } ++ // println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); ++ + // If we couldn't query `rustc` (e.g. a custom JSON target was used), make the safe + // choice and leave `f16` and `f128` disabled. + let rustc_output_ok = out.status.success(); +@@ -55,7 +61,7 @@ pub fn from_env() -> Self { + let reliable_f16 = + rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f16"); + +- Self { ++ let ret = Self { + triple, + triple_split, + os: env::var("CARGO_CFG_TARGET_OS").unwrap(), +@@ -76,7 +82,10 @@ pub fn from_env() -> Self { + .collect(), + reliable_f128, + reliable_f16, +- } ++ }; ++ ++ println!("cargo::warning=target: {ret:?}"); ++ ret + } + + #[allow(dead_code)] +-- +2.48.1 + From d38a79d1f126f32fbc7e494e0a0f3c3d048fe32c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 5 Aug 2025 19:04:11 +0000 Subject: [PATCH 04/10] fix patch --- patches/0001-Debug-builtins-output.patch | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/patches/0001-Debug-builtins-output.patch b/patches/0001-Debug-builtins-output.patch index fe0a9618621..932b2ed9254 100644 --- a/patches/0001-Debug-builtins-output.patch +++ b/patches/0001-Debug-builtins-output.patch @@ -16,7 +16,7 @@ index 9721ddf090c..19a7886f496 100644 let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); + println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); -+ for line in rustc_cfg { ++ for line in rustc_cfg.lines() { + println!("cargo::warning=cfg: {line}"); + } + // println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); @@ -47,4 +47,3 @@ index 9721ddf090c..19a7886f496 100644 #[allow(dead_code)] -- 2.48.1 - From b22919718c37bf1eb4ce8c267950519e333b9c07 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 5 Aug 2025 19:16:22 +0000 Subject: [PATCH 05/10] dump rustflags too --- patches/0001-Debug-builtins-output.patch | 1 + 1 file changed, 1 insertion(+) diff --git a/patches/0001-Debug-builtins-output.patch b/patches/0001-Debug-builtins-output.patch index 932b2ed9254..ef6a5faec5b 100644 --- a/patches/0001-Debug-builtins-output.patch +++ b/patches/0001-Debug-builtins-output.patch @@ -16,6 +16,7 @@ index 9721ddf090c..19a7886f496 100644 let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); + println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); ++ println!("cargo::warning=rustflags: {}", env::var("RUSTFLAGS").unwrap()); + for line in rustc_cfg.lines() { + println!("cargo::warning=cfg: {line}"); + } From 586c1fcdd68a2cc8ebe05cf1a552a1c30736af81 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 5 Aug 2025 19:18:19 +0000 Subject: [PATCH 06/10] fix patch, kinda --- patches/0001-Debug-builtins-output.patch | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/patches/0001-Debug-builtins-output.patch b/patches/0001-Debug-builtins-output.patch index ef6a5faec5b..87ea115dd5d 100644 --- a/patches/0001-Debug-builtins-output.patch +++ b/patches/0001-Debug-builtins-output.patch @@ -15,8 +15,7 @@ index 9721ddf090c..19a7886f496 100644 .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); -+ println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); -+ println!("cargo::warning=rustflags: {}", env::var("RUSTFLAGS").unwrap()); ++ println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); println!("cargo::warning=rustflags: {}", env::var("RUSTFLAGS").unwrap()); + for line in rustc_cfg.lines() { + println!("cargo::warning=cfg: {line}"); + } From f48dfb718e14a9d62fd51513d0be48fddaadcead Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 5 Aug 2025 19:22:33 +0000 Subject: [PATCH 07/10] update patch --- patches/0001-Debug-builtins-output.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/0001-Debug-builtins-output.patch b/patches/0001-Debug-builtins-output.patch index 87ea115dd5d..45b807a17db 100644 --- a/patches/0001-Debug-builtins-output.patch +++ b/patches/0001-Debug-builtins-output.patch @@ -15,7 +15,7 @@ index 9721ddf090c..19a7886f496 100644 .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); -+ println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); println!("cargo::warning=rustflags: {}", env::var("RUSTFLAGS").unwrap()); ++ println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); println!("cargo::warning=rustflags: {:?}", env::var("RUSTFLAGS")); + for line in rustc_cfg.lines() { + println!("cargo::warning=cfg: {line}"); + } From 0e9ed61a75ab0d686fa447444fa8ddfd40d330b6 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 5 Aug 2025 21:13:04 +0000 Subject: [PATCH 08/10] update patch --- patches/0001-Debug-builtins-output.patch | 157 ++++++++++++++++++----- 1 file changed, 122 insertions(+), 35 deletions(-) diff --git a/patches/0001-Debug-builtins-output.patch b/patches/0001-Debug-builtins-output.patch index 45b807a17db..c1dbea3b6d5 100644 --- a/patches/0001-Debug-builtins-output.patch +++ b/patches/0001-Debug-builtins-output.patch @@ -1,49 +1,136 @@ -From 337e3a5cbc1e92538f02f50baa971f46d235d20e Mon Sep 17 00:00:00 2001 +From f13f9eb30c76108ef60782399daffaedc81ee012 Mon Sep 17 00:00:00 2001 From: Trevor Gross -Date: Tue, 5 Aug 2025 18:48:23 +0000 -Subject: [PATCH] Debug builtins output +Date: Tue, 5 Aug 2025 20:56:27 +0000 +Subject: [PATCH] configure: Use `CARGO_CFG_*_{F16,F128}` rather than invoking + rustc +Currently we run `rustc` from the `RUSTC` environment variable to figure +out whether or not to enable `f16` and `f128`, based on the +`target_has_reliable_{f16,f128}` config. However, this does not know +about the codegen backend used, and the backend isn't trivial to check +in a build script (usually the backend gets set via `RUSTFLAGS`). + +It turns out we don't actually need to run `rustc` here: Cargo +unconditionally emits all config from the relevant compiler as +`CARGO_CFG_*` variables, regardless of whether or not they are known +options. Switch to checking these to set config rather than invoking +`rustc`. + +As an added advantage, we don't need any special handling for +target.json files. + +Fixes: ed17b95715dd ("Use the compiler to determine whether or not to enable `f16` and `f128`") --- - .../compiler-builtins/configure.rs | 13 +++++++++++-- - 1 file changed, 11 insertions(+), 2 deletions(-) + compiler-builtins/configure.rs | 27 ++++----------------------- + libm/configure.rs | 30 ++++++------------------------ + 2 files changed, 10 insertions(+), 47 deletions(-) diff --git a/library/compiler-builtins/compiler-builtins/configure.rs b/library/compiler-builtins/compiler-builtins/configure.rs -index 9721ddf090c..19a7886f496 100644 ---- a/library/compiler-builtins/compiler-builtins/configure.rs -+++ b/library/compiler-builtins/compiler-builtins/configure.rs -@@ -47,6 +47,12 @@ pub fn from_env() -> Self { - .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); - let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); +index caedc034d..79e238abc 100644 +--- a/compiler-builtins/configure.rs ++++ b/compiler-builtins/configure.rs +@@ -1,6 +1,5 @@ + // Configuration that is shared between `compiler_builtins` and `builtins_test`. + +-use std::process::{Command, Stdio}; + use std::{env, str}; -+ println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); println!("cargo::warning=rustflags: {:?}", env::var("RUSTFLAGS")); -+ for line in rustc_cfg.lines() { -+ println!("cargo::warning=cfg: {line}"); -+ } -+ // println!("cargo::warning=rustc: {}", env::var("RUSTC").unwrap()); -+ - // If we couldn't query `rustc` (e.g. a custom JSON target was used), make the safe - // choice and leave `f16` and `f128` disabled. - let rustc_output_ok = out.status.success(); -@@ -55,7 +61,7 @@ pub fn from_env() -> Self { - let reliable_f16 = - rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f16"); + #[derive(Debug)] +@@ -35,26 +34,6 @@ impl Target { + .map(|s| s.to_lowercase().replace("_", "-")) + .collect(); -- Self { -+ let ret = Self { +- // Query rustc for options that Cargo does not provide env for. The bootstrap hack is used +- // to get consistent output regardless of channel (`f16`/`f128` config options are hidden +- // on stable otherwise). +- let mut cmd = Command::new(env::var("RUSTC").unwrap()); +- cmd.args(["--print=cfg", "--target", &triple]) +- .env("RUSTC_BOOTSTRAP", "1") +- .stderr(Stdio::inherit()); +- let out = cmd +- .output() +- .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); +- let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); +- +- // If we couldn't query `rustc` (e.g. a custom JSON target was used), make the safe +- // choice and leave `f16` and `f128` disabled. +- let rustc_output_ok = out.status.success(); +- let reliable_f128 = +- rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f128"); +- let reliable_f16 = +- rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f16"); +- + Self { triple, triple_split, - os: env::var("CARGO_CFG_TARGET_OS").unwrap(), -@@ -76,7 +82,10 @@ pub fn from_env() -> Self { +@@ -74,8 +53,10 @@ impl Target { + .split(",") + .map(ToOwned::to_owned) .collect(), - reliable_f128, - reliable_f16, -- } -+ }; -+ -+ println!("cargo::warning=target: {ret:?}"); -+ ret +- reliable_f128, +- reliable_f16, ++ // Note that these are unstable options, so only show up with the nightly compiler or ++ // with `RUSTC_BOOTSTRAP=1` (which is required to use the types anyway). ++ reliable_f128: env::var_os("CARGO_CFG_TARGET_HAS_RELIABLE_F128").is_some(), ++ reliable_f16: env::var_os("CARGO_CFG_TARGET_HAS_RELIABLE_F16").is_some(), + } } - #[allow(dead_code)] +diff --git a/library/compiler-builtins/libm/configure.rs b/library/compiler-builtins/libm/configure.rs +index f9100d2d5..76186e636 100644 +--- a/libm/configure.rs ++++ b/libm/configure.rs +@@ -1,9 +1,9 @@ + // Configuration shared with both libm and libm-test + ++use std::env; + use std::path::PathBuf; +-use std::process::{Command, Stdio}; +-use std::{env, str}; + ++#[derive(Debug)] + #[allow(dead_code)] + pub struct Config { + pub manifest_dir: PathBuf, +@@ -33,26 +33,6 @@ impl Config { + .map(|s| s.to_lowercase().replace("_", "-")) + .collect(); + +- // Query rustc for options that Cargo does not provide env for. The bootstrap hack is used +- // to get consistent output regardless of channel (`f16`/`f128` config options are hidden +- // on stable otherwise). +- let mut cmd = Command::new(env::var("RUSTC").unwrap()); +- cmd.args(["--print=cfg", "--target", &target_triple]) +- .env("RUSTC_BOOTSTRAP", "1") +- .stderr(Stdio::inherit()); +- let out = cmd +- .output() +- .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); +- let rustc_cfg = str::from_utf8(&out.stdout).unwrap(); +- +- // If we couldn't query `rustc` (e.g. a custom JSON target was used), make the safe +- // choice and leave `f16` and `f128` disabled. +- let rustc_output_ok = out.status.success(); +- let reliable_f128 = +- rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f128"); +- let reliable_f16 = +- rustc_output_ok && rustc_cfg.lines().any(|l| l == "target_has_reliable_f16"); +- + Self { + target_triple, + manifest_dir: PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()), +@@ -66,8 +46,10 @@ impl Config { + target_string: env::var("TARGET").unwrap(), + target_vendor: env::var("CARGO_CFG_TARGET_VENDOR").unwrap(), + target_features, +- reliable_f128, +- reliable_f16, ++ // Note that these are unstable options, so only show up with the nightly compiler or ++ // with `RUSTC_BOOTSTRAP=1` (which is required to use the types anyway). ++ reliable_f128: env::var_os("CARGO_CFG_TARGET_HAS_RELIABLE_F128").is_some(), ++ reliable_f16: env::var_os("CARGO_CFG_TARGET_HAS_RELIABLE_F16").is_some(), + } + } + } -- 2.48.1 From 7961cab0a3125b161a5ff88f5f831f835d745c6e Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 5 Aug 2025 21:15:54 +0000 Subject: [PATCH 09/10] fix patch --- patches/0001-Debug-builtins-output.patch | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/patches/0001-Debug-builtins-output.patch b/patches/0001-Debug-builtins-output.patch index c1dbea3b6d5..c097e161814 100644 --- a/patches/0001-Debug-builtins-output.patch +++ b/patches/0001-Debug-builtins-output.patch @@ -27,8 +27,8 @@ Fixes: ed17b95715dd ("Use the compiler to determine whether or not to enable `f1 diff --git a/library/compiler-builtins/compiler-builtins/configure.rs b/library/compiler-builtins/compiler-builtins/configure.rs index caedc034d..79e238abc 100644 ---- a/compiler-builtins/configure.rs -+++ b/compiler-builtins/configure.rs +--- a/library/compiler-builtins/compiler-builtins/configure.rs ++++ b/library/compiler-builtins/compiler-builtins/configure.rs @@ -1,6 +1,5 @@ // Configuration that is shared between `compiler_builtins` and `builtins_test`. @@ -78,8 +78,8 @@ index caedc034d..79e238abc 100644 diff --git a/library/compiler-builtins/libm/configure.rs b/library/compiler-builtins/libm/configure.rs index f9100d2d5..76186e636 100644 ---- a/libm/configure.rs -+++ b/libm/configure.rs +--- a/library/compiler-builtins/libm/configure.rs ++++ b/library/compiler-builtins/libm/configure.rs @@ -1,9 +1,9 @@ // Configuration shared with both libm and libm-test From c8a5143dd287b082283738dd6ce3ddfcf10fbf2e Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 5 Aug 2025 21:22:44 +0000 Subject: [PATCH 10/10] fix ci --- .github/workflows/m68k.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/m68k.yml b/.github/workflows/m68k.yml index 90c3c695679..e49c62d6c93 100644 --- a/.github/workflows/m68k.yml +++ b/.github/workflows/m68k.yml @@ -102,7 +102,7 @@ jobs: - name: Run tests run: | - ./y.sh test --target-triple m68k-unknown-linux-gnu --release --clean --build-sysroot --sysroot-features ${{ matrix.commands }} + ./y.sh test --target-triple m68k-unknown-linux-gnu --release --clean --build-sysroot ${{ matrix.commands }} - name: Run Hello World! run: |