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,50 @@ 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
+ concat!(
59
+ r#"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("# ,
62
+ stringify!( $cfg) ,
63
+ ")."
64
+ )
65
+ )
66
+ } ;
67
+ ) *
68
+ $(
69
+ ( $bind_feature) => { $macro_name!( $feature_impl) } ;
70
+ ) *
71
+ $(
72
+ ( $nort_feature) => {
73
+ compile_error!(
74
+ concat!(
75
+ stringify!( $nort_feature) ,
76
+ " feature cannot be detected at run-time"
77
+ )
78
+ )
79
+ } ;
80
+ ) *
81
+ ( $t: tt, ) => {
82
+ $macro_name!( $t) ;
83
+ } ;
84
+ ( $t: tt) => {
85
+ compile_error!(
86
+ concat!(
87
+ concat!( "unknown " , stringify!( $target) ) ,
88
+ concat!( " target feature: " , $t)
89
+ )
90
+ )
91
+ } ;
92
+ }
93
+
47
94
/// Each variant denotes a position in a bitset for a particular feature.
48
95
///
49
96
/// PLEASE: do not use this, it is an implementation detail subject
@@ -53,6 +100,7 @@ macro_rules! features {
53
100
#[ derive( Copy , Clone ) ]
54
101
#[ repr( u8 ) ]
55
102
#[ unstable( feature = "stdsimd_internal" , issue = "none" ) ]
103
+ #[ cfg( $cfg) ]
56
104
pub ( crate ) enum Feature {
57
105
$(
58
106
$( #[ $feature_comment] ) *
@@ -63,6 +111,7 @@ macro_rules! features {
63
111
_last
64
112
}
65
113
114
+ #[ cfg( $cfg) ]
66
115
impl Feature {
67
116
pub ( crate ) fn to_str( self ) -> & ' static str {
68
117
match self {
@@ -86,6 +135,7 @@ macro_rules! features {
86
135
/// PLEASE: do not use this, it is an implementation detail subject
87
136
/// to change.
88
137
#[ doc( hidden) ]
138
+ #[ cfg( $cfg) ]
89
139
pub mod __is_feature_detected {
90
140
$(
91
141
0 commit comments