@@ -225,7 +225,6 @@ impl Default for CodegenConfig {
225
225
pub struct Builder {
226
226
state : BindgenState ,
227
227
options : BindgenOptions ,
228
- input_headers : Vec < String > ,
229
228
// Tuples of unsaved file contents of the form (name, contents).
230
229
input_header_contents : Vec < ( String , String ) > ,
231
230
}
@@ -254,7 +253,7 @@ impl Builder {
254
253
pub fn command_line_flags ( & self ) -> Vec < String > {
255
254
let mut output_vector: Vec < String > = Vec :: new ( ) ;
256
255
257
- if let Some ( header) = self . input_headers . last ( ) . cloned ( ) {
256
+ if let Some ( header) = self . options . input_headers . last ( ) . cloned ( ) {
258
257
// Positional argument 'header'
259
258
output_vector. push ( header) ;
260
259
}
@@ -602,10 +601,10 @@ impl Builder {
602
601
output_vector. extend ( self . options . clang_args . iter ( ) . cloned ( ) ) ;
603
602
}
604
603
605
- if self . input_headers . len ( ) > 1 {
604
+ if self . options . input_headers . len ( ) > 1 {
606
605
// To pass more than one header, we need to pass all but the last
607
606
// header via the `-include` clang arg
608
- for header in & self . input_headers [ ..self . input_headers . len ( ) - 1 ] {
607
+ for header in & self . options . input_headers [ ..self . options . input_headers . len ( ) - 1 ] {
609
608
output_vector. push ( "-include" . to_string ( ) ) ;
610
609
output_vector. push ( header. clone ( ) ) ;
611
610
}
@@ -637,7 +636,7 @@ impl Builder {
637
636
/// .unwrap();
638
637
/// ```
639
638
pub fn header < T : Into < String > > ( mut self , header : T ) -> Builder {
640
- self . input_headers . push ( header. into ( ) ) ;
639
+ self . options . input_headers . push ( header. into ( ) ) ;
641
640
self
642
641
}
643
642
@@ -1533,13 +1532,13 @@ impl Builder {
1533
1532
/// Generate the Rust bindings using the options built up thus far.
1534
1533
pub fn generate ( mut self ) -> Result < Bindings , BindgenError > {
1535
1534
// Add any extra arguments from the environment to the clang command line.
1536
- self . options . clang_args . extend ( get_extra_clang_args ( ) ) ;
1535
+ self . state . clang_args . extend ( get_extra_clang_args ( ) ) ;
1537
1536
1538
1537
// Transform input headers to arguments on the clang command line.
1539
- self . options . input_header = self . input_headers . pop ( ) ;
1540
- self . options . extra_input_headers = self . input_headers ;
1541
- self . options . clang_args . extend (
1542
- self . options
1538
+ self . state . input_header = self . options . input_headers . pop ( ) ;
1539
+ self . state . extra_input_headers = std :: mem :: take ( & mut self . options . input_headers ) ;
1540
+ self . state . clang_args . extend (
1541
+ self . state
1543
1542
. extra_input_headers
1544
1543
. iter ( )
1545
1544
. flat_map ( |header| [ "-include" . into ( ) , header. to_string ( ) ] ) ,
@@ -1575,10 +1574,10 @@ impl Builder {
1575
1574
let mut wrapper_contents = String :: new ( ) ;
1576
1575
1577
1576
// Whether we are working with C or C++ inputs.
1578
- let mut is_cpp = args_are_cpp ( & self . options . clang_args ) ;
1577
+ let mut is_cpp = args_are_cpp ( & self . state . clang_args ) ;
1579
1578
1580
1579
// For each input header, add `#include "$header"`.
1581
- for header in & self . input_headers {
1580
+ for header in & self . options . input_headers {
1582
1581
is_cpp |= file_is_cpp ( header) ;
1583
1582
1584
1583
wrapper_contents. push_str ( "#include \" " ) ;
@@ -1616,7 +1615,7 @@ impl Builder {
1616
1615
. arg ( & wrapper_path)
1617
1616
. stdout ( Stdio :: piped ( ) ) ;
1618
1617
1619
- for a in & self . options . clang_args {
1618
+ for a in & self . state . clang_args {
1620
1619
cmd. arg ( a) ;
1621
1620
}
1622
1621
@@ -1938,11 +1937,8 @@ struct BindgenOptions {
1938
1937
/// The set of arguments to pass straight through to Clang.
1939
1938
clang_args : Vec < String > ,
1940
1939
1941
- /// The input header file.
1942
- input_header : Option < String > ,
1943
-
1944
- /// Any additional input header files.
1945
- extra_input_headers : Vec < String > ,
1940
+ /// The input header files.
1941
+ input_headers : Vec < String > ,
1946
1942
1947
1943
/// Which kind of items should we generate? By default, we'll generate all
1948
1944
/// of them.
@@ -2125,8 +2121,7 @@ impl Default for BindgenOptions {
2125
2121
raw_lines : Default :: default ( ) ,
2126
2122
module_lines : Default :: default ( ) ,
2127
2123
clang_args : Default :: default ( ) ,
2128
- input_header : Default :: default ( ) ,
2129
- extra_input_headers : Default :: default ( ) ,
2124
+ input_headers : Default :: default ( ) ,
2130
2125
codegen_config : CodegenConfig :: all ( ) ,
2131
2126
conservative_inline_namespaces : Default :: default ( ) ,
2132
2127
generate_comments : true ,
@@ -2251,6 +2246,15 @@ struct BindgenState {
2251
2246
/// The set of types that we should not derive `PartialEq` for.
2252
2247
no_partialeq_types : RegexSet ,
2253
2248
2249
+ /// The set of arguments to pass straight through to Clang.
2250
+ clang_args : Vec < String > ,
2251
+
2252
+ /// The input header file.
2253
+ input_header : Option < String > ,
2254
+
2255
+ /// Any additional input header files.
2256
+ extra_input_headers : Vec < String > ,
2257
+
2254
2258
/// The set of types that we should not derive `Copy` for.
2255
2259
no_copy_types : RegexSet ,
2256
2260
@@ -2281,6 +2285,8 @@ impl ::std::panic::UnwindSafe for BindgenState {}
2281
2285
2282
2286
impl BindgenState {
2283
2287
fn build ( & mut self , options : & BindgenOptions ) {
2288
+ self . clang_args . extend_from_slice ( & options. clang_args ) ;
2289
+
2284
2290
let mut regex_sets = [
2285
2291
( & mut self . allowlisted_vars , & options. allowlisted_vars ) ,
2286
2292
( & mut self . allowlisted_types , & options. allowlisted_types ) ,
@@ -2448,7 +2454,7 @@ impl Bindings {
2448
2454
/// Generate bindings for the given options.
2449
2455
pub ( crate ) fn generate (
2450
2456
mut state : BindgenState ,
2451
- mut options : BindgenOptions ,
2457
+ options : BindgenOptions ,
2452
2458
) -> Result < Self , BindgenError > {
2453
2459
ensure_libclang_is_loaded ( ) ;
2454
2460
@@ -2463,7 +2469,7 @@ impl Bindings {
2463
2469
state. build ( & options) ;
2464
2470
2465
2471
let ( effective_target, explicit_target) =
2466
- find_effective_target ( & options . clang_args ) ;
2472
+ find_effective_target ( & state . clang_args ) ;
2467
2473
2468
2474
let is_host_build =
2469
2475
rust_to_clang_target ( HOST_TARGET ) == effective_target;
@@ -2474,12 +2480,12 @@ impl Bindings {
2474
2480
// opening libclang.so, it has to be the same architecture and thus the
2475
2481
// check is fine.
2476
2482
if !explicit_target && !is_host_build {
2477
- options
2483
+ state
2478
2484
. clang_args
2479
2485
. insert ( 0 , format ! ( "--target={}" , effective_target) ) ;
2480
2486
} ;
2481
2487
2482
- fn detect_include_paths ( options : & mut BindgenOptions ) {
2488
+ fn detect_include_paths ( options : & BindgenOptions , state : & mut BindgenState ) {
2483
2489
if !options. detect_include_paths {
2484
2490
return ;
2485
2491
}
@@ -2488,7 +2494,7 @@ impl Bindings {
2488
2494
// promote them to `-isystem`.
2489
2495
let clang_args_for_clang_sys = {
2490
2496
let mut last_was_include_prefix = false ;
2491
- options
2497
+ state
2492
2498
. clang_args
2493
2499
. iter ( )
2494
2500
. filter ( |arg| {
@@ -2534,8 +2540,8 @@ impl Bindings {
2534
2540
debug ! ( "Found clang: {:?}" , clang) ;
2535
2541
2536
2542
// Whether we are working with C or C++ inputs.
2537
- let is_cpp = args_are_cpp ( & options . clang_args ) ||
2538
- options . input_header . as_deref ( ) . map_or ( false , file_is_cpp) ;
2543
+ let is_cpp = args_are_cpp ( & state . clang_args ) ||
2544
+ state . input_header . as_deref ( ) . map_or ( false , file_is_cpp) ;
2539
2545
2540
2546
let search_paths = if is_cpp {
2541
2547
clang. cpp_search_paths
@@ -2546,14 +2552,14 @@ impl Bindings {
2546
2552
if let Some ( search_paths) = search_paths {
2547
2553
for path in search_paths. into_iter ( ) {
2548
2554
if let Ok ( path) = path. into_os_string ( ) . into_string ( ) {
2549
- options . clang_args . push ( "-isystem" . to_owned ( ) ) ;
2550
- options . clang_args . push ( path) ;
2555
+ state . clang_args . push ( "-isystem" . to_owned ( ) ) ;
2556
+ state . clang_args . push ( path) ;
2551
2557
}
2552
2558
}
2553
2559
}
2554
2560
}
2555
2561
2556
- detect_include_paths ( & mut options ) ;
2562
+ detect_include_paths ( & options , & mut state ) ;
2557
2563
2558
2564
#[ cfg( unix) ]
2559
2565
fn can_read ( perms : & std:: fs:: Permissions ) -> bool {
@@ -2566,7 +2572,7 @@ impl Bindings {
2566
2572
true
2567
2573
}
2568
2574
2569
- if let Some ( h) = options . input_header . as_ref ( ) {
2575
+ if let Some ( h) = state . input_header . as_ref ( ) {
2570
2576
let path = Path :: new ( h) ;
2571
2577
if let Ok ( md) = std:: fs:: metadata ( path) {
2572
2578
if md. is_dir ( ) {
@@ -2577,17 +2583,17 @@ impl Bindings {
2577
2583
path. into ( ) ,
2578
2584
) ) ;
2579
2585
}
2580
- options . clang_args . push ( h. clone ( ) )
2586
+ state . clang_args . push ( h. clone ( ) )
2581
2587
} else {
2582
2588
return Err ( BindgenError :: NotExist ( path. into ( ) ) ) ;
2583
2589
}
2584
2590
}
2585
2591
2586
2592
for ( idx, f) in state. input_unsaved_files . iter ( ) . enumerate ( ) {
2587
- if idx != 0 || options . input_header . is_some ( ) {
2588
- options . clang_args . push ( "-include" . to_owned ( ) ) ;
2593
+ if idx != 0 || state . input_header . is_some ( ) {
2594
+ state . clang_args . push ( "-include" . to_owned ( ) ) ;
2589
2595
}
2590
- options . clang_args . push ( f. name . to_str ( ) . unwrap ( ) . to_owned ( ) )
2596
+ state . clang_args . push ( f. name . to_str ( ) . unwrap ( ) . to_owned ( ) )
2591
2597
}
2592
2598
2593
2599
debug ! ( "Fixed-up options: {:?}" , options) ;
0 commit comments