@@ -79,12 +79,12 @@ use crate::parse::{ClangItemParser, ParseError};
79
79
use crate :: regex_set:: RegexSet ;
80
80
81
81
use std:: borrow:: Cow ;
82
+ use std:: env;
82
83
use std:: fs:: { File , OpenOptions } ;
83
84
use std:: io:: { self , Write } ;
84
85
use std:: path:: { Path , PathBuf } ;
85
86
use std:: process:: { Command , Stdio } ;
86
87
use std:: rc:: Rc ;
87
- use std:: { env, iter} ;
88
88
89
89
// Some convenient typedefs for a fast hash map and hash set.
90
90
type HashMap < K , V > = :: rustc_hash:: FxHashMap < K , V > ;
@@ -225,7 +225,6 @@ impl Default for CodegenConfig {
225
225
#[ derive( Debug , Default ) ]
226
226
pub struct Builder {
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
}
@@ -627,13 +626,13 @@ impl Builder {
627
626
output_vector. extend ( self . options . clang_args . iter ( ) . cloned ( ) ) ;
628
627
}
629
628
630
- if self . input_headers . len ( ) > 1 {
631
- // To pass more than one header, we need to pass all but the last
632
- // header via the `-include` clang arg
633
- for header in & self . input_headers [ ..self . input_headers . len ( ) - 1 ] {
634
- output_vector . push ( "-include" . to_string ( ) ) ;
635
- output_vector. push ( header . clone ( ) ) ;
636
- }
629
+ // To pass more than one header, we need to pass all but the last
630
+ // header via the `-include` clang arg
631
+ for header in & self . options . input_headers
632
+ [ ..self . options . input_headers . len ( ) . saturating_sub ( 1 ) ]
633
+ {
634
+ output_vector. push ( "-include" . to_string ( ) ) ;
635
+ output_vector . push ( header . clone ( ) ) ;
637
636
}
638
637
639
638
output_vector
@@ -662,7 +661,7 @@ impl Builder {
662
661
/// .unwrap();
663
662
/// ```
664
663
pub fn header < T : Into < String > > ( mut self , header : T ) -> Builder {
665
- self . input_headers . push ( header. into ( ) ) ;
664
+ self . options . input_headers . push ( header. into ( ) ) ;
666
665
self
667
666
}
668
667
@@ -1566,13 +1565,11 @@ impl Builder {
1566
1565
self . options . clang_args . extend ( get_extra_clang_args ( ) ) ;
1567
1566
1568
1567
// Transform input headers to arguments on the clang command line.
1569
- self . options . input_header = self . input_headers . pop ( ) ;
1570
- self . options . extra_input_headers = self . input_headers ;
1571
1568
self . options . clang_args . extend (
1572
- self . options . extra_input_headers . iter ( ) . flat_map ( |header| {
1573
- iter :: once ( "-include" . into ( ) )
1574
- . chain ( iter:: once ( header . to_string ( ) ) )
1575
- } ) ,
1569
+ self . options . input_headers
1570
+ [ .. self . options . input_headers . len ( ) . saturating_sub ( 1 ) ]
1571
+ . iter ( )
1572
+ . flat_map ( |header| [ "-include" . into ( ) , header . to_string ( ) ] ) ,
1576
1573
) ;
1577
1574
1578
1575
let input_unsaved_files = self
@@ -1606,7 +1603,7 @@ impl Builder {
1606
1603
let mut is_cpp = args_are_cpp ( & self . options . clang_args ) ;
1607
1604
1608
1605
// For each input header, add `#include "$header"`.
1609
- for header in & self . input_headers {
1606
+ for header in & self . options . input_headers {
1610
1607
is_cpp |= file_is_cpp ( header) ;
1611
1608
1612
1609
wrapper_contents. push_str ( "#include \" " ) ;
@@ -1970,11 +1967,8 @@ struct BindgenOptions {
1970
1967
/// The set of arguments to pass straight through to Clang.
1971
1968
clang_args : Vec < String > ,
1972
1969
1973
- /// The input header file.
1974
- input_header : Option < String > ,
1975
-
1976
- /// Any additional input header files.
1977
- extra_input_headers : Vec < String > ,
1970
+ /// The input header files.
1971
+ input_headers : Vec < String > ,
1978
1972
1979
1973
/// A user-provided visitor to allow customizing different kinds of
1980
1974
/// situations.
@@ -2224,8 +2218,7 @@ impl Default for BindgenOptions {
2224
2218
raw_lines : vec ! [ ] ,
2225
2219
module_lines : HashMap :: default ( ) ,
2226
2220
clang_args : vec ! [ ] ,
2227
- input_header : None ,
2228
- extra_input_headers : vec ! [ ] ,
2221
+ input_headers : vec ! [ ] ,
2229
2222
parse_callbacks : None ,
2230
2223
codegen_config : CodegenConfig :: all ( ) ,
2231
2224
conservative_inline_namespaces : false ,
@@ -2470,7 +2463,10 @@ impl Bindings {
2470
2463
2471
2464
// Whether we are working with C or C++ inputs.
2472
2465
let is_cpp = args_are_cpp ( & options. clang_args ) ||
2473
- options. input_header . as_deref ( ) . map_or ( false , file_is_cpp) ;
2466
+ options
2467
+ . input_headers
2468
+ . last ( )
2469
+ . map_or ( false , |x| file_is_cpp ( x) ) ;
2474
2470
2475
2471
let search_paths = if is_cpp {
2476
2472
clang. cpp_search_paths
@@ -2501,7 +2497,7 @@ impl Bindings {
2501
2497
true
2502
2498
}
2503
2499
2504
- if let Some ( h) = options. input_header . as_ref ( ) {
2500
+ if let Some ( h) = options. input_headers . last ( ) {
2505
2501
let path = Path :: new ( h) ;
2506
2502
if let Ok ( md) = std:: fs:: metadata ( path) {
2507
2503
if md. is_dir ( ) {
@@ -2512,14 +2508,15 @@ impl Bindings {
2512
2508
path. into ( ) ,
2513
2509
) ) ;
2514
2510
}
2515
- options. clang_args . push ( h. clone ( ) )
2511
+ let h = h. clone ( ) ;
2512
+ options. clang_args . push ( h) ;
2516
2513
} else {
2517
2514
return Err ( BindgenError :: NotExist ( path. into ( ) ) ) ;
2518
2515
}
2519
2516
}
2520
2517
2521
2518
for ( idx, f) in input_unsaved_files. iter ( ) . enumerate ( ) {
2522
- if idx != 0 || options. input_header . is_some ( ) {
2519
+ if idx != 0 || ! options. input_headers . is_empty ( ) {
2523
2520
options. clang_args . push ( "-include" . to_owned ( ) ) ;
2524
2521
}
2525
2522
options. clang_args . push ( f. name . to_str ( ) . unwrap ( ) . to_owned ( ) )
0 commit comments