@@ -1335,8 +1335,8 @@ impl Builder {
1335
1335
self
1336
1336
}
1337
1337
1338
- /// Generate the Rust bindings using the options built up thus far.
1339
- pub fn generate ( mut self ) -> Result < Bindings , ( ) > {
1338
+ /// Generate the Rust bindings options
1339
+ pub fn generate_options ( mut self ) -> Self {
1340
1340
// Add any extra arguments from the environment to the clang command line.
1341
1341
if let Some ( extra_clang_args) =
1342
1342
env:: var ( "BINDGEN_EXTRA_CLANG_ARGS" ) . ok ( )
@@ -1364,24 +1364,28 @@ impl Builder {
1364
1364
clang:: UnsavedFile :: new ( & name, & contents)
1365
1365
} ) ,
1366
1366
) ;
1367
+ self
1368
+ }
1367
1369
1368
- Bindings :: generate ( self . options )
1370
+ /// Generate the Rust bindings using the options built up thus far.
1371
+ pub fn generate ( self ) -> Result < Bindings , ( ) > {
1372
+ Bindings :: generate ( Builder :: generate_options ( self ) . options )
1369
1373
}
1370
1374
1371
1375
/// Preprocess and dump the input header files to disk.
1372
1376
///
1373
1377
/// This is useful when debugging bindgen, using C-Reduce, or when filing
1374
1378
/// issues. The resulting file will be named something like `__bindgen.i` or
1375
1379
/// `__bindgen.ii`
1376
- pub fn dump_preprocessed_input ( & self ) -> io:: Result < ( ) > {
1380
+ pub fn dump_preprocessed_input ( & mut self ) -> io:: Result < ( ) > {
1377
1381
let clang =
1378
1382
clang_sys:: support:: Clang :: find ( None , & [ ] ) . ok_or_else ( || {
1379
1383
io:: Error :: new (
1380
1384
io:: ErrorKind :: Other ,
1381
1385
"Cannot find clang executable" ,
1382
1386
)
1383
1387
} ) ?;
1384
-
1388
+ // Builder::generate_options(self);
1385
1389
// The contents of a wrapper file that includes all the input header
1386
1390
// files.
1387
1391
let mut wrapper_contents = String :: new ( ) ;
@@ -2011,39 +2015,8 @@ fn find_effective_target(clang_args: &[String]) -> (String, bool) {
2011
2015
}
2012
2016
2013
2017
impl Bindings {
2014
- /// Generate bindings for the given options.
2015
- pub ( crate ) fn generate (
2016
- mut options : BindgenOptions ,
2017
- ) -> Result < Bindings , ( ) > {
2018
- ensure_libclang_is_loaded ( ) ;
2019
-
2020
- #[ cfg( feature = "runtime" ) ]
2021
- debug ! (
2022
- "Generating bindings, libclang at {}" ,
2023
- clang_sys:: get_library( ) . unwrap( ) . path( ) . display( )
2024
- ) ;
2025
- #[ cfg( not( feature = "runtime" ) ) ]
2026
- debug ! ( "Generating bindings, libclang linked" ) ;
2027
-
2028
- options. build ( ) ;
2029
-
2030
- let ( effective_target, explicit_target) =
2031
- find_effective_target ( & options. clang_args ) ;
2032
-
2033
- let is_host_build =
2034
- rust_to_clang_target ( HOST_TARGET ) == effective_target;
2035
-
2036
- // NOTE: The is_host_build check wouldn't be sound normally in some
2037
- // cases if we were to call a binary (if you have a 32-bit clang and are
2038
- // building on a 64-bit system for example). But since we rely on
2039
- // opening libclang.so, it has to be the same architecture and thus the
2040
- // check is fine.
2041
- if !explicit_target && !is_host_build {
2042
- options
2043
- . clang_args
2044
- . insert ( 0 , format ! ( "--target={}" , effective_target) ) ;
2045
- } ;
2046
-
2018
+ /// Common part of generate()
2019
+ fn generate_common ( options : & mut BindgenOptions ) {
2047
2020
fn detect_include_paths ( options : & mut BindgenOptions ) {
2048
2021
if !options. detect_include_paths {
2049
2022
return ;
@@ -2120,8 +2093,43 @@ impl Bindings {
2120
2093
}
2121
2094
}
2122
2095
}
2096
+ detect_include_paths ( options) ;
2097
+ }
2098
+
2099
+ /// Generate bindings for the given options.
2100
+ pub ( crate ) fn generate (
2101
+ mut options : BindgenOptions ,
2102
+ ) -> Result < Bindings , ( ) > {
2103
+ ensure_libclang_is_loaded ( ) ;
2104
+
2105
+ #[ cfg( feature = "runtime" ) ]
2106
+ debug ! (
2107
+ "Generating bindings, libclang at {}" ,
2108
+ clang_sys:: get_library( ) . unwrap( ) . path( ) . display( )
2109
+ ) ;
2110
+ #[ cfg( not( feature = "runtime" ) ) ]
2111
+ debug ! ( "Generating bindings, libclang linked" ) ;
2112
+
2113
+ options. build ( ) ;
2114
+
2115
+ let ( effective_target, explicit_target) =
2116
+ find_effective_target ( & options. clang_args ) ;
2117
+
2118
+ let is_host_build =
2119
+ rust_to_clang_target ( HOST_TARGET ) == effective_target;
2120
+
2121
+ // NOTE: The is_host_build check wouldn't be sound normally in some
2122
+ // cases if we were to call a binary (if you have a 32-bit clang and are
2123
+ // building on a 64-bit system for example). But since we rely on
2124
+ // opening libclang.so, it has to be the same architecture and thus the
2125
+ // check is fine.
2126
+ if !explicit_target && !is_host_build {
2127
+ options
2128
+ . clang_args
2129
+ . insert ( 0 , format ! ( "--target={}" , effective_target) ) ;
2130
+ } ;
2123
2131
2124
- detect_include_paths ( & mut options) ;
2132
+ Bindings :: generate_common ( & mut options) ;
2125
2133
2126
2134
#[ cfg( unix) ]
2127
2135
fn can_read ( perms : & std:: fs:: Permissions ) -> bool {
0 commit comments