|
1 | 1 | use std::{collections::BTreeMap, env, path::PathBuf, sync::atomic::Ordering};
|
2 | 2 |
|
3 |
| -#[allow(dead_code)] |
4 |
| -struct Target { |
5 |
| - triple: String, |
6 |
| - os: String, |
7 |
| - arch: String, |
8 |
| - vendor: String, |
9 |
| - env: String, |
10 |
| - pointer_width: u8, |
11 |
| - little_endian: bool, |
12 |
| - features: Vec<String>, |
13 |
| -} |
14 |
| - |
15 |
| -impl Target { |
16 |
| - fn from_env() -> Self { |
17 |
| - let little_endian = match env::var("CARGO_CFG_TARGET_ENDIAN").unwrap().as_str() { |
18 |
| - "little" => true, |
19 |
| - "big" => false, |
20 |
| - x => panic!("unknown endian {x}"), |
21 |
| - }; |
| 3 | +mod configure; |
22 | 4 |
|
23 |
| - Self { |
24 |
| - triple: env::var("TARGET").unwrap(), |
25 |
| - os: env::var("CARGO_CFG_TARGET_OS").unwrap(), |
26 |
| - arch: env::var("CARGO_CFG_TARGET_ARCH").unwrap(), |
27 |
| - vendor: env::var("CARGO_CFG_TARGET_VENDOR").unwrap(), |
28 |
| - env: env::var("CARGO_CFG_TARGET_ENV").unwrap(), |
29 |
| - pointer_width: env::var("CARGO_CFG_TARGET_POINTER_WIDTH") |
30 |
| - .unwrap() |
31 |
| - .parse() |
32 |
| - .unwrap(), |
33 |
| - little_endian, |
34 |
| - features: env::var("CARGO_CFG_TARGET_FEATURE") |
35 |
| - .unwrap_or_default() |
36 |
| - .split(",") |
37 |
| - .map(ToOwned::to_owned) |
38 |
| - .collect(), |
39 |
| - } |
40 |
| - } |
41 |
| -} |
| 5 | +use configure::{configure_f16_f128, Target}; |
42 | 6 |
|
43 | 7 | fn main() {
|
44 | 8 | println!("cargo:rerun-if-changed=build.rs");
|
@@ -261,49 +225,6 @@ fn configure_check_cfg() {
|
261 | 225 | println!("cargo::rustc-check-cfg=cfg(assert_no_panic)");
|
262 | 226 | }
|
263 | 227 |
|
264 |
| -/// Configure whether or not `f16` and `f128` support should be enabled. |
265 |
| -fn configure_f16_f128(target: &Target) { |
266 |
| - // Set whether or not `f16` and `f128` are supported at a basic level by LLVM. This only means |
267 |
| - // that the backend will not crash when using these types. This does not mean that the |
268 |
| - // backend does the right thing, or that the platform doesn't have ABI bugs. |
269 |
| - // |
270 |
| - // We do this here rather than in `rust-lang/rust` because configuring via cargo features is |
271 |
| - // not straightforward. |
272 |
| - // |
273 |
| - // Original source of this list: |
274 |
| - // <https://github.com/rust-lang/compiler-builtins/pull/652#issuecomment-2266151350> |
275 |
| - let (f16_ok, f128_ok) = match target.arch.as_str() { |
276 |
| - // `f16` and `f128` both crash <https://github.com/llvm/llvm-project/issues/94434> |
277 |
| - "arm64ec" => (false, false), |
278 |
| - // `f16` crashes <https://github.com/llvm/llvm-project/issues/50374> |
279 |
| - "s390x" => (false, true), |
280 |
| - // `f128` crashes <https://github.com/llvm/llvm-project/issues/96432> |
281 |
| - "mips64" | "mips64r6" => (true, false), |
282 |
| - // `f128` crashes <https://github.com/llvm/llvm-project/issues/101545> |
283 |
| - "powerpc64" if &target.os == "aix" => (true, false), |
284 |
| - // `f128` crashes <https://github.com/llvm/llvm-project/issues/41838> |
285 |
| - "sparc" | "sparcv9" => (true, false), |
286 |
| - // `f16` miscompiles <https://github.com/llvm/llvm-project/issues/96438> |
287 |
| - "wasm32" | "wasm64" => (false, true), |
288 |
| - // Most everything else works as of LLVM 19 |
289 |
| - _ => (true, true), |
290 |
| - }; |
291 |
| - |
292 |
| - // If the feature is set, disable these types. |
293 |
| - let disable_both = env::var_os("CARGO_FEATURE_NO_F16_F128").is_some(); |
294 |
| - |
295 |
| - println!("cargo::rustc-check-cfg=cfg(f16_enabled)"); |
296 |
| - println!("cargo::rustc-check-cfg=cfg(f128_enabled)"); |
297 |
| - |
298 |
| - if f16_ok && !disable_both { |
299 |
| - println!("cargo::rustc-cfg=f16_enabled"); |
300 |
| - } |
301 |
| - |
302 |
| - if f128_ok && !disable_both { |
303 |
| - println!("cargo::rustc-cfg=f128_enabled"); |
304 |
| - } |
305 |
| -} |
306 |
| - |
307 | 228 | #[cfg(feature = "c")]
|
308 | 229 | mod c {
|
309 | 230 | use std::collections::{BTreeMap, HashSet};
|
|
0 commit comments