@@ -132,6 +132,7 @@ const BINDGEN_FILE_GENERATORS_TUPLES: &[(&str, GenerateFn)] = &[
132
132
( "base.rs" , generate_base) ,
133
133
( "wdf.rs" , generate_wdf) ,
134
134
( "hid.rs" , generate_hid) ,
135
+ ( "spb.rs" , generate_spb) ,
135
136
] ;
136
137
137
138
fn initialize_tracing ( ) -> Result < ( ) , ParseError > {
@@ -196,6 +197,8 @@ fn generate_constants(out_path: &Path, config: &Config) -> Result<(), ConfigErro
196
197
ApiSubset :: Wdf ,
197
198
#[ cfg( feature = "hid" ) ]
198
199
ApiSubset :: Hid ,
200
+ #[ cfg( feature = "spb" ) ]
201
+ ApiSubset :: Spb ,
199
202
] ) ;
200
203
trace ! ( header_contents = ?header_contents) ;
201
204
@@ -218,6 +221,8 @@ fn generate_types(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
218
221
ApiSubset :: Wdf ,
219
222
#[ cfg( feature = "hid" ) ]
220
223
ApiSubset :: Hid ,
224
+ #[ cfg( feature = "spb" ) ]
225
+ ApiSubset :: Spb ,
221
226
] ) ;
222
227
trace ! ( header_contents = ?header_contents) ;
223
228
@@ -268,10 +273,6 @@ fn generate_wdf(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
268
273
. allowlist_file ( "(?i).*wdf.*" ) ;
269
274
trace ! ( bindgen_builder = ?bindgen_builder) ;
270
275
271
- // As of NI WDK, this may generate an empty file due to no non-type and non-var
272
- // items in the wdf headers(i.e. functions are all inlined). This step is
273
- // intentionally left here in case older/newer WDKs have non-inlined functions
274
- // or new WDKs may introduce non-inlined functions.
275
276
Ok ( bindgen_builder
276
277
. generate ( )
277
278
. expect ( "Bindings should succeed to generate" )
@@ -321,6 +322,42 @@ fn generate_hid(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
321
322
}
322
323
}
323
324
325
+ fn generate_spb ( out_path : & Path , config : & Config ) -> Result < ( ) , ConfigError > {
326
+ cfg_if:: cfg_if! {
327
+ if #[ cfg( feature = "spb" ) ] {
328
+ info!( "Generating bindings to WDK: spb.rs" ) ;
329
+
330
+ let header_contents = config. bindgen_header_contents( [ ApiSubset :: Base , ApiSubset :: Wdf , ApiSubset :: Spb ] ) ;
331
+ trace!( header_contents = ?header_contents) ;
332
+
333
+ let bindgen_builder = {
334
+ let mut builder = bindgen:: Builder :: wdk_default( config) ?
335
+ . with_codegen_config( ( CodegenConfig :: TYPES | CodegenConfig :: VARS ) . complement( ) )
336
+ . header_contents( "spb-input.h" , & header_contents) ;
337
+
338
+ // Only allowlist files in the spb-specific files to avoid duplicate definitions
339
+ for header_file in config. headers( ApiSubset :: Spb )
340
+ {
341
+ builder = builder. allowlist_file( format!( "(?i).*{header_file}.*" ) ) ;
342
+ }
343
+ builder
344
+ } ;
345
+ trace!( bindgen_builder = ?bindgen_builder) ;
346
+
347
+ Ok ( bindgen_builder
348
+ . generate( )
349
+ . expect( "Bindings should succeed to generate" )
350
+ . write_to_file( out_path. join( "spb.rs" ) ) ?)
351
+ } else {
352
+ let _ = ( out_path, config) ; // Silence unused variable warnings when spb feature is not enabled
353
+
354
+ info!(
355
+ "Skipping spb.rs generation since spb feature is not enabled" ) ;
356
+ Ok ( ( ) )
357
+ }
358
+ }
359
+ }
360
+
324
361
/// Generates a `wdf_function_count.rs` file in `OUT_DIR` which contains the
325
362
/// definition of the function `get_wdf_function_count()`. This is required to
326
363
/// be generated here since the size of the table is derived from either a
@@ -480,6 +517,8 @@ fn main() -> anyhow::Result<()> {
480
517
ApiSubset :: Wdf ,
481
518
#[ cfg( feature = "hid" ) ]
482
519
ApiSubset :: Hid ,
520
+ #[ cfg( feature = "spb" ) ]
521
+ ApiSubset :: Spb ,
483
522
] )
484
523
. as_bytes ( ) ,
485
524
) ?;
0 commit comments