From 4359549eb8ee01d7b8298a0a3257a1fae7d02501 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 6 Jan 2025 01:10:04 +0000 Subject: [PATCH] Update the `libm` submodule --- build.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++----- configure.rs | 8 ++++++++ libm | 2 +- src/math.rs | 1 + 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index 22ec9e4d..2bb8651d 100644 --- a/build.rs +++ b/build.rs @@ -14,12 +14,9 @@ fn main() { configure_check_cfg(); configure_f16_f128(&target); - println!("cargo:compiler-rt={}", cwd.join("compiler-rt").display()); + configure_libm(&target); - // Activate libm's unstable features to make full use of Nightly. - println!("cargo::rustc-check-cfg=cfg(feature, values(\"unstable\", \"force-soft-floats\"))"); - println!("cargo:rustc-cfg=feature=\"unstable\""); - println!("cargo:rustc-cfg=feature=\"force-soft-floats\""); + println!("cargo:compiler-rt={}", cwd.join("compiler-rt").display()); // Emscripten's runtime includes all the builtins if target.os == "emscripten" { @@ -104,6 +101,48 @@ fn main() { } } +/// Run configuration for `libm` since it is included directly. +/// +/// Much of this is copied from `libm/configure.rs`. +fn configure_libm(target: &Target) { + println!("cargo:rustc-check-cfg=cfg(intrinsics_enabled)"); + println!("cargo:rustc-check-cfg=cfg(arch_enabled)"); + println!("cargo:rustc-check-cfg=cfg(optimizations_enabled)"); + println!("cargo:rustc-check-cfg=cfg(feature, values(\"unstable-public-internals\"))"); + + // Always use intrinsics + println!("cargo:rustc-cfg=intrinsics_enabled"); + + // The arch module may contain assembly. + if cfg!(feature = "no-asm") { + println!("cargo:rustc-cfg=feature=\"force-soft-floats\""); + } else { + println!("cargo:rustc-cfg=arch_enabled"); + } + + println!("cargo:rustc-check-cfg=cfg(optimizations_enabled)"); + if target.opt_level >= 2 { + println!("cargo:rustc-cfg=optimizations_enabled"); + } + + // Config shorthands + println!("cargo:rustc-check-cfg=cfg(x86_no_sse)"); + if target.arch == "x86" && !target.features.iter().any(|f| f == "sse") { + // Shorthand to detect i586 targets + println!("cargo:rustc-cfg=x86_no_sse"); + } + + println!( + "cargo:rustc-env=CFG_CARGO_FEATURES={:?}", + target.cargo_features + ); + println!("cargo:rustc-env=CFG_OPT_LEVEL={}", target.opt_level); + println!("cargo:rustc-env=CFG_TARGET_FEATURES={:?}", target.features); + + // Activate libm's unstable features to make full use of Nightly. + println!("cargo:rustc-cfg=feature=\"unstable-intrinsics\""); +} + fn aarch64_symbol(ordering: Ordering) -> &'static str { match ordering { Ordering::Relaxed => "relax", diff --git a/configure.rs b/configure.rs index e20c717e..6cfbe11c 100644 --- a/configure.rs +++ b/configure.rs @@ -6,6 +6,8 @@ use std::env; #[allow(dead_code)] pub struct Target { pub triple: String, + pub opt_level: u8, + pub cargo_features: Vec, pub os: String, pub arch: String, pub vendor: String, @@ -22,10 +24,16 @@ impl Target { "big" => false, x => panic!("unknown endian {x}"), }; + let cargo_features = env::vars() + .filter_map(|(name, _value)| name.strip_prefix("CARGO_FEATURE_").map(ToOwned::to_owned)) + .map(|s| s.to_lowercase().replace("_", "-")) + .collect(); Self { triple: env::var("TARGET").unwrap(), os: env::var("CARGO_CFG_TARGET_OS").unwrap(), + opt_level: env::var("OPT_LEVEL").unwrap().parse().unwrap(), + cargo_features, arch: env::var("CARGO_CFG_TARGET_ARCH").unwrap(), vendor: env::var("CARGO_CFG_TARGET_VENDOR").unwrap(), env: env::var("CARGO_CFG_TARGET_ENV").unwrap(), diff --git a/libm b/libm index f4e5b38a..424c3ece 160000 --- a/libm +++ b/libm @@ -1 +1 @@ -Subproject commit f4e5b38aee0e0c592a82ed45b21cd068c9b6c89a +Subproject commit 424c3ece1a7546de8530fa9d0fbf90d3b182cd18 diff --git a/src/math.rs b/src/math.rs index 477dfe36..da208239 100644 --- a/src/math.rs +++ b/src/math.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] #[allow(dead_code)] #[allow(unused_imports)] #[allow(clippy::all)]