Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 59f61b2

Browse files
committed
Split off f16 and f128 configuration from std/build.rs
This configuration needs to be reused for tests that aren't in `std`. To facilitate this, move the relevant portion of `build.rs` that can be `include!`d from other locations.
1 parent 4301f02 commit 59f61b2

File tree

2 files changed

+150
-114
lines changed

2 files changed

+150
-114
lines changed

library/std/build.rs

Lines changed: 8 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
use std::env;
22

3+
use build_shared::Config;
4+
mod build_shared;
5+
36
fn main() {
47
println!("cargo:rerun-if-changed=build.rs");
5-
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH was not set");
6-
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS was not set");
7-
let target_vendor =
8-
env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set");
9-
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();
8+
println!("cargo:rerun-if-changed=build_shared.rs");
9+
10+
let cfg = Config::from_env();
11+
let Config { ref target_arch, ref target_os, ref target_vendor, ref target_env, .. } = cfg;
1612

1713
println!("cargo:rustc-check-cfg=cfg(netbsd10)");
1814
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
@@ -81,107 +77,5 @@ fn main() {
8177

8278
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
8379

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-
}
80+
build_shared::configure_f16_f128(&cfg);
18781
}

library/std/build_shared.rs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// This portion of configuration is shared between `std` and `coretests`.
2+
3+
use std::env;
4+
5+
#[allow(dead_code)] // Not all importers of this file use all fields
6+
pub struct Config {
7+
pub target_arch: String,
8+
pub target_os: String,
9+
pub target_vendor: String,
10+
pub target_env: String,
11+
pub target_abi: String,
12+
pub target_pointer_width: u32,
13+
pub is_miri: bool,
14+
}
15+
16+
impl Config {
17+
pub fn from_env() -> Self {
18+
Self {
19+
target_arch: env::var("CARGO_CFG_TARGET_ARCH")
20+
.expect("CARGO_CFG_TARGET_ARCH was not set"),
21+
target_os: env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS was not set"),
22+
target_vendor: env::var("CARGO_CFG_TARGET_VENDOR")
23+
.expect("CARGO_CFG_TARGET_VENDOR was not set"),
24+
target_env: env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set"),
25+
target_abi: env::var("CARGO_CFG_TARGET_ABI").expect("CARGO_CFG_TARGET_ABI was not set"),
26+
target_pointer_width: env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
27+
.expect("CARGO_CFG_TARGET_POINTER_WIDTH was not set")
28+
.parse()
29+
.unwrap(),
30+
is_miri: env::var_os("CARGO_CFG_MIRI").is_some(),
31+
}
32+
}
33+
}
34+
35+
pub fn configure_f16_f128(cfg: &Config) {
36+
// Emit these on platforms that have no known ABI bugs, LLVM selection bugs, lowering bugs,
37+
// missing symbols, or other problems, to determine when tests get run.
38+
// If more broken platforms are found, please update the tracking issue at
39+
// <https://github.com/rust-lang/rust/issues/116909>
40+
//
41+
// Some of these match arms are redundant; the goal is to separate reasons that the type is
42+
// unreliable, even when multiple reasons might fail the same platform.
43+
println!("cargo:rustc-check-cfg=cfg(reliable_f16)");
44+
println!("cargo:rustc-check-cfg=cfg(reliable_f128)");
45+
46+
// This is a step beyond only having the types and basic functions available. Math functions
47+
// aren't consistently available or correct.
48+
println!("cargo:rustc-check-cfg=cfg(reliable_f16_math)");
49+
println!("cargo:rustc-check-cfg=cfg(reliable_f128_math)");
50+
51+
let target_arch = cfg.target_arch.as_str();
52+
let target_os = cfg.target_os.as_str();
53+
54+
let has_reliable_f16 = match (target_arch, target_os) {
55+
// We can always enable these in Miri as that is not affected by codegen bugs.
56+
_ if cfg.is_miri => true,
57+
// Selection failure <https://github.com/llvm/llvm-project/issues/50374>
58+
("s390x", _) => false,
59+
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
60+
("arm64ec", _) => false,
61+
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
62+
("x86_64", "windows") if cfg.target_env == "gnu" && cfg.target_abi != "llvm" => false,
63+
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
64+
("csky", _) => false,
65+
("hexagon", _) => false,
66+
("powerpc" | "powerpc64", _) => false,
67+
("sparc" | "sparc64", _) => false,
68+
("wasm32" | "wasm64", _) => false,
69+
// `f16` support only requires that symbols converting to and from `f32` are available. We
70+
// provide these in `compiler-builtins`, so `f16` should be available on all platforms that
71+
// do not have other ABI issues or LLVM crashes.
72+
_ => true,
73+
};
74+
75+
let has_reliable_f128 = match (target_arch, target_os) {
76+
// We can always enable these in Miri as that is not affected by codegen bugs.
77+
_ if cfg.is_miri => true,
78+
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
79+
("arm64ec", _) => false,
80+
// Selection bug <https://github.com/llvm/llvm-project/issues/96432>
81+
("mips64" | "mips64r6", _) => false,
82+
// Selection bug <https://github.com/llvm/llvm-project/issues/95471>
83+
("nvptx64", _) => false,
84+
// ABI bugs <https://github.com/rust-lang/rust/issues/125109> et al. (full
85+
// list at <https://github.com/rust-lang/rust/issues/116909>)
86+
("powerpc" | "powerpc64", _) => false,
87+
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
88+
("sparc", _) => false,
89+
// Stack alignment bug <https://github.com/llvm/llvm-project/issues/77401>. NB: tests may
90+
// not fail if our compiler-builtins is linked.
91+
("x86", _) => false,
92+
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
93+
("x86_64", "windows") if cfg.target_env == "gnu" && cfg.target_abi != "llvm" => false,
94+
// There are no known problems on other platforms, so the only requirement is that symbols
95+
// are available. `compiler-builtins` provides all symbols required for core `f128`
96+
// support, so this should work for everything else.
97+
_ => true,
98+
};
99+
100+
// Configure platforms that have reliable basics but may have unreliable math.
101+
102+
// LLVM is currently adding missing routines, <https://github.com/llvm/llvm-project/issues/93566>
103+
let has_reliable_f16_math = has_reliable_f16
104+
&& match (target_arch, target_os) {
105+
// FIXME: Disabled on Miri as the intrinsics are not implemented yet.
106+
_ if cfg.is_miri => false,
107+
// x86 has a crash for `powi`: <https://github.com/llvm/llvm-project/issues/105747>
108+
("x86" | "x86_64", _) => false,
109+
// Assume that working `f16` means working `f16` math for most platforms, since
110+
// operations just go through `f32`.
111+
_ => true,
112+
};
113+
114+
let has_reliable_f128_math = has_reliable_f128
115+
&& match (target_arch, target_os) {
116+
// FIXME: Disabled on Miri as the intrinsics are not implemented yet.
117+
_ if cfg.is_miri => false,
118+
// LLVM lowers `fp128` math to `long double` symbols even on platforms where
119+
// `long double` is not IEEE binary128. See
120+
// <https://github.com/llvm/llvm-project/issues/44744>.
121+
//
122+
// This rules out anything that doesn't have `long double` = `binary128`; <= 32 bits
123+
// (ld is `f64`), anything other than Linux (Windows and MacOS use `f64`), and `x86`
124+
// (ld is 80-bit extended precision).
125+
("x86_64", _) => false,
126+
(_, "linux") if cfg.target_pointer_width == 64 => true,
127+
_ => false,
128+
};
129+
130+
if has_reliable_f16 {
131+
println!("cargo:rustc-cfg=reliable_f16");
132+
}
133+
if has_reliable_f128 {
134+
println!("cargo:rustc-cfg=reliable_f128");
135+
}
136+
if has_reliable_f16_math {
137+
println!("cargo:rustc-cfg=reliable_f16_math");
138+
}
139+
if has_reliable_f128_math {
140+
println!("cargo:rustc-cfg=reliable_f128_math");
141+
}
142+
}

0 commit comments

Comments
 (0)