Skip to content

Commit fff8011

Browse files
committed
Add build.rs config for reliable f16 and f128
There are some complexities about what platforms we can test f16 and f128 on. Put this in build.rs so we have an easy way to configure tests with a single attribute, and keep it up to date.
1 parent 731406f commit fff8011

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

library/std/build.rs

+52
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ fn main() {
77
let target_vendor =
88
env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set");
99
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
10+
let target_pointer_width: u32 = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
11+
.expect("CARGO_CFG_TARGET_POINTER_WIDTH was not set")
12+
.parse()
13+
.unwrap();
1014

1115
println!("cargo:rustc-check-cfg=cfg(netbsd10)");
1216
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
@@ -70,4 +74,52 @@ fn main() {
7074
println!("cargo:rustc-cfg=backtrace_in_libstd");
7175

7276
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
77+
78+
// Emit these on platforms that have no known ABI bugs, LLVM selection bugs, lowering bugs,
79+
// missing symbols, or other problems, to determine when tests get run.
80+
// If more broken platforms are found, please update the tracking issue at
81+
// <https://github.com/rust-lang/rust/issues/116909>
82+
println!("cargo:rustc-check-cfg=cfg(reliable_f16)");
83+
println!("cargo:rustc-check-cfg=cfg(reliable_f128)");
84+
85+
let has_reliable_f16 = match (target_arch.as_str(), target_os.as_str()) {
86+
// Selection failure until recent LLVM <https://github.com/llvm/llvm-project/issues/93894>
87+
// FIXME(llvm19): can probably be removed at the version bump
88+
("loongarch64", _) => false,
89+
// Selection failure <https://github.com/llvm/llvm-project/issues/50374>
90+
("s390x", _) => false,
91+
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
92+
("arm64ec", _) => false,
93+
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
94+
("x86", "windows") => false,
95+
// x86 has ABI bugs that show up with optimizations. This should be partially fixed with
96+
// the compiler-builtins update. <https://github.com/rust-lang/rust/issues/123885>
97+
("x86" | "x86_64", _) => false,
98+
_ => true,
99+
};
100+
101+
let has_reliable_f128 = match (target_arch.as_str(), target_os.as_str()) {
102+
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
103+
("arm64ec", _) => false,
104+
// ABI and precision bugs <https://github.com/rust-lang/rust/issues/125109>
105+
// <https://github.com/rust-lang/rust/issues/125102>
106+
("powerpc" | "powerpc64", _) => false,
107+
// Selection bug <https://github.com/llvm/llvm-project/issues/95471>
108+
("nvptx64", _) => false,
109+
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
110+
("sparc", _) => false,
111+
// 64-bit Linux is about the only platform to have f128 symbols by default
112+
(_, "linux") if target_pointer_width == 64 => true,
113+
// Almost all OSs besides Linux are missing symbols until compiler-builtins can be
114+
// updated <https://github.com/rust-lang/rust/pull/125016> will get some of these, the
115+
// next CB update should get the rest.
116+
_ => false,
117+
};
118+
119+
if has_reliable_f16 {
120+
println!("cargo:rustc-cfg=reliable_f16");
121+
}
122+
if has_reliable_f128 {
123+
println!("cargo:rustc-cfg=reliable_f128");
124+
}
73125
}

0 commit comments

Comments
 (0)