@@ -1435,8 +1435,8 @@ impl Builder {
1435
1435
self
1436
1436
}
1437
1437
1438
- /// Generate the Rust bindings using the options built up thus far.
1439
- pub fn generate ( mut self ) -> Result < Bindings , ( ) > {
1438
+ /// Generate the Rust bindings options
1439
+ pub fn generate_options ( & mut self ) -> & Self {
1440
1440
// Add any extra arguments from the environment to the clang command line.
1441
1441
if let Some ( extra_clang_args) =
1442
1442
get_target_dependent_env_var ( "BINDGEN_EXTRA_CLANG_ARGS" )
@@ -1451,7 +1451,7 @@ impl Builder {
1451
1451
1452
1452
// Transform input headers to arguments on the clang command line.
1453
1453
self . options . input_header = self . input_headers . pop ( ) ;
1454
- self . options . extra_input_headers = self . input_headers ;
1454
+ self . options . extra_input_headers = self . input_headers . to_vec ( ) ;
1455
1455
self . options . clang_args . extend (
1456
1456
self . options . extra_input_headers . iter ( ) . flat_map ( |header| {
1457
1457
iter:: once ( "-include" . into ( ) )
@@ -1466,7 +1466,12 @@ impl Builder {
1466
1466
clang:: UnsavedFile :: new ( & name, & contents)
1467
1467
} ) ,
1468
1468
) ;
1469
+ self
1470
+ }
1469
1471
1472
+ /// Generate the Rust bindings using the options built up thus far.
1473
+ pub fn generate ( mut self ) -> Result < Bindings , ( ) > {
1474
+ self . generate_options ( ) ;
1470
1475
Bindings :: generate ( self . options )
1471
1476
}
1472
1477
@@ -1475,7 +1480,7 @@ impl Builder {
1475
1480
/// This is useful when debugging bindgen, using C-Reduce, or when filing
1476
1481
/// issues. The resulting file will be named something like `__bindgen.i` or
1477
1482
/// `__bindgen.ii`
1478
- pub fn dump_preprocessed_input ( & self ) -> io:: Result < ( ) > {
1483
+ pub fn dump_preprocessed_input ( & mut self ) -> io:: Result < ( ) > {
1479
1484
let clang =
1480
1485
clang_sys:: support:: Clang :: find ( None , & [ ] ) . ok_or_else ( || {
1481
1486
io:: Error :: new (
@@ -1543,6 +1548,7 @@ impl Builder {
1543
1548
"__bindgen.i"
1544
1549
} ) ?;
1545
1550
io:: copy ( & mut preprocessed, & mut file) ?;
1551
+ self . generate_options ( ) ;
1546
1552
1547
1553
if child. wait ( ) ?. success ( ) {
1548
1554
Ok ( ( ) )
@@ -2189,39 +2195,8 @@ fn find_effective_target(clang_args: &[String]) -> (String, bool) {
2189
2195
}
2190
2196
2191
2197
impl Bindings {
2192
- /// Generate bindings for the given options.
2193
- pub ( crate ) fn generate (
2194
- mut options : BindgenOptions ,
2195
- ) -> Result < Bindings , ( ) > {
2196
- ensure_libclang_is_loaded ( ) ;
2197
-
2198
- #[ cfg( feature = "runtime" ) ]
2199
- debug ! (
2200
- "Generating bindings, libclang at {}" ,
2201
- clang_sys:: get_library( ) . unwrap( ) . path( ) . display( )
2202
- ) ;
2203
- #[ cfg( not( feature = "runtime" ) ) ]
2204
- debug ! ( "Generating bindings, libclang linked" ) ;
2205
-
2206
- options. build ( ) ;
2207
-
2208
- let ( effective_target, explicit_target) =
2209
- find_effective_target ( & options. clang_args ) ;
2210
-
2211
- let is_host_build =
2212
- rust_to_clang_target ( HOST_TARGET ) == effective_target;
2213
-
2214
- // NOTE: The is_host_build check wouldn't be sound normally in some
2215
- // cases if we were to call a binary (if you have a 32-bit clang and are
2216
- // building on a 64-bit system for example). But since we rely on
2217
- // opening libclang.so, it has to be the same architecture and thus the
2218
- // check is fine.
2219
- if !explicit_target && !is_host_build {
2220
- options
2221
- . clang_args
2222
- . insert ( 0 , format ! ( "--target={}" , effective_target) ) ;
2223
- } ;
2224
-
2198
+ /// Common part of generate()
2199
+ fn generate_common ( options : & mut BindgenOptions ) {
2225
2200
fn detect_include_paths ( options : & mut BindgenOptions ) {
2226
2201
if !options. detect_include_paths {
2227
2202
return ;
@@ -2298,8 +2273,43 @@ impl Bindings {
2298
2273
}
2299
2274
}
2300
2275
}
2276
+ detect_include_paths ( options) ;
2277
+ }
2278
+
2279
+ /// Generate bindings for the given options.
2280
+ pub ( crate ) fn generate (
2281
+ mut options : BindgenOptions ,
2282
+ ) -> Result < Bindings , ( ) > {
2283
+ ensure_libclang_is_loaded ( ) ;
2284
+
2285
+ #[ cfg( feature = "runtime" ) ]
2286
+ debug ! (
2287
+ "Generating bindings, libclang at {}" ,
2288
+ clang_sys:: get_library( ) . unwrap( ) . path( ) . display( )
2289
+ ) ;
2290
+ #[ cfg( not( feature = "runtime" ) ) ]
2291
+ debug ! ( "Generating bindings, libclang linked" ) ;
2292
+
2293
+ options. build ( ) ;
2294
+
2295
+ let ( effective_target, explicit_target) =
2296
+ find_effective_target ( & options. clang_args ) ;
2297
+
2298
+ let is_host_build =
2299
+ rust_to_clang_target ( HOST_TARGET ) == effective_target;
2300
+
2301
+ // NOTE: The is_host_build check wouldn't be sound normally in some
2302
+ // cases if we were to call a binary (if you have a 32-bit clang and are
2303
+ // building on a 64-bit system for example). But since we rely on
2304
+ // opening libclang.so, it has to be the same architecture and thus the
2305
+ // check is fine.
2306
+ if !explicit_target && !is_host_build {
2307
+ options
2308
+ . clang_args
2309
+ . insert ( 0 , format ! ( "--target={}" , effective_target) ) ;
2310
+ } ;
2301
2311
2302
- detect_include_paths ( & mut options) ;
2312
+ Bindings :: generate_common ( & mut options) ;
2303
2313
2304
2314
#[ cfg( unix) ]
2305
2315
fn can_read ( perms : & std:: fs:: Permissions ) -> bool {
0 commit comments