@@ -135,7 +135,10 @@ fn get_boringssl_source_path(config: &Config) -> &PathBuf {
135135
136136 let _ = fs:: remove_dir_all ( & src_path) ;
137137 fs_extra:: dir:: copy ( submodule_path, & config. out_dir , & Default :: default ( ) )
138- . expect ( "out dir copy" ) ;
138+ . inspect_err ( |_| {
139+ let _ = fs:: remove_dir_all ( & config. out_dir ) ;
140+ } )
141+ . expect ( "copying failed. Try running `cargo clean`" ) ;
139142
140143 // NOTE: .git can be both file and dir, depening on whether it was copied from a submodule
141144 // or created by the patches code.
@@ -613,20 +616,33 @@ fn emit_link_directives(config: &Config) {
613616 }
614617}
615618
619+ fn check_include_path ( path : PathBuf ) -> Result < PathBuf , String > {
620+ if path. join ( "openssl" ) . join ( "x509v3.h" ) . exists ( ) {
621+ Ok ( path)
622+ } else {
623+ Err ( format ! (
624+ "Include path {} {}" ,
625+ path. display( ) ,
626+ if !path. exists( ) {
627+ "does not exist"
628+ } else {
629+ "does not have expected openssl/x509v3.h"
630+ }
631+ ) )
632+ }
633+ }
634+
616635fn generate_bindings ( config : & Config ) {
617636 let include_path = config. env . include_path . clone ( ) . unwrap_or_else ( || {
618637 if let Some ( bssl_path) = & config. env . path {
619- return bssl_path. join ( "include" ) ;
638+ return check_include_path ( bssl_path. join ( "include" ) )
639+ . expect ( "config has invalid include path" ) ;
620640 }
621641
622642 let src_path = get_boringssl_source_path ( config) ;
623- let candidate = src_path. join ( "include" ) ;
624-
625- if candidate. exists ( ) {
626- candidate
627- } else {
628- src_path. join ( "src" ) . join ( "include" )
629- }
643+ check_include_path ( src_path. join ( "include" ) )
644+ . or_else ( |_| check_include_path ( src_path. join ( "src" ) . join ( "include" ) ) )
645+ . expect ( "can't find usable include path" )
630646 } ) ;
631647
632648 let target_rust_version =
@@ -706,7 +722,14 @@ fn generate_bindings(config: &Config) {
706722 "x509v3.h" ,
707723 ] ;
708724 for header in & headers {
709- builder = builder. header ( include_path. join ( "openssl" ) . join ( header) . to_str ( ) . unwrap ( ) ) ;
725+ let header_path = include_path. join ( "openssl" ) . join ( header) ;
726+ assert ! (
727+ header_path. exists( ) ,
728+ "{} is missing. Is {} correct? run `cargo clean`" ,
729+ header_path. display( ) ,
730+ include_path. display( )
731+ ) ;
732+ builder = builder. header ( header_path. to_str ( ) . unwrap ( ) ) ;
710733 }
711734
712735 let bindings = builder. generate ( ) . expect ( "Unable to generate bindings" ) ;
0 commit comments