about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2024-06-20 22:05:07 -0400
committerTrevor Gross <tmgross@umich.edu>2024-06-25 01:32:36 -0400
commit99ed3d3e99da5bf7c1fc0df49425e2dc4d0ca2a9 (patch)
treef9ff6e49c09e7fcdde345b9e712e0f2cb6a2ad79
parent0314fe62bd178200a620b90b59becd735d6c2e66 (diff)
downloadrust-99ed3d3e99da5bf7c1fc0df49425e2dc4d0ca2a9.tar.gz
rust-99ed3d3e99da5bf7c1fc0df49425e2dc4d0ca2a9.zip
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.
-rw-r--r--library/std/build.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/library/std/build.rs b/library/std/build.rs
index 7d975df545e..55388648a14 100644
--- a/library/std/build.rs
+++ b/library/std/build.rs
@@ -7,6 +7,10 @@ fn main() {
     let target_vendor =
         env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set");
     let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
+    let target_pointer_width: u32 = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")
+        .expect("CARGO_CFG_TARGET_POINTER_WIDTH was not set")
+        .parse()
+        .unwrap();
 
     println!("cargo:rustc-check-cfg=cfg(netbsd10)");
     if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
@@ -70,4 +74,62 @@ fn main() {
     println!("cargo:rustc-cfg=backtrace_in_libstd");
 
     println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
+
+    // Emit these on platforms that have no known ABI bugs, LLVM selection bugs, lowering bugs,
+    // missing symbols, or other problems, to determine when tests get run.
+    // If more broken platforms are found, please update the tracking issue at
+    // <https://github.com/rust-lang/rust/issues/116909>
+    //
+    // Some of these match arms are redundant; the goal is to separate reasons that the type is
+    // unreliable, even when multiple reasons might fail the same platform.
+    println!("cargo:rustc-check-cfg=cfg(reliable_f16)");
+    println!("cargo:rustc-check-cfg=cfg(reliable_f128)");
+
+    let has_reliable_f16 = match (target_arch.as_str(), target_os.as_str()) {
+        // Selection failure until recent LLVM <https://github.com/llvm/llvm-project/issues/93894>
+        // FIXME(llvm19): can probably be removed at the version bump
+        ("loongarch64", _) => false,
+        // Selection failure <https://github.com/llvm/llvm-project/issues/50374>
+        ("s390x", _) => false,
+        // Unsupported <https://github.com/llvm/llvm-project/issues/94434>
+        ("arm64ec", _) => false,
+        // MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
+        ("x86", "windows") => false,
+        // x86 has ABI bugs that show up with optimizations. This should be partially fixed with
+        // the compiler-builtins update. <https://github.com/rust-lang/rust/issues/123885>
+        ("x86" | "x86_64", _) => false,
+        // Missing `__gnu_h2f_ieee` and `__gnu_f2h_ieee`
+        ("powerpc" | "powerpc64" | "powerpc64le", _) => false,
+        // Missing `__extendhfsf` and `__truncsfhf`
+        ("riscv32" | "riscv64", _) => false,
+        // Most OSs are missing `__extendhfsf` and `__truncsfhf`
+        (_, "linux" | "macos") => true,
+        // Almost all OSs besides Linux and MacOS are missing symbols until compiler-builtins can
+        // be updated. <https://github.com/rust-lang/rust/pull/125016> will get some of these, the
+        // next CB update should get the rest.
+        _ => false,
+    };
+
+    let has_reliable_f128 = match (target_arch.as_str(), target_os.as_str()) {
+        // Unsupported <https://github.com/llvm/llvm-project/issues/94434>
+        ("arm64ec", _) => false,
+        // ABI and precision bugs <https://github.com/rust-lang/rust/issues/125109>
+        // <https://github.com/rust-lang/rust/issues/125102>
+        ("powerpc" | "powerpc64", _) => false,
+        // Selection bug <https://github.com/llvm/llvm-project/issues/95471>
+        ("nvptx64", _) => false,
+        // ABI unsupported  <https://github.com/llvm/llvm-project/issues/41838>
+        ("sparc", _) => false,
+        // 64-bit Linux is about the only platform to have f128 symbols by default
+        (_, "linux") if target_pointer_width == 64 => true,
+        // Same as for f16, except MacOS is also missing f128 symbols.
+        _ => false,
+    };
+
+    if has_reliable_f16 {
+        println!("cargo:rustc-cfg=reliable_f16");
+    }
+    if has_reliable_f128 {
+        println!("cargo:rustc-cfg=reliable_f128");
+    }
 }