1
- use bindgen:: callbacks:: TypeKind ;
2
- use bindgen:: {
3
- builder, Abi , AliasVariation , Builder , CodegenConfig , EnumVariation ,
1
+ use crate :: {
2
+ builder,
3
+ callbacks:: {
4
+ AttributeInfo , DeriveInfo , ItemInfo , ParseCallbacks , TypeKind ,
5
+ } ,
6
+ features:: RUST_TARGET_STRINGS ,
7
+ Abi , AliasVariation , Builder , CodegenConfig , EnumVariation ,
4
8
FieldVisibilityKind , Formatter , MacroTypeVariation , NonCopyUnionStyle ,
5
- RegexSet , RustTarget , DEFAULT_ANON_FIELDS_PREFIX , RUST_TARGET_STRINGS ,
9
+ RegexSet , RustTarget , DEFAULT_ANON_FIELDS_PREFIX ,
10
+ } ;
11
+ use clap:: {
12
+ error:: { Error , ErrorKind } ,
13
+ CommandFactory , Parser ,
6
14
} ;
7
- use clap:: error:: { Error , ErrorKind } ;
8
- use clap:: { CommandFactory , Parser } ;
9
15
use proc_macro2:: TokenStream ;
10
16
use std:: fs:: File ;
11
17
use std:: io;
@@ -491,6 +497,7 @@ struct BindgenCommand {
491
497
#[ arg( long, value_name = "VISIBILITY" ) ]
492
498
default_visibility : Option < FieldVisibilityKind > ,
493
499
/// Whether to emit diagnostics or not.
500
+ #[ cfg( feature = "experimental" ) ]
494
501
#[ arg( long, requires = "experimental" ) ]
495
502
emit_diagnostics : bool ,
496
503
/// Generates completions for the specified SHELL, sends them to `stdout` and exits.
@@ -633,6 +640,7 @@ where
633
640
wrap_static_fns_path,
634
641
wrap_static_fns_suffix,
635
642
default_visibility,
643
+ #[ cfg( feature = "experimental" ) ]
636
644
emit_diagnostics,
637
645
generate_shell_completions,
638
646
experimental: _,
@@ -657,7 +665,7 @@ where
657
665
option_env!( "CARGO_PKG_VERSION" ) . unwrap_or( "unknown" )
658
666
) ;
659
667
if verbose {
660
- println ! ( "Clang: {}" , bindgen :: clang_version( ) . full) ;
668
+ println ! ( "Clang: {}" , crate :: clang_version( ) . full) ;
661
669
}
662
670
std:: process:: exit ( 0 ) ;
663
671
}
@@ -1046,10 +1054,10 @@ where
1046
1054
prefix : String ,
1047
1055
}
1048
1056
1049
- impl bindgen :: callbacks :: ParseCallbacks for PrefixLinkNameCallback {
1057
+ impl ParseCallbacks for PrefixLinkNameCallback {
1050
1058
fn generated_link_name_override (
1051
1059
& self ,
1052
- item_info : bindgen :: callbacks :: ItemInfo < ' _ > ,
1060
+ item_info : ItemInfo < ' _ > ,
1053
1061
) -> Option < String > {
1054
1062
let mut prefix = self . prefix . clone ( ) ;
1055
1063
prefix. push_str ( item_info. name ) ;
@@ -1114,10 +1122,10 @@ where
1114
1122
struct CustomDeriveCallback {
1115
1123
derives : Vec < String > ,
1116
1124
kind : Option < TypeKind > ,
1117
- regex_set : bindgen :: RegexSet ,
1125
+ regex_set : RegexSet ,
1118
1126
}
1119
1127
1120
- impl bindgen :: callbacks :: ParseCallbacks for CustomDeriveCallback {
1128
+ impl ParseCallbacks for CustomDeriveCallback {
1121
1129
fn cli_args ( & self ) -> Vec < String > {
1122
1130
let mut args = vec ! [ ] ;
1123
1131
@@ -1140,10 +1148,7 @@ where
1140
1148
args
1141
1149
}
1142
1150
1143
- fn add_derives (
1144
- & self ,
1145
- info : & bindgen:: callbacks:: DeriveInfo < ' _ > ,
1146
- ) -> Vec < String > {
1151
+ fn add_derives ( & self , info : & DeriveInfo < ' _ > ) -> Vec < String > {
1147
1152
if self . kind . map ( |kind| kind == info. kind ) . unwrap_or ( true ) &&
1148
1153
self . regex_set . matches ( info. name )
1149
1154
{
@@ -1153,7 +1158,7 @@ where
1153
1158
}
1154
1159
}
1155
1160
1156
- for ( custom_derives, kind, name ) in [
1161
+ for ( custom_derives, kind, _name ) in [
1157
1162
( with_derive_custom, None , "--with-derive-custom" ) ,
1158
1163
(
1159
1164
with_derive_custom_struct,
@@ -1171,11 +1176,17 @@ where
1171
1176
"--with-derive-custom-union" ,
1172
1177
) ,
1173
1178
] {
1174
- let name = emit_diagnostics. then_some ( name) ;
1179
+ #[ cfg( feature = "experimental" ) ]
1180
+ let name = emit_diagnostics. then_some ( _name) ;
1181
+
1175
1182
for ( derives, regex) in custom_derives {
1176
1183
let mut regex_set = RegexSet :: new ( ) ;
1177
1184
regex_set. insert ( regex) ;
1185
+
1186
+ #[ cfg( feature = "experimental" ) ]
1178
1187
regex_set. build_with_diagnostics ( false , name) ;
1188
+ #[ cfg( not( feature = "experimental" ) ) ]
1189
+ regex_set. build ( false ) ;
1179
1190
1180
1191
builder = builder. parse_callbacks ( Box :: new ( CustomDeriveCallback {
1181
1192
derives,
@@ -1189,10 +1200,10 @@ where
1189
1200
struct CustomAttributeCallback {
1190
1201
attributes : Vec < String > ,
1191
1202
kind : Option < TypeKind > ,
1192
- regex_set : bindgen :: RegexSet ,
1203
+ regex_set : RegexSet ,
1193
1204
}
1194
1205
1195
- impl bindgen :: callbacks :: ParseCallbacks for CustomAttributeCallback {
1206
+ impl ParseCallbacks for CustomAttributeCallback {
1196
1207
fn cli_args ( & self ) -> Vec < String > {
1197
1208
let mut args = vec ! [ ] ;
1198
1209
@@ -1215,10 +1226,7 @@ where
1215
1226
args
1216
1227
}
1217
1228
1218
- fn add_attributes (
1219
- & self ,
1220
- info : & bindgen:: callbacks:: AttributeInfo < ' _ > ,
1221
- ) -> Vec < String > {
1229
+ fn add_attributes ( & self , info : & AttributeInfo < ' _ > ) -> Vec < String > {
1222
1230
if self . kind . map ( |kind| kind == info. kind ) . unwrap_or ( true ) &&
1223
1231
self . regex_set . matches ( info. name )
1224
1232
{
@@ -1228,7 +1236,7 @@ where
1228
1236
}
1229
1237
}
1230
1238
1231
- for ( custom_attributes, kind, name ) in [
1239
+ for ( custom_attributes, kind, _name ) in [
1232
1240
( with_attribute_custom, None , "--with-attribute-custom" ) ,
1233
1241
(
1234
1242
with_attribute_custom_struct,
@@ -1246,11 +1254,17 @@ where
1246
1254
"--with-attribute-custom-union" ,
1247
1255
) ,
1248
1256
] {
1249
- let name = emit_diagnostics. then_some ( name) ;
1257
+ #[ cfg( feature = "experimental" ) ]
1258
+ let name = emit_diagnostics. then_some ( _name) ;
1259
+
1250
1260
for ( attributes, regex) in custom_attributes {
1251
1261
let mut regex_set = RegexSet :: new ( ) ;
1252
1262
regex_set. insert ( regex) ;
1263
+
1264
+ #[ cfg( feature = "experimental" ) ]
1253
1265
regex_set. build_with_diagnostics ( false , name) ;
1266
+ #[ cfg( not( feature = "experimental" ) ) ]
1267
+ regex_set. build ( false ) ;
1254
1268
1255
1269
builder =
1256
1270
builder. parse_callbacks ( Box :: new ( CustomAttributeCallback {
@@ -1277,6 +1291,7 @@ where
1277
1291
builder = builder. default_visibility ( visibility) ;
1278
1292
}
1279
1293
1294
+ #[ cfg( feature = "experimental" ) ]
1280
1295
if emit_diagnostics {
1281
1296
builder = builder. emit_diagnostics ( ) ;
1282
1297
}
0 commit comments