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