mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-15 00:37:04 +00:00

Introduce a Cargo feature to enable or disable architecture-specific features (SIMD, assembly), which is on by default. This allows for more fine grained control compared to relying on the `force-soft-floats` feature. Similar to "unstable-intrinsics", introduce a build.rs config option for `unstable-intrinsics AND NOT force-soft-floats`, which makes this easier to work with in code. Effectively, this allows moving our non-additive Cargo feature (force-soft-floats) to a positive one by default, allowing for an override when needed.
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
use std::env;
|
|
|
|
fn main() {
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
println!("cargo:rustc-check-cfg=cfg(assert_no_panic)");
|
|
|
|
println!("cargo:rustc-check-cfg=cfg(feature, values(\"checked\"))");
|
|
|
|
#[allow(unexpected_cfgs)]
|
|
if !cfg!(feature = "checked") {
|
|
let lvl = env::var("OPT_LEVEL").unwrap();
|
|
if lvl != "0" {
|
|
println!("cargo:rustc-cfg=assert_no_panic");
|
|
}
|
|
}
|
|
|
|
configure_intrinsics();
|
|
configure_arch();
|
|
}
|
|
|
|
/// Simplify the feature logic for enabling intrinsics so code only needs to use
|
|
/// `cfg(intrinsics_enabled)`.
|
|
fn configure_intrinsics() {
|
|
println!("cargo:rustc-check-cfg=cfg(intrinsics_enabled)");
|
|
|
|
// Disabled by default; `unstable-intrinsics` enables again; `force-soft-floats` overrides
|
|
// to disable.
|
|
if cfg!(feature = "unstable-intrinsics") && !cfg!(feature = "force-soft-floats") {
|
|
println!("cargo:rustc-cfg=intrinsics_enabled");
|
|
}
|
|
}
|
|
|
|
/// Simplify the feature logic for enabling arch-specific features so code only needs to use
|
|
/// `cfg(arch_enabled)`.
|
|
fn configure_arch() {
|
|
println!("cargo:rustc-check-cfg=cfg(arch_enabled)");
|
|
|
|
// Enabled by default via the "arch" feature, `force-soft-floats` overrides to disable.
|
|
if cfg!(feature = "arch") && !cfg!(feature = "force-soft-floats") {
|
|
println!("cargo:rustc-cfg=arch_enabled");
|
|
}
|
|
}
|