Skip to content

Commit 8d8801f

Browse files
authored
Allow mapping a runtime feature to a set of target_features (#1311)
1 parent 92ca93f commit 8d8801f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

crates/std_detect/src/detect/arch/aarch64.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ features! {
7272
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] pmull: "pmull";
7373
/// FEAT_PMULL (Polynomial Multiply)
7474
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] fp: "fp";
75-
/// FEAT_FP (Floating point support)
75+
implied by target_features: ["neon"];
76+
/// FEAT_FP (Floating point support) - Implied by `neon` target_feature
7677
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] fp16: "fp16";
7778
/// FEAT_FP16 (Half-float support)
7879
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] sve: "sve";

crates/std_detect/src/detect/macros.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
#[macro_export]
2+
macro_rules! detect_feature {
3+
($feature:tt, $feature_lit:tt) => {
4+
$crate::detect_feature!($feature, $feature_lit : $feature_lit)
5+
};
6+
($feature:tt, $feature_lit:tt : $($target_feature_lit:tt),*) => {
7+
$(cfg!(target_feature = $target_feature_lit) ||)*
8+
$crate::detect::__is_feature_detected::$feature()
9+
};
10+
}
11+
112
#[allow(unused)]
213
macro_rules! features {
314
(
@@ -7,7 +18,9 @@ macro_rules! features {
718
@MACRO_ATTRS: $(#[$macro_attrs:meta])*
819
$(@BIND_FEATURE_NAME: $bind_feature:tt; $feature_impl:tt; )*
920
$(@NO_RUNTIME_DETECTION: $nort_feature:tt; )*
10-
$(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt; $(#[$feature_comment:meta])*)*
21+
$(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt;
22+
$(implied by target_features: [$($target_feature_lit:tt),*];)?
23+
$(#[$feature_comment:meta])*)*
1124
) => {
1225
#[macro_export]
1326
$(#[$macro_attrs])*
@@ -17,8 +30,7 @@ macro_rules! features {
1730
macro_rules! $macro_name {
1831
$(
1932
($feature_lit) => {
20-
cfg!(target_feature = $feature_lit) ||
21-
$crate::detect::__is_feature_detected::$feature()
33+
$crate::detect_feature!($feature, $feature_lit $(: $($target_feature_lit),*)?)
2234
};
2335
)*
2436
$(

0 commit comments

Comments
 (0)