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