Skip to content

Commit 304739d

Browse files
committed
Use feature(target_has_reliable_f16_f128) in library tests
New compiler configuration has been introduced that is designed to replace the build script configuration `reliable_f16`, `reliable_f128`, `reliable_f16_math`, and `reliable_f128_math`. Do this replacement here, which allows us to clean up `std`'s build script. All tests are gated by `#[cfg(bootstrap)]` rather than doing a more complicated `cfg(bootstrap)` / `cfg(not(bootstrap))` split since the next beta split is within two weeks.
1 parent 9e82a89 commit 304739d

File tree

7 files changed

+558
-262
lines changed

7 files changed

+558
-262
lines changed

library/std/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@ check-cfg = [
163163
# and to the `backtrace` crate which messes-up with Cargo list
164164
# of declared features, we therefor expect any feature cfg
165165
'cfg(feature, values(any()))',
166+
# Internal features aren't marked known config by default, we use these to
167+
# gate tests.
168+
'cfg(target_has_reliable_f16)',
169+
'cfg(target_has_reliable_f16_math)',
170+
'cfg(target_has_reliable_f128)',
171+
'cfg(target_has_reliable_f128_math)',
166172
]

library/std/build.rs

-110
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ 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_abi = env::var("CARGO_CFG_TARGET_ABI").expect("CARGO_CFG_TARGET_ABI was not set");
11-
let target_pointer_width: u32 = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
12-
.expect("CARGO_CFG_TARGET_POINTER_WIDTH was not set")
13-
.parse()
14-
.unwrap();
15-
let is_miri = env::var_os("CARGO_CFG_MIRI").is_some();
1610

1711
println!("cargo:rustc-check-cfg=cfg(netbsd10)");
1812
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
@@ -80,108 +74,4 @@ fn main() {
8074
println!("cargo:rustc-cfg=backtrace_in_libstd");
8175

8276
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
83-
84-
// Emit these on platforms that have no known ABI bugs, LLVM selection bugs, lowering bugs,
85-
// missing symbols, or other problems, to determine when tests get run.
86-
// If more broken platforms are found, please update the tracking issue at
87-
// <https://github.com/rust-lang/rust/issues/116909>
88-
//
89-
// Some of these match arms are redundant; the goal is to separate reasons that the type is
90-
// unreliable, even when multiple reasons might fail the same platform.
91-
println!("cargo:rustc-check-cfg=cfg(reliable_f16)");
92-
println!("cargo:rustc-check-cfg=cfg(reliable_f128)");
93-
94-
// This is a step beyond only having the types and basic functions available. Math functions
95-
// aren't consistently available or correct.
96-
println!("cargo:rustc-check-cfg=cfg(reliable_f16_math)");
97-
println!("cargo:rustc-check-cfg=cfg(reliable_f128_math)");
98-
99-
let has_reliable_f16 = match (target_arch.as_str(), target_os.as_str()) {
100-
// We can always enable these in Miri as that is not affected by codegen bugs.
101-
_ if is_miri => true,
102-
// Selection failure <https://github.com/llvm/llvm-project/issues/50374>
103-
("s390x", _) => false,
104-
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
105-
("arm64ec", _) => false,
106-
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
107-
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
108-
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
109-
("csky", _) => false,
110-
("hexagon", _) => false,
111-
("powerpc" | "powerpc64", _) => false,
112-
("sparc" | "sparc64", _) => false,
113-
("wasm32" | "wasm64", _) => false,
114-
// `f16` support only requires that symbols converting to and from `f32` are available. We
115-
// provide these in `compiler-builtins`, so `f16` should be available on all platforms that
116-
// do not have other ABI issues or LLVM crashes.
117-
_ => true,
118-
};
119-
120-
let has_reliable_f128 = match (target_arch.as_str(), target_os.as_str()) {
121-
// We can always enable these in Miri as that is not affected by codegen bugs.
122-
_ if is_miri => true,
123-
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
124-
("arm64ec", _) => false,
125-
// Selection bug <https://github.com/llvm/llvm-project/issues/96432>
126-
("mips64" | "mips64r6", _) => false,
127-
// Selection bug <https://github.com/llvm/llvm-project/issues/95471>
128-
("nvptx64", _) => false,
129-
// ABI bugs <https://github.com/rust-lang/rust/issues/125109> et al. (full
130-
// list at <https://github.com/rust-lang/rust/issues/116909>)
131-
("powerpc" | "powerpc64", _) => false,
132-
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
133-
("sparc", _) => false,
134-
// Stack alignment bug <https://github.com/llvm/llvm-project/issues/77401>. NB: tests may
135-
// not fail if our compiler-builtins is linked.
136-
("x86", _) => false,
137-
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
138-
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
139-
// There are no known problems on other platforms, so the only requirement is that symbols
140-
// are available. `compiler-builtins` provides all symbols required for core `f128`
141-
// support, so this should work for everything else.
142-
_ => true,
143-
};
144-
145-
// Configure platforms that have reliable basics but may have unreliable math.
146-
147-
// LLVM is currently adding missing routines, <https://github.com/llvm/llvm-project/issues/93566>
148-
let has_reliable_f16_math = has_reliable_f16
149-
&& match (target_arch.as_str(), target_os.as_str()) {
150-
// FIXME: Disabled on Miri as the intrinsics are not implemented yet.
151-
_ if is_miri => false,
152-
// x86 has a crash for `powi`: <https://github.com/llvm/llvm-project/issues/105747>
153-
("x86" | "x86_64", _) => false,
154-
// Assume that working `f16` means working `f16` math for most platforms, since
155-
// operations just go through `f32`.
156-
_ => true,
157-
};
158-
159-
let has_reliable_f128_math = has_reliable_f128
160-
&& match (target_arch.as_str(), target_os.as_str()) {
161-
// FIXME: Disabled on Miri as the intrinsics are not implemented yet.
162-
_ if is_miri => false,
163-
// LLVM lowers `fp128` math to `long double` symbols even on platforms where
164-
// `long double` is not IEEE binary128. See
165-
// <https://github.com/llvm/llvm-project/issues/44744>.
166-
//
167-
// This rules out anything that doesn't have `long double` = `binary128`; <= 32 bits
168-
// (ld is `f64`), anything other than Linux (Windows and MacOS use `f64`), and `x86`
169-
// (ld is 80-bit extended precision).
170-
("x86_64", _) => false,
171-
(_, "linux") if target_pointer_width == 64 => true,
172-
_ => false,
173-
};
174-
175-
if has_reliable_f16 {
176-
println!("cargo:rustc-cfg=reliable_f16");
177-
}
178-
if has_reliable_f128 {
179-
println!("cargo:rustc-cfg=reliable_f128");
180-
}
181-
if has_reliable_f16_math {
182-
println!("cargo:rustc-cfg=reliable_f16_math");
183-
}
184-
if has_reliable_f128_math {
185-
println!("cargo:rustc-cfg=reliable_f128_math");
186-
}
18777
}

0 commit comments

Comments
 (0)