@@ -1512,29 +1512,8 @@ impl Builder {
1512
1512
}
1513
1513
1514
1514
/// Generate the Rust bindings using the options built up thus far.
1515
- pub fn generate ( mut self ) -> Result < Bindings , BindgenError > {
1516
- let mut state = BindgenState :: build ( & self . options ) ;
1517
- state. parse_callbacks = self . parse_callbacks ;
1518
-
1519
- // Add any extra arguments from the environment to the clang command line.
1520
- state. clang_args . extend ( get_extra_clang_args ( ) ) ;
1521
-
1522
- // Transform input headers to arguments on the clang command line.
1523
- state. input_header = self . options . input_headers . pop ( ) ;
1524
- state. extra_input_headers =
1525
- std:: mem:: take ( & mut self . options . input_headers ) ;
1526
- state. clang_args . extend (
1527
- state
1528
- . extra_input_headers
1529
- . iter ( )
1530
- . flat_map ( |header| [ "-include" . into ( ) , header. to_string ( ) ] ) ,
1531
- ) ;
1532
-
1533
- state. input_unsaved_files . extend (
1534
- self . options . input_header_contents . drain ( ..) . map (
1535
- |( name, contents) | clang:: UnsavedFile :: new ( & name, & contents) ,
1536
- ) ,
1537
- ) ;
1515
+ pub fn generate ( self ) -> Result < Bindings , BindgenError > {
1516
+ let state = BindgenState :: build ( & self . options , self . parse_callbacks ) ;
1538
1517
1539
1518
Bindings :: generate ( state, self . options )
1540
1519
}
@@ -2272,7 +2251,37 @@ struct BindgenState {
2272
2251
impl :: std:: panic:: UnwindSafe for BindgenState { }
2273
2252
2274
2253
impl BindgenState {
2275
- fn build ( options : & BindgenOptions ) -> Self {
2254
+ fn build (
2255
+ options : & BindgenOptions ,
2256
+ parse_callbacks : Option < Box < dyn callbacks:: ParseCallbacks > > ,
2257
+ ) -> Self {
2258
+ let mut clang_args = options. clang_args . clone ( ) ;
2259
+
2260
+ // Add any extra arguments from the environment to the clang command line.
2261
+ clang_args. extend ( get_extra_clang_args ( ) ) ;
2262
+
2263
+ // Transform input headers to arguments on the clang command line.
2264
+ let ( input_header, extra_input_headers) =
2265
+ if let Some ( ( input_header, extra_input_headers) ) =
2266
+ options. input_headers . split_last ( )
2267
+ {
2268
+ ( Some ( input_header. clone ( ) ) , extra_input_headers. to_vec ( ) )
2269
+ } else {
2270
+ Default :: default ( )
2271
+ } ;
2272
+
2273
+ clang_args. extend (
2274
+ extra_input_headers
2275
+ . iter ( )
2276
+ . flat_map ( |header| [ "-include" . into ( ) , header. to_string ( ) ] ) ,
2277
+ ) ;
2278
+
2279
+ let input_unsaved_files = options
2280
+ . input_header_contents
2281
+ . iter ( )
2282
+ . map ( |( name, contents) | clang:: UnsavedFile :: new ( & name, & contents) )
2283
+ . collect ( ) ;
2284
+
2276
2285
Self {
2277
2286
allowlisted_vars : RegexSet :: new (
2278
2287
options. allowlisted_vars . clone ( ) ,
@@ -2374,11 +2383,11 @@ impl BindgenState {
2374
2383
options. must_use_types . clone ( ) ,
2375
2384
options. record_matches ,
2376
2385
) ,
2377
- clang_args : options . clang_args . clone ( ) ,
2378
- input_header : Default :: default ( ) ,
2379
- extra_input_headers : Default :: default ( ) ,
2380
- input_unsaved_files : Default :: default ( ) ,
2381
- parse_callbacks : Default :: default ( ) ,
2386
+ clang_args,
2387
+ input_header,
2388
+ extra_input_headers,
2389
+ input_unsaved_files,
2390
+ parse_callbacks,
2382
2391
}
2383
2392
}
2384
2393
}
0 commit comments