@@ -1492,29 +1492,8 @@ impl Builder {
1492
1492
}
1493
1493
1494
1494
/// Generate the Rust bindings using the options built up thus far.
1495
- pub fn generate ( mut self ) -> Result < Bindings , BindgenError > {
1496
- let mut state = BindgenState :: build ( & self . options ) ;
1497
- state. parse_callbacks = self . parse_callbacks ;
1498
-
1499
- // Add any extra arguments from the environment to the clang command line.
1500
- state. clang_args . extend ( get_extra_clang_args ( ) ) ;
1501
-
1502
- // Transform input headers to arguments on the clang command line.
1503
- state. input_header = self . options . input_headers . pop ( ) ;
1504
- state. extra_input_headers =
1505
- std:: mem:: take ( & mut self . options . input_headers ) ;
1506
- state. clang_args . extend (
1507
- state
1508
- . extra_input_headers
1509
- . iter ( )
1510
- . flat_map ( |header| [ "-include" . into ( ) , header. to_string ( ) ] ) ,
1511
- ) ;
1512
-
1513
- state. input_unsaved_files . extend (
1514
- self . options . input_header_contents . drain ( ..) . map (
1515
- |( name, contents) | clang:: UnsavedFile :: new ( & name, & contents) ,
1516
- ) ,
1517
- ) ;
1495
+ pub fn generate ( self ) -> Result < Bindings , BindgenError > {
1496
+ let state = BindgenState :: build ( & self . options , self . parse_callbacks ) ;
1518
1497
1519
1498
Bindings :: generate ( state, self . options )
1520
1499
}
@@ -2245,7 +2224,37 @@ struct BindgenState {
2245
2224
impl :: std:: panic:: UnwindSafe for BindgenState { }
2246
2225
2247
2226
impl BindgenState {
2248
- fn build ( options : & BindgenOptions ) -> Self {
2227
+ fn build (
2228
+ options : & BindgenOptions ,
2229
+ parse_callbacks : Option < Box < dyn callbacks:: ParseCallbacks > > ,
2230
+ ) -> Self {
2231
+ let mut clang_args = options. clang_args . clone ( ) ;
2232
+
2233
+ // Add any extra arguments from the environment to the clang command line.
2234
+ clang_args. extend ( get_extra_clang_args ( ) ) ;
2235
+
2236
+ // Transform input headers to arguments on the clang command line.
2237
+ let ( input_header, extra_input_headers) =
2238
+ if let Some ( ( input_header, extra_input_headers) ) =
2239
+ options. input_headers . split_last ( )
2240
+ {
2241
+ ( Some ( input_header. clone ( ) ) , extra_input_headers. to_vec ( ) )
2242
+ } else {
2243
+ Default :: default ( )
2244
+ } ;
2245
+
2246
+ clang_args. extend (
2247
+ extra_input_headers
2248
+ . iter ( )
2249
+ . flat_map ( |header| [ "-include" . into ( ) , header. to_string ( ) ] ) ,
2250
+ ) ;
2251
+
2252
+ let input_unsaved_files = options
2253
+ . input_header_contents
2254
+ . iter ( )
2255
+ . map ( |( name, contents) | clang:: UnsavedFile :: new ( & name, & contents) )
2256
+ . collect ( ) ;
2257
+
2249
2258
Self {
2250
2259
allowlisted_vars : RegexSet :: new (
2251
2260
options. allowlisted_vars . clone ( ) ,
@@ -2343,11 +2352,11 @@ impl BindgenState {
2343
2352
options. must_use_types . clone ( ) ,
2344
2353
options. record_matches ,
2345
2354
) ,
2346
- clang_args : options . clang_args . clone ( ) ,
2347
- input_header : Default :: default ( ) ,
2348
- extra_input_headers : Default :: default ( ) ,
2349
- input_unsaved_files : Default :: default ( ) ,
2350
- parse_callbacks : Default :: default ( ) ,
2355
+ clang_args,
2356
+ input_header,
2357
+ extra_input_headers,
2358
+ input_unsaved_files,
2359
+ parse_callbacks,
2351
2360
}
2352
2361
}
2353
2362
}
0 commit comments