@@ -159,6 +159,7 @@ const BINDGEN_FILE_GENERATORS_TUPLES: &[(&str, GenerateFn)] = &[
159
159
( "base.rs" , generate_base) ,
160
160
( "wdf.rs" , generate_wdf) ,
161
161
( "hid.rs" , generate_hid) ,
162
+ ( "spb.rs" , generate_spb) ,
162
163
] ;
163
164
164
165
fn initialize_tracing ( ) -> Result < ( ) , ParseError > {
@@ -223,6 +224,8 @@ fn generate_constants(out_path: &Path, config: &Config) -> Result<(), ConfigErro
223
224
ApiSubset :: Wdf ,
224
225
#[ cfg( feature = "hid" ) ]
225
226
ApiSubset :: Hid ,
227
+ #[ cfg( feature = "spb" ) ]
228
+ ApiSubset :: Spb ,
226
229
] ) ;
227
230
trace ! ( header_contents = ?header_contents) ;
228
231
@@ -245,6 +248,8 @@ fn generate_types(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
245
248
ApiSubset :: Wdf ,
246
249
#[ cfg( feature = "hid" ) ]
247
250
ApiSubset :: Hid ,
251
+ #[ cfg( feature = "spb" ) ]
252
+ ApiSubset :: Spb ,
248
253
] ) ;
249
254
trace ! ( header_contents = ?header_contents) ;
250
255
@@ -295,10 +300,6 @@ fn generate_wdf(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
295
300
. allowlist_file ( "(?i).*wdf.*" ) ;
296
301
trace ! ( bindgen_builder = ?bindgen_builder) ;
297
302
298
- // As of NI WDK, this may generate an empty file due to no non-type and non-var
299
- // items in the wdf headers(i.e. functions are all inlined). This step is
300
- // intentionally left here in case older/newer WDKs have non-inlined functions
301
- // or new WDKs may introduce non-inlined functions.
302
303
Ok ( bindgen_builder
303
304
. generate ( )
304
305
. expect ( "Bindings should succeed to generate" )
@@ -348,6 +349,42 @@ fn generate_hid(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
348
349
}
349
350
}
350
351
352
+ fn generate_spb ( out_path : & Path , config : & Config ) -> Result < ( ) , ConfigError > {
353
+ cfg_if:: cfg_if! {
354
+ if #[ cfg( feature = "spb" ) ] {
355
+ info!( "Generating bindings to WDK: spb.rs" ) ;
356
+
357
+ let header_contents = config. bindgen_header_contents( [ ApiSubset :: Base , ApiSubset :: Wdf , ApiSubset :: Spb ] ) ;
358
+ trace!( header_contents = ?header_contents) ;
359
+
360
+ let bindgen_builder = {
361
+ let mut builder = bindgen:: Builder :: wdk_default( config) ?
362
+ . with_codegen_config( ( CodegenConfig :: TYPES | CodegenConfig :: VARS ) . complement( ) )
363
+ . header_contents( "spb-input.h" , & header_contents) ;
364
+
365
+ // Only allowlist files in the spb-specific files to avoid duplicate definitions
366
+ for header_file in config. headers( ApiSubset :: Spb )
367
+ {
368
+ builder = builder. allowlist_file( format!( "(?i).*{header_file}.*" ) ) ;
369
+ }
370
+ builder
371
+ } ;
372
+ trace!( bindgen_builder = ?bindgen_builder) ;
373
+
374
+ Ok ( bindgen_builder
375
+ . generate( )
376
+ . expect( "Bindings should succeed to generate" )
377
+ . write_to_file( out_path. join( "spb.rs" ) ) ?)
378
+ } else {
379
+ let _ = ( out_path, config) ; // Silence unused variable warnings when spb feature is not enabled
380
+
381
+ info!(
382
+ "Skipping spb.rs generation since spb feature is not enabled" ) ;
383
+ Ok ( ( ) )
384
+ }
385
+ }
386
+ }
387
+
351
388
/// Generates a `wdf_function_table.rs` file in `OUT_DIR` which contains the
352
389
/// definition of `WDF_FUNCTION_TABLE`. This is required to be generated here
353
390
/// since the size of the table is derived from either a global symbol
@@ -517,6 +554,8 @@ fn main() -> anyhow::Result<()> {
517
554
ApiSubset :: Wdf ,
518
555
#[ cfg( feature = "hid" ) ]
519
556
ApiSubset :: Hid ,
557
+ #[ cfg( feature = "spb" ) ]
558
+ ApiSubset :: Spb ,
520
559
] )
521
560
. as_bytes ( ) ,
522
561
) ?;
0 commit comments