diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 95b0962b0..541c99c82 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -195,6 +195,25 @@ jobs: run: ./ci/update-musl.sh - run: cargo clippy --workspace --all-targets + build-custom: + name: Build custom target + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: | + rustup update nightly --no-self-update + rustup default nightly + rustup component add rust-src + - uses: Swatinem/rust-cache@v2 + - run: | + # Ensure we can build with custom target.json files (these can interact + # poorly with build scripts) + cargo build -p compiler_builtins -p libm \ + --target etc/thumbv7em-none-eabi-renamed.json \ + -Zbuild-std=core + benchmarks: name: Benchmarks timeout-minutes: 20 @@ -331,6 +350,7 @@ jobs: success: needs: - benchmarks + - build-custom - clippy - extensive - miri diff --git a/compiler-builtins/configure.rs b/compiler-builtins/configure.rs index a1e45080e..9721ddf09 100644 --- a/compiler-builtins/configure.rs +++ b/compiler-builtins/configure.rs @@ -45,9 +45,16 @@ impl Target { let out = cmd .output() .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); - assert!(out.status.success(), "failed to run `{cmd:?}`"); 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, @@ -67,8 +74,8 @@ impl Target { .split(",") .map(ToOwned::to_owned) .collect(), - reliable_f128: rustc_cfg.lines().any(|l| l == "target_has_reliable_f128"), - reliable_f16: rustc_cfg.lines().any(|l| l == "target_has_reliable_f16"), + reliable_f128, + reliable_f16, } } diff --git a/etc/thumbv7em-none-eabi-renamed.json b/etc/thumbv7em-none-eabi-renamed.json new file mode 100644 index 000000000..81273d44e --- /dev/null +++ b/etc/thumbv7em-none-eabi-renamed.json @@ -0,0 +1,23 @@ +{ + "abi": "eabi", + "arch": "arm", + "c-enum-min-bits": 8, + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64", + "emit-debug-gdb-scripts": false, + "frame-pointer": "always", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-floatabi": "soft", + "llvm-target": "thumbv7em-none-eabi", + "max-atomic-width": 32, + "metadata": { + "description": "Bare ARMv7E-M", + "host_tools": false, + "std": false, + "tier": 2 + }, + "panic-strategy": "abort", + "relocation-model": "static", + "target-pointer-width": "32" +} diff --git a/libm/configure.rs b/libm/configure.rs index 6562ecbe5..f9100d2d5 100644 --- a/libm/configure.rs +++ b/libm/configure.rs @@ -43,9 +43,16 @@ impl Config { let out = cmd .output() .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}")); - assert!(out.status.success(), "failed to run `{cmd:?}`"); 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()), @@ -59,8 +66,8 @@ impl Config { target_string: env::var("TARGET").unwrap(), target_vendor: env::var("CARGO_CFG_TARGET_VENDOR").unwrap(), target_features, - reliable_f128: rustc_cfg.lines().any(|l| l == "target_has_reliable_f128"), - reliable_f16: rustc_cfg.lines().any(|l| l == "target_has_reliable_f16"), + reliable_f128, + reliable_f16, } } }