@@ -36,6 +36,13 @@ macro_rules! add_msvc_includes_to_bindings {
36
36
} ;
37
37
}
38
38
39
+ fn get_bundled_header_path ( ) -> PathBuf {
40
+ let mut include_path: PathBuf = PathBuf :: from ( env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
41
+ include_path. push ( format ! ( "SDL2-{}" , SDL2_HEADERS_BUNDLED_VERSION ) ) ;
42
+ include_path. push ( "include" ) ;
43
+ include_path
44
+ }
45
+
39
46
#[ cfg( feature = "bundled" ) ]
40
47
fn run_command ( cmd : & str , args : & [ & str ] ) {
41
48
use std:: process:: Command ;
@@ -468,8 +475,12 @@ fn main() {
468
475
469
476
#[ cfg( feature = "bindgen" ) ] {
470
477
let include_paths = vec ! ( String :: from( sdl2_downloaded_include_path. to_str( ) . unwrap( ) ) ) ;
478
+ println ! ( "cargo:include={}" , include_paths. join( ":" ) ) ;
471
479
generate_bindings ( target. as_str ( ) , host. as_str ( ) , include_paths. as_slice ( ) )
472
480
}
481
+ #[ cfg( not( feature = "bindgen" ) ) ] {
482
+ println ! ( "cargo:include={}" , sdl2_downloaded_include_path. display( ) ) ;
483
+ }
473
484
} ;
474
485
475
486
#[ cfg( all( not( feature = "bundled" ) , feature = "bindgen" ) ) ] {
@@ -479,6 +490,7 @@ fn main() {
479
490
480
491
#[ cfg( not( feature = "bindgen" ) ) ] {
481
492
copy_pregenerated_bindings ( ) ;
493
+ println ! ( "cargo:include={}" , get_bundled_header_path( ) . display( ) ) ;
482
494
}
483
495
484
496
link_sdl2 ( target_os) ;
@@ -526,7 +538,7 @@ fn copy_pregenerated_bindings() {
526
538
#[ cfg( feature = "bindgen" ) ]
527
539
// headers_path is a list of directories where the SDL2 headers are expected
528
540
// to be found by bindgen (should point to the include/ directories)
529
- fn generate_bindings < S : AsRef < str > + :: std :: fmt :: Debug > ( target : & str , host : & str , headers_paths : & [ S ] ) {
541
+ fn generate_bindings ( target : & str , host : & str , headers_paths : & [ String ] ) {
530
542
let target_os = get_os_from_triple ( target) . unwrap ( ) ;
531
543
let mut bindings = bindgen:: Builder :: default ( )
532
544
// enable no_std-friendly output by only using core definitions
@@ -600,9 +612,9 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
600
612
601
613
if headers_paths. len ( ) == 0 {
602
614
// if no paths are being provided, fall back to the headers included in this repo
603
- let mut include_path: PathBuf = PathBuf :: from ( env :: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
604
- include_path . push ( format ! ( "SDL2- {}" , SDL2_HEADERS_BUNDLED_VERSION ) ) ;
605
- include_path . push ( "include" ) ;
615
+ let include_path = get_bundled_header_path ( ) ;
616
+ println ! ( "cargo:include= {}" , include_path . display ( ) ) ;
617
+
606
618
bindings = bindings. clang_arg ( format ! ( "-I{}" , include_path. display( ) ) ) ;
607
619
if cfg ! ( feature = "image" ) {
608
620
image_bindings = image_bindings. clang_arg ( format ! ( "-I{}" , include_path. display( ) ) ) ;
@@ -621,22 +633,23 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
621
633
}
622
634
} else {
623
635
// if paths are included, use them for bindgen. Bindgen should use the first one.
636
+ println ! ( "cargo:include={}" , headers_paths. join( ":" ) ) ;
624
637
for headers_path in headers_paths {
625
- bindings = bindings. clang_arg ( format ! ( "-I{}" , headers_path. as_ref ( ) ) ) ;
638
+ bindings = bindings. clang_arg ( format ! ( "-I{}" , headers_path) ) ;
626
639
if cfg ! ( feature = "image" ) {
627
- image_bindings = image_bindings. clang_arg ( format ! ( "-I{}" , headers_path. as_ref ( ) ) ) ;
640
+ image_bindings = image_bindings. clang_arg ( format ! ( "-I{}" , headers_path) ) ;
628
641
}
629
642
if cfg ! ( feature = "ttf" ) {
630
- ttf_bindings = ttf_bindings. clang_arg ( format ! ( "-I{}" , headers_path. as_ref ( ) ) ) ;
643
+ ttf_bindings = ttf_bindings. clang_arg ( format ! ( "-I{}" , headers_path) ) ;
631
644
}
632
645
if cfg ! ( feature = "mixer" ) {
633
- mixer_bindings = mixer_bindings. clang_arg ( format ! ( "-I{}" , headers_path. as_ref ( ) ) ) ;
646
+ mixer_bindings = mixer_bindings. clang_arg ( format ! ( "-I{}" , headers_path) ) ;
634
647
}
635
648
if cfg ! ( feature = "gfx" ) {
636
- gfx_framerate_bindings = gfx_framerate_bindings. clang_arg ( format ! ( "-I{}" , headers_path. as_ref ( ) ) ) ;
637
- gfx_primitives_bindings = gfx_primitives_bindings. clang_arg ( format ! ( "-I{}" , headers_path. as_ref ( ) ) ) ;
638
- gfx_imagefilter_bindings = gfx_imagefilter_bindings. clang_arg ( format ! ( "-I{}" , headers_path. as_ref ( ) ) ) ;
639
- gfx_rotozoom_bindings = gfx_rotozoom_bindings. clang_arg ( format ! ( "-I{}" , headers_path. as_ref ( ) ) ) ;
649
+ gfx_framerate_bindings = gfx_framerate_bindings. clang_arg ( format ! ( "-I{}" , headers_path) ) ;
650
+ gfx_primitives_bindings = gfx_primitives_bindings. clang_arg ( format ! ( "-I{}" , headers_path) ) ;
651
+ gfx_imagefilter_bindings = gfx_imagefilter_bindings. clang_arg ( format ! ( "-I{}" , headers_path) ) ;
652
+ gfx_rotozoom_bindings = gfx_rotozoom_bindings. clang_arg ( format ! ( "-I{}" , headers_path) ) ;
640
653
}
641
654
}
642
655
}
0 commit comments