@@ -675,7 +675,7 @@ impl Config {
675
675
}
676
676
677
677
/// Returns a [`String`] containing the contents of a header file designed
678
- /// for [`bindgen`](https://docs.rs/bindgen) to processs
678
+ /// for [`bindgen`](https://docs.rs/bindgen) to process
679
679
///
680
680
/// The contents contain `#include`'ed headers based off the [`ApiSubset`]
681
681
/// and [`Config`], as well as any additional definitions required for the
@@ -686,85 +686,11 @@ impl Config {
686
686
) -> String {
687
687
api_subsets
688
688
. into_iter ( )
689
- . fold ( String :: new ( ) , |mut acc, api_subset| {
690
- acc. push_str (
691
- self . headers ( api_subset)
692
- . fold ( String :: new ( ) , |mut acc, header| {
693
- acc. push_str ( r#"#include ""# ) ;
694
- acc. push_str ( & header) ;
695
- acc. push_str ( "\" \n " ) ;
696
- acc
697
- } )
698
- . as_str ( ) ,
699
- ) ;
700
-
701
- if api_subset == ApiSubset :: Base
702
- && matches ! (
703
- self . driver_config,
704
- DriverConfig :: Wdm | DriverConfig :: Kmdf ( _)
705
- )
706
- {
707
- // TODO: Why is there no definition for this struct? Maybe blocklist this struct
708
- // in bindgen.
709
- acc. push_str (
710
- r"
711
- typedef union _KGDTENTRY64
712
- {
713
- struct
714
- {
715
- unsigned short LimitLow;
716
- unsigned short BaseLow;
717
- union
718
- {
719
- struct
720
- {
721
- unsigned char BaseMiddle;
722
- unsigned char Flags1;
723
- unsigned char Flags2;
724
- unsigned char BaseHigh;
725
- } Bytes;
726
- struct
727
- {
728
- unsigned long BaseMiddle : 8;
729
- unsigned long Type : 5;
730
- unsigned long Dpl : 2;
731
- unsigned long Present : 1;
732
- unsigned long LimitHigh : 4;
733
- unsigned long System : 1;
734
- unsigned long LongMode : 1;
735
- unsigned long DefaultBig : 1;
736
- unsigned long Granularity : 1;
737
- unsigned long BaseHigh : 8;
738
- } Bits;
739
- };
740
- unsigned long BaseUpper;
741
- unsigned long MustBeZero;
742
- };
743
- unsigned __int64 Alignment;
744
- } KGDTENTRY64, *PKGDTENTRY64;
745
-
746
- typedef union _KIDTENTRY64
747
- {
748
- struct
749
- {
750
- unsigned short OffsetLow;
751
- unsigned short Selector;
752
- unsigned short IstIndex : 3;
753
- unsigned short Reserved0 : 5;
754
- unsigned short Type : 5;
755
- unsigned short Dpl : 2;
756
- unsigned short Present : 1;
757
- unsigned short OffsetMiddle;
758
- unsigned long OffsetHigh;
759
- unsigned long Reserved1;
760
- };
761
- unsigned __int64 Alignment;
762
- } KIDTENTRY64, *PKIDTENTRY64;
763
- " ,
764
- ) ;
765
- }
766
- acc
689
+ . flat_map ( |api_subset| {
690
+ self . headers ( api_subset)
691
+ . map ( |header| format ! ( "#include \" {header}\" \n " ) )
767
692
} )
693
+ . collect :: < String > ( )
768
694
}
769
695
770
696
/// Configure a Cargo build of a library that depends on the WDK. This
@@ -1332,6 +1258,64 @@ mod tests {
1332
1258
assert_eq ! ( CpuArchitecture :: try_from_cargo_str( "arm" ) , None ) ;
1333
1259
}
1334
1260
1261
+ mod bindgen_header_contents {
1262
+ use super :: * ;
1263
+ use crate :: { KmdfConfig , UmdfConfig } ;
1264
+
1265
+ #[ test]
1266
+ fn wdm ( ) {
1267
+ let config = with_env ( & [ ( "CARGO_CFG_TARGET_ARCH" , "x86_64" ) ] , || Config {
1268
+ driver_config : DriverConfig :: Wdm ,
1269
+ ..Default :: default ( )
1270
+ } ) ;
1271
+
1272
+ assert_eq ! (
1273
+ config. bindgen_header_contents( [ ApiSubset :: Base ] ) ,
1274
+ r#"#include "ntifs.h"
1275
+ #include "ntddk.h"
1276
+ "# ,
1277
+ ) ;
1278
+ }
1279
+
1280
+ #[ test]
1281
+ fn kmdf ( ) {
1282
+ let config = with_env ( & [ ( "CARGO_CFG_TARGET_ARCH" , "x86_64" ) ] , || Config {
1283
+ driver_config : DriverConfig :: Kmdf ( KmdfConfig {
1284
+ kmdf_version_major : 1 ,
1285
+ target_kmdf_version_minor : 33 ,
1286
+ minimum_kmdf_version_minor : None ,
1287
+ } ) ,
1288
+ ..Default :: default ( )
1289
+ } ) ;
1290
+
1291
+ assert_eq ! (
1292
+ config. bindgen_header_contents( [ ApiSubset :: Base , ApiSubset :: Wdf ] ) ,
1293
+ r#"#include "ntifs.h"
1294
+ #include "ntddk.h"
1295
+ #include "wdf.h"
1296
+ "# ,
1297
+ ) ;
1298
+ }
1299
+
1300
+ #[ test]
1301
+ fn umdf ( ) {
1302
+ let config = with_env ( & [ ( "CARGO_CFG_TARGET_ARCH" , "aarch64" ) ] , || Config {
1303
+ driver_config : DriverConfig :: Umdf ( UmdfConfig {
1304
+ umdf_version_major : 2 ,
1305
+ target_umdf_version_minor : 15 ,
1306
+ minimum_umdf_version_minor : None ,
1307
+ } ) ,
1308
+ ..Default :: default ( )
1309
+ } ) ;
1310
+
1311
+ assert_eq ! (
1312
+ config. bindgen_header_contents( [ ApiSubset :: Base , ApiSubset :: Wdf ] ) ,
1313
+ r#"#include "windows.h"
1314
+ #include "wdf.h"
1315
+ "# ,
1316
+ ) ;
1317
+ }
1318
+ }
1335
1319
mod compute_wdffunctions_symbol_name {
1336
1320
use super :: * ;
1337
1321
use crate :: { KmdfConfig , UmdfConfig } ;
0 commit comments