Skip to content

Commit e8726ef

Browse files
committed
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.
1 parent 88f6b83 commit e8726ef

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ exclude = ["/ci/", "/.github/workflows/"]
1414
rust-version = "1.63"
1515

1616
[features]
17-
default = []
17+
default = ["arch"]
18+
19+
# Enable architecture-specific features such as SIMD or assembly routines.
20+
arch = []
1821

1922
# This tells the compiler to assume that a Nightly toolchain is being used and
2023
# that it should activate any useful Nightly things accordingly.

build.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn main() {
1515
}
1616

1717
configure_intrinsics();
18+
configure_arch();
1819
}
1920

2021
/// Simplify the feature logic for enabling intrinsics so code only needs to use
@@ -28,3 +29,14 @@ fn configure_intrinsics() {
2829
println!("cargo:rustc-cfg=intrinsics_enabled");
2930
}
3031
}
32+
33+
/// Simplify the feature logic for enabling arch-specific features so code only needs to use
34+
/// `cfg(arch_enabled)`.
35+
fn configure_arch() {
36+
println!("cargo:rustc-check-cfg=cfg(arch_enabled)");
37+
38+
// Enabled by default via the "arch" feature, `force-soft-floats` overrides to disable.
39+
if cfg!(feature = "arch") && !cfg!(feature = "force-soft-floats") {
40+
println!("cargo:rustc-cfg=arch_enabled");
41+
}
42+
}

ci/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fi
6464

6565
# Make sure we can build with overriding features. We test the indibidual
6666
# features it controls separately.
67+
cargo check --no-default-features
6768
cargo check --features "force-soft-floats"
6869

6970
if [ "${BUILD_ONLY:-}" = "1" ]; then

crates/compiler-builtins-smoke-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ force-soft-floats = []
1818

1919
[lints.rust]
2020
unexpected_cfgs = { level = "warn", check-cfg = [
21+
"cfg(arch_enabled)",
2122
"cfg(assert_no_panic)",
2223
"cfg(intrinsics_enabled)",
2324
] }

0 commit comments

Comments
 (0)