Skip to content

Commit

Permalink
Allow mapping a runtime feature to a set of target_features (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgemmell authored Jul 1, 2022
1 parent 92ca93f commit 8d8801f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion crates/std_detect/src/detect/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ features! {
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] pmull: "pmull";
/// FEAT_PMULL (Polynomial Multiply)
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] fp: "fp";
/// FEAT_FP (Floating point support)
implied by target_features: ["neon"];
/// FEAT_FP (Floating point support) - Implied by `neon` target_feature
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] fp16: "fp16";
/// FEAT_FP16 (Half-float support)
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] sve: "sve";
Expand Down
18 changes: 15 additions & 3 deletions crates/std_detect/src/detect/macros.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#[macro_export]
macro_rules! detect_feature {
($feature:tt, $feature_lit:tt) => {
$crate::detect_feature!($feature, $feature_lit : $feature_lit)
};
($feature:tt, $feature_lit:tt : $($target_feature_lit:tt),*) => {
$(cfg!(target_feature = $target_feature_lit) ||)*
$crate::detect::__is_feature_detected::$feature()
};
}

#[allow(unused)]
macro_rules! features {
(
Expand All @@ -7,7 +18,9 @@ macro_rules! features {
@MACRO_ATTRS: $(#[$macro_attrs:meta])*
$(@BIND_FEATURE_NAME: $bind_feature:tt; $feature_impl:tt; )*
$(@NO_RUNTIME_DETECTION: $nort_feature:tt; )*
$(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt; $(#[$feature_comment:meta])*)*
$(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt;
$(implied by target_features: [$($target_feature_lit:tt),*];)?
$(#[$feature_comment:meta])*)*
) => {
#[macro_export]
$(#[$macro_attrs])*
Expand All @@ -17,8 +30,7 @@ macro_rules! features {
macro_rules! $macro_name {
$(
($feature_lit) => {
cfg!(target_feature = $feature_lit) ||
$crate::detect::__is_feature_detected::$feature()
$crate::detect_feature!($feature, $feature_lit $(: $($target_feature_lit),*)?)
};
)*
$(
Expand Down

0 comments on commit 8d8801f

Please sign in to comment.