Skip to content

Commit 6ecaadc

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 98a4362 commit 6ecaadc

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

library/std/build.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ 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_family =
11+
env::var("CARGO_CFG_TARGET_FAMILY").expect("CARGO_CFG_TARGET_FAMILY was not set");
12+
let target_pointer_width: u32 = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
13+
.expect("CARGO_CFG_TARGET_POINTER_WIDTH was not set")
14+
.parse()
15+
.unwrap();
1016

1117
println!("cargo:rustc-check-cfg=cfg(netbsd10)");
1218
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
@@ -70,4 +76,54 @@ fn main() {
7076
println!("cargo:rustc-cfg=backtrace_in_libstd");
7177

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

0 commit comments

Comments
 (0)