@@ -76,16 +76,20 @@ fn find_capstone_header(header_search_paths: &Vec<PathBuf>, name: &str) -> Optio
7676
7777/// Create bindings using bindgen
7878fn write_bindgen_bindings ( header_search_paths : & Vec < PathBuf > , update_pregenerated_bindings : bool ) {
79- debug_println ! ( "Writing bindgen bindings with search paths {:?}" ,
80- header_search_paths) ;
79+ debug_println ! (
80+ "Writing bindgen bindings with search paths {:?}" ,
81+ header_search_paths
82+ ) ;
8183
8284
8385 let mut builder = bindgen:: Builder :: default ( )
8486 . unstable_rust ( false )
85- . header ( find_capstone_header ( header_search_paths, "capstone.h" )
86- . expect ( "Could not find header" )
87- . to_str ( )
88- . unwrap ( ) )
87+ . header (
88+ find_capstone_header ( header_search_paths, "capstone.h" )
89+ . expect ( "Could not find header" )
90+ . to_str ( )
91+ . unwrap ( ) ,
92+ )
8993 . disable_name_namespacing ( )
9094 . prepend_enum_name ( false )
9195 . generate_comments ( true )
@@ -108,17 +112,23 @@ fn write_bindgen_bindings(header_search_paths: &Vec<PathBuf>, update_pregenerate
108112
109113 // Write bindings to $OUT_DIR/bindings.rs
110114 let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( BINDINGS_FILE ) ;
111- bindings
112- . write_to_file ( out_path. clone ( ) )
113- . expect ( "Unable to write bindings" ) ;
114-
115- if update_pregenerated_bindings {
116- let stored_bindgen_header: PathBuf = [
117- env:: var ( "CARGO_MANIFEST_DIR" ) . expect ( "Could not find cargo environment variable" ) ,
118- "pre_generated" . into ( ) ,
119- BINDINGS_FILE . into ( )
120- ] . iter ( ) . collect ( ) ;
121- debug_println ! ( "Updating capstone bindings at \" {}\" " , stored_bindgen_header. to_str( ) . unwrap( ) ) ;
115+ bindings. write_to_file ( out_path. clone ( ) ) . expect (
116+ "Unable to write bindings" ,
117+ ) ;
118+
119+ if update_pregenerated_bindings {
120+ debug_println ! ( "Updating pre-generated capstone bindings" ) ;
121+ let stored_bindgen_header: PathBuf =
122+ [
123+ env:: var ( "CARGO_MANIFEST_DIR" ) . expect ( "Could not find cargo environment variable" ) ,
124+ "pre_generated" . into ( ) ,
125+ BINDINGS_FILE . into ( ) ,
126+ ] . iter ( )
127+ . collect ( ) ;
128+ debug_println ! (
129+ "Updating capstone bindings at \" {}\" " ,
130+ stored_bindgen_header. to_str( ) . unwrap( )
131+ ) ;
122132 copy ( out_path, stored_bindgen_header) . expect ( "Unable to update capstone bindings" ) ;
123133 }
124134}
@@ -132,8 +142,10 @@ fn main() {
132142 if cfg ! ( feature = "use_system_capstone" ) {
133143 debug_println ! ( "Using system capstone library" ) ;
134144
135- assert ! ( !cfg!( feature = "build_capstone_cmake" ) ,
136- "build_capstone_cmake feature is only valid when using bundled cmake" ) ;
145+ assert ! (
146+ !cfg!( feature = "build_capstone_cmake" ) ,
147+ "build_capstone_cmake feature is only valid when using bundled cmake"
148+ ) ;
137149
138150 let capstone_lib =
139151 pkg_config:: find_library ( "capstone" ) . expect ( "Could not find system capstone" ) ;
@@ -178,11 +190,15 @@ fn main() {
178190 // If UPDATE_CAPSTONE_BINDINGS is set, then updated the pre-generated capstone bindings
179191 let update_pregenerated_bindings = env:: var ( "UPDATE_CAPSTONE_BINDINGS" ) . is_ok ( ) ;
180192 if update_pregenerated_bindings {
181- assert ! ( cfg!( feature = "use_bundled_capstone_bindings" ) ,
182- concat!( "Setting UPDATE_CAPSTONE_BINDINGS only makes " ,
183- "sense when NOT enabling feature use_bundled_capstone_bindings" ) ) ;
184- } else {
185- debug_println ! ( "Creating capstone bindings with bindgen" ) ;
186- write_bindgen_bindings ( & header_search_paths, update_pregenerated_bindings) ;
193+ assert ! (
194+ !cfg!( feature = "use_bundled_capstone_bindings" ) ,
195+ concat!(
196+ "Setting UPDATE_CAPSTONE_BINDINGS only makes " ,
197+ "sense when NOT enabling feature use_bundled_capstone_bindings"
198+ )
199+ ) ;
187200 }
201+
202+ debug_println ! ( "Creating capstone bindings with bindgen" ) ;
203+ write_bindgen_bindings ( & header_search_paths, update_pregenerated_bindings) ;
188204}
0 commit comments