2
2
macro_rules! features {
3
3
(
4
4
@TARGET : $target: ident;
5
+ @CFG : $cfg: meta;
5
6
@MACRO_NAME : $macro_name: ident;
6
7
@MACRO_ATTRS : $( #[ $macro_attrs: meta] ) *
7
8
$( @BIND_FEATURE_NAME : $bind_feature: tt; $feature_impl: tt; ) *
@@ -11,6 +12,7 @@ macro_rules! features {
11
12
#[ macro_export]
12
13
$( #[ $macro_attrs] ) *
13
14
#[ allow_internal_unstable( stdsimd_internal) ]
15
+ #[ cfg( $cfg) ]
14
16
macro_rules! $macro_name {
15
17
$(
16
18
( $feature_lit) => {
@@ -44,6 +46,47 @@ macro_rules! features {
44
46
} ;
45
47
}
46
48
49
+ $( #[ $macro_attrs] ) *
50
+ #[ macro_export]
51
+ #[ cfg( not( $cfg) ) ]
52
+ macro_rules! $macro_name {
53
+ $(
54
+ ( $feature_lit) => {
55
+ compile_error!(
56
+ r#"
57
+ This macro cannot be used on the current target.
58
+ You can prevent it from being used in other architectures by
59
+ guarding it behind a cfg(target_arch).
60
+ "#
61
+ )
62
+ } ;
63
+ ) *
64
+ $(
65
+ ( $bind_feature) => { $macro_name!( $feature_impl) } ;
66
+ ) *
67
+ $(
68
+ ( $nort_feature) => {
69
+ compile_error!(
70
+ concat!(
71
+ stringify!( $nort_feature) ,
72
+ " feature cannot be detected at run-time"
73
+ )
74
+ )
75
+ } ;
76
+ ) *
77
+ ( $t: tt, ) => {
78
+ $macro_name!( $t) ;
79
+ } ;
80
+ ( $t: tt) => {
81
+ compile_error!(
82
+ concat!(
83
+ concat!( "unknown " , stringify!( $target) ) ,
84
+ concat!( " target feature: " , $t)
85
+ )
86
+ )
87
+ } ;
88
+ }
89
+
47
90
/// Each variant denotes a position in a bitset for a particular feature.
48
91
///
49
92
/// PLEASE: do not use this, it is an implementation detail subject
@@ -53,6 +96,7 @@ macro_rules! features {
53
96
#[ derive( Copy , Clone ) ]
54
97
#[ repr( u8 ) ]
55
98
#[ unstable( feature = "stdsimd_internal" , issue = "none" ) ]
99
+ #[ cfg( $cfg) ]
56
100
pub ( crate ) enum Feature {
57
101
$(
58
102
$( #[ $feature_comment] ) *
@@ -63,6 +107,7 @@ macro_rules! features {
63
107
_last
64
108
}
65
109
110
+ #[ cfg( $cfg) ]
66
111
impl Feature {
67
112
pub ( crate ) fn to_str( self ) -> & ' static str {
68
113
match self {
@@ -86,6 +131,7 @@ macro_rules! features {
86
131
/// PLEASE: do not use this, it is an implementation detail subject
87
132
/// to change.
88
133
#[ doc( hidden) ]
134
+ #[ cfg( $cfg) ]
89
135
pub mod __is_feature_detected {
90
136
$(
91
137
0 commit comments