@@ -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
}
@@ -2240,7 +2219,37 @@ struct BindgenState {
2240
2219
impl :: std:: panic:: UnwindSafe for BindgenState { }
2241
2220
2242
2221
impl BindgenState {
2243
- fn build ( options : & BindgenOptions ) -> Self {
2222
+ fn build (
2223
+ options : & BindgenOptions ,
2224
+ parse_callbacks : Option < Box < dyn callbacks:: ParseCallbacks > > ,
2225
+ ) -> Self {
2226
+ let mut clang_args = options. clang_args . clone ( ) ;
2227
+
2228
+ // Add any extra arguments from the environment to the clang command line.
2229
+ clang_args. extend ( get_extra_clang_args ( ) ) ;
2230
+
2231
+ // Transform input headers to arguments on the clang command line.
2232
+ let ( input_header, extra_input_headers) =
2233
+ if let Some ( ( input_header, extra_input_headers) ) =
2234
+ options. input_headers . split_last ( )
2235
+ {
2236
+ ( Some ( input_header. clone ( ) ) , extra_input_headers. to_vec ( ) )
2237
+ } else {
2238
+ Default :: default ( )
2239
+ } ;
2240
+
2241
+ clang_args. extend (
2242
+ extra_input_headers
2243
+ . iter ( )
2244
+ . flat_map ( |header| [ "-include" . into ( ) , header. to_string ( ) ] ) ,
2245
+ ) ;
2246
+
2247
+ let input_unsaved_files = options
2248
+ . input_header_contents
2249
+ . iter ( )
2250
+ . map ( |( name, contents) | clang:: UnsavedFile :: new ( & name, & contents) )
2251
+ . collect ( ) ;
2252
+
2244
2253
Self {
2245
2254
allowlisted_vars : RegexSet :: new (
2246
2255
options. allowlisted_vars . clone ( ) ,
@@ -2338,11 +2347,11 @@ impl BindgenState {
2338
2347
options. must_use_types . clone ( ) ,
2339
2348
options. record_matches ,
2340
2349
) ,
2341
- clang_args : options . clang_args . clone ( ) ,
2342
- input_header : Default :: default ( ) ,
2343
- extra_input_headers : Default :: default ( ) ,
2344
- input_unsaved_files : Default :: default ( ) ,
2345
- parse_callbacks : Default :: default ( ) ,
2350
+ clang_args,
2351
+ input_header,
2352
+ extra_input_headers,
2353
+ input_unsaved_files,
2354
+ parse_callbacks,
2346
2355
}
2347
2356
}
2348
2357
}
0 commit comments