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