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