Add an "arch" Cargo feature that is on by default

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.
This commit is contained in:
Trevor Gross 2024-10-28 20:24:46 -05:00
parent ec1ca51298
commit 6d1033e7fc
4 changed files with 18 additions and 1 deletions

View file

@ -14,7 +14,10 @@ exclude = ["/ci/", "/.github/workflows/"]
rust-version = "1.63"
[features]
default = []
default = ["arch"]
# Enable architecture-specific features such as SIMD or assembly routines.
arch = []
# This tells the compiler to assume that a Nightly toolchain is being used and
# that it should activate any useful Nightly things accordingly.

View file

@ -15,6 +15,7 @@ fn main() {
}
configure_intrinsics();
configure_arch();
}
/// Simplify the feature logic for enabling intrinsics so code only needs to use
@ -28,3 +29,14 @@ fn configure_intrinsics() {
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");
}
}

View file

@ -64,6 +64,7 @@ fi
# Make sure we can build with overriding features. We test the indibidual
# features it controls separately.
cargo check --no-default-features
cargo check --features "force-soft-floats"
if [ "${BUILD_ONLY:-}" = "1" ]; then

View file

@ -18,6 +18,7 @@ force-soft-floats = []
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
"cfg(arch_enabled)",
"cfg(assert_no_panic)",
"cfg(intrinsics_enabled)",
] }