Skip to content

Commit d91dcf4

Browse files
committed
Configure which platforms get f16 and f128 enabled by default
By moving the logic for which platforms get symbols to `compiler_builtins` rather than rust-lang/rust, we can control where symbols get enabled without relying on Cargo features. Using Cargo features turned out to be a problem in [1]. This will help resolve errors like [2]. [1]: rust-lang/rust#128358 [2]: rust-lang/rust#128401
1 parent e3de4ab commit d91dcf4

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

build.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ impl Target {
4242

4343
fn main() {
4444
println!("cargo:rerun-if-changed=build.rs");
45-
configure_check_cfg();
46-
4745
let target = Target::from_env();
4846
let cwd = env::current_dir().unwrap();
4947

48+
configure_check_cfg();
49+
configure_f16_f128(&target);
50+
5051
println!("cargo:compiler-rt={}", cwd.join("compiler-rt").display());
5152

5253
// Activate libm's unstable features to make full use of Nightly.
@@ -259,6 +260,47 @@ fn configure_check_cfg() {
259260
println!("cargo::rustc-check-cfg=cfg(assert_no_panic)");
260261
}
261262

263+
/// Configure whether or not `f16` and `f128` support should be enabled.
264+
fn configure_f16_f128(target: &Target) {
265+
// Set whether or not `f16` and `f128` are supported at a basic level by LLVM. This only means
266+
// that the backend will not crash when using these types. This does not mean that the
267+
// backend does the right thing, or that the platform doesn't have ABI bugs.
268+
//
269+
// We do this here rather than in `rust-lang/rust` because configuring via cargo features is
270+
// not straightforward.
271+
//
272+
// Original source of this list:
273+
// <https://github.com/rust-lang/compiler-builtins/pull/652#issuecomment-2266151350>
274+
let (f16_ok, f128_ok) = match target.arch.as_str() {
275+
// `f16` and `f128` both crash <https://github.com/llvm/llvm-project/issues/94434>
276+
"arm64ec" => (false, false),
277+
// `f16` crashes <https://github.com/llvm/llvm-project/issues/50374>
278+
"s390x" => (false, true),
279+
// `f128` crashes <https://github.com/llvm/llvm-project/issues/96432>
280+
"mips64" | "mips64r6" => (true, false),
281+
// `f128` crashes <https://github.com/llvm/llvm-project/issues/101545>
282+
"powerpc64" if &target.os == "aix" => (true, false),
283+
// `f128` crashes <https://github.com/llvm/llvm-project/issues/41838>
284+
"sparc" | "sparcv9" => (true, false),
285+
// Most everything else works as of LLVM 19
286+
_ => (true, true),
287+
};
288+
289+
// If the feature is set, disable these types.
290+
let disable_both = env::var_os("CARGO_FEATURE_NO_F16_F128").is_some();
291+
292+
println!("cargo::rustc-check-cfg=cfg(f16_enabled)");
293+
println!("cargo::rustc-check-cfg=cfg(f128_enabled)");
294+
295+
if f16_ok && !disable_both {
296+
println!("cargo::rustc-cfg=f16_enabled");
297+
}
298+
299+
if f128_ok && !disable_both {
300+
println!("cargo::rustc-cfg=f128_enabled");
301+
}
302+
}
303+
262304
#[cfg(feature = "c")]
263305
mod c {
264306
use std::collections::{BTreeMap, HashSet};

0 commit comments

Comments
 (0)