Skip to content

Commit 179f4e6

Browse files
committed
move input_headers to BindgenOptions
1 parent 73ce4bc commit 179f4e6

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

bindgen/ir/context.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
541541
let root_module_id = root_module.id().as_module_id_unchecked();
542542

543543
// depfiles need to include the explicitly listed headers too
544-
let mut deps = BTreeSet::default();
545-
if let Some(filename) = &options.input_header {
546-
deps.insert(filename.clone());
547-
}
548-
deps.extend(options.extra_input_headers.iter().cloned());
544+
let deps = options.input_headers.iter().cloned().collect();
549545

550546
BindgenContext {
551547
items: vec![Some(root_module)],

bindgen/lib.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ use crate::parse::{ClangItemParser, ParseError};
7979
use crate::regex_set::RegexSet;
8080

8181
use std::borrow::Cow;
82+
use std::env;
8283
use std::fs::{File, OpenOptions};
8384
use std::io::{self, Write};
8485
use std::path::{Path, PathBuf};
8586
use std::process::{Command, Stdio};
8687
use std::rc::Rc;
87-
use std::{env, iter};
8888

8989
// Some convenient typedefs for a fast hash map and hash set.
9090
type HashMap<K, V> = ::rustc_hash::FxHashMap<K, V>;
@@ -225,7 +225,6 @@ impl Default for CodegenConfig {
225225
#[derive(Debug, Default)]
226226
pub struct Builder {
227227
options: BindgenOptions,
228-
input_headers: Vec<String>,
229228
// Tuples of unsaved file contents of the form (name, contents).
230229
input_header_contents: Vec<(String, String)>,
231230
}
@@ -254,7 +253,7 @@ impl Builder {
254253
pub fn command_line_flags(&self) -> Vec<String> {
255254
let mut output_vector: Vec<String> = Vec::new();
256255

257-
if let Some(header) = self.input_headers.last().cloned() {
256+
if let Some(header) = self.options.input_headers.last().cloned() {
258257
// Positional argument 'header'
259258
output_vector.push(header);
260259
}
@@ -627,13 +626,13 @@ impl Builder {
627626
output_vector.extend(self.options.clang_args.iter().cloned());
628627
}
629628

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());
637636
}
638637

639638
output_vector
@@ -662,7 +661,7 @@ impl Builder {
662661
/// .unwrap();
663662
/// ```
664663
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());
666665
self
667666
}
668667

@@ -1566,13 +1565,11 @@ impl Builder {
15661565
self.options.clang_args.extend(get_extra_clang_args());
15671566

15681567
// 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;
15711568
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()]),
15761573
);
15771574

15781575
let input_unsaved_files = self
@@ -1606,7 +1603,7 @@ impl Builder {
16061603
let mut is_cpp = args_are_cpp(&self.options.clang_args);
16071604

16081605
// For each input header, add `#include "$header"`.
1609-
for header in &self.input_headers {
1606+
for header in &self.options.input_headers {
16101607
is_cpp |= file_is_cpp(header);
16111608

16121609
wrapper_contents.push_str("#include \"");
@@ -1970,11 +1967,8 @@ struct BindgenOptions {
19701967
/// The set of arguments to pass straight through to Clang.
19711968
clang_args: Vec<String>,
19721969

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>,
19781972

19791973
/// A user-provided visitor to allow customizing different kinds of
19801974
/// situations.
@@ -2224,8 +2218,7 @@ impl Default for BindgenOptions {
22242218
raw_lines: vec![],
22252219
module_lines: HashMap::default(),
22262220
clang_args: vec![],
2227-
input_header: None,
2228-
extra_input_headers: vec![],
2221+
input_headers: vec![],
22292222
parse_callbacks: None,
22302223
codegen_config: CodegenConfig::all(),
22312224
conservative_inline_namespaces: false,
@@ -2470,7 +2463,10 @@ impl Bindings {
24702463

24712464
// Whether we are working with C or C++ inputs.
24722465
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));
24742470

24752471
let search_paths = if is_cpp {
24762472
clang.cpp_search_paths
@@ -2501,7 +2497,7 @@ impl Bindings {
25012497
true
25022498
}
25032499

2504-
if let Some(h) = options.input_header.as_ref() {
2500+
if let Some(h) = options.input_headers.last() {
25052501
let path = Path::new(h);
25062502
if let Ok(md) = std::fs::metadata(path) {
25072503
if md.is_dir() {
@@ -2512,14 +2508,15 @@ impl Bindings {
25122508
path.into(),
25132509
));
25142510
}
2515-
options.clang_args.push(h.clone())
2511+
let h = h.clone();
2512+
options.clang_args.push(h);
25162513
} else {
25172514
return Err(BindgenError::NotExist(path.into()));
25182515
}
25192516
}
25202517

25212518
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() {
25232520
options.clang_args.push("-include".to_owned());
25242521
}
25252522
options.clang_args.push(f.name.to_str().unwrap().to_owned())

0 commit comments

Comments
 (0)