@@ -2493,12 +2493,22 @@ pub fn generate_const_debugs(const_values: &BTreeMap<Ident, ConstantTypeInfo>) -
2493
2493
pub fn generate_aliases_of_types (
2494
2494
types : & vk_parse:: Types ,
2495
2495
ty_cache : & mut HashSet < Ident , impl BuildHasher > ,
2496
+ include_headers : & mut Vec < String > ,
2496
2497
) -> TokenStream {
2497
2498
let aliases = types
2498
2499
. children
2499
2500
. iter ( )
2500
2501
. filter_map ( |child| match child {
2501
- vk_parse:: TypesChild :: Type ( ty) => Some ( ( ty. name . as_ref ( ) ?, ty. alias . as_ref ( ) ?) ) ,
2502
+ vk_parse:: TypesChild :: Type ( ty) => {
2503
+ if ty. category . as_deref ( ) == Some ( "include" ) {
2504
+ include_headers. push (
2505
+ ty. name
2506
+ . clone ( )
2507
+ . expect ( "Include type must provide header name" ) ,
2508
+ ) ;
2509
+ }
2510
+ Some ( ( ty. name . as_ref ( ) ?, ty. alias . as_ref ( ) ?) )
2511
+ }
2502
2512
_ => None ,
2503
2513
} )
2504
2514
. filter_map ( |( name, alias) | {
@@ -2516,10 +2526,11 @@ pub fn generate_aliases_of_types(
2516
2526
#( #aliases) *
2517
2527
}
2518
2528
}
2519
- pub fn write_source_code < P : AsRef < Path > > ( vk_xml : & Path , src_dir : P ) {
2529
+ pub fn write_source_code < P : AsRef < Path > > ( vk_headers_dir : & Path , src_dir : P ) {
2530
+ let vk_xml = vk_headers_dir. join ( "registry/vk.xml" ) ;
2520
2531
use std:: fs:: File ;
2521
2532
use std:: io:: Write ;
2522
- let ( spec2, _errors) = vk_parse:: parse_file ( vk_xml) . expect ( "Invalid xml file" ) ;
2533
+ let ( spec2, _errors) = vk_parse:: parse_file ( & vk_xml) . expect ( "Invalid xml file" ) ;
2523
2534
let extensions: & Vec < vk_parse:: Extension > = spec2
2524
2535
. 0
2525
2536
. iter ( )
@@ -2530,18 +2541,21 @@ pub fn write_source_code<P: AsRef<Path>>(vk_xml: &Path, src_dir: P) {
2530
2541
. next ( )
2531
2542
. expect ( "extension" ) ;
2532
2543
let mut ty_cache = HashSet :: new ( ) ;
2544
+ let mut header_includes = vec ! [ ] ;
2533
2545
let aliases: Vec < _ > = spec2
2534
2546
. 0
2535
2547
. iter ( )
2536
2548
. filter_map ( |item| match item {
2537
- vk_parse:: RegistryChild :: Types ( ref ty) => {
2538
- Some ( generate_aliases_of_types ( ty, & mut ty_cache) )
2539
- }
2549
+ vk_parse:: RegistryChild :: Types ( ref ty) => Some ( generate_aliases_of_types (
2550
+ ty,
2551
+ & mut ty_cache,
2552
+ & mut header_includes,
2553
+ ) ) ,
2540
2554
_ => None ,
2541
2555
} )
2542
2556
. collect ( ) ;
2543
2557
2544
- let spec = vk_parse:: parse_file_as_vkxml ( vk_xml) . expect ( "Invalid xml file." ) ;
2558
+ let spec = vk_parse:: parse_file_as_vkxml ( & vk_xml) . expect ( "Invalid xml file." ) ;
2545
2559
let cmd_aliases: HashMap < String , String > = spec2
2546
2560
. 0
2547
2561
. iter ( )
@@ -2745,6 +2759,7 @@ pub fn write_source_code<P: AsRef<Path>>(vk_xml: &Path, src_dir: P) {
2745
2759
use crate :: vk:: bitflags:: * ;
2746
2760
use crate :: vk:: constants:: * ;
2747
2761
use crate :: vk:: enums:: * ;
2762
+ use crate :: vk:: video:: * ;
2748
2763
#( #definition_code) *
2749
2764
} ;
2750
2765
@@ -2824,6 +2839,8 @@ pub fn write_source_code<P: AsRef<Path>>(vk_xml: &Path, src_dir: P) {
2824
2839
pub use features:: * ;
2825
2840
mod platform_types;
2826
2841
pub use platform_types:: * ;
2842
+ #[ allow( nonstandard_style, dead_code, clippy:: redundant_static_lifetimes) ]
2843
+ pub mod video;
2827
2844
2828
2845
#ptr_chain_code
2829
2846
@@ -2854,4 +2871,25 @@ pub fn write_source_code<P: AsRef<Path>>(vk_xml: &Path, src_dir: P) {
2854
2871
write ! ( & mut vk_aliases_file, "{}" , aliases) . expect ( "Unable to write vk/aliases.rs" ) ;
2855
2872
write ! ( & mut vk_rs_file, "{} {}" , vk_rs_clippy_lints, vk_rs_code)
2856
2873
. expect ( "Unable to write vk.rs" ) ;
2874
+
2875
+ let vk_include = vk_headers_dir. join ( "include" ) ;
2876
+
2877
+ let mut bindings = bindgen:: Builder :: default ( )
2878
+ . clang_arg ( format ! (
2879
+ "-I{}" ,
2880
+ vk_include. to_str( ) . expect( "Valid UTF8 string" )
2881
+ ) )
2882
+ . header ( "stdint.h" ) ;
2883
+
2884
+ for h in header_includes {
2885
+ if h. starts_with ( "vk_video" ) {
2886
+ bindings = bindings. header ( vk_include. join ( h) . to_str ( ) . expect ( "Valid UTF8 string" ) ) ;
2887
+ }
2888
+ }
2889
+
2890
+ bindings
2891
+ . generate ( )
2892
+ . expect ( "Unable to generate bindings" )
2893
+ . write_to_file ( vk_dir. join ( "video.rs" ) )
2894
+ . expect ( "Couldn't write bindings!" ) ;
2857
2895
}
0 commit comments