Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions bindgen-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,42 @@ fn test_multiple_header_calls_in_builder() {
}
}

#[test]
fn test_headers_call_in_builder() {
let actual = builder()
.headers([
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/func_ptr.h"),
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h"),
])
.clang_arg("--target=x86_64-unknown-linux")
.generate()
.unwrap()
.to_string();

let actual = format_code(actual).unwrap();

let expected_filename = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/expectations/tests/test_multiple_header_calls_in_builder.rs"
);
let expected = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/expectations/tests/test_multiple_header_calls_in_builder.rs"
));
let expected = format_code(expected).unwrap();

if actual != expected {
println!("Generated bindings differ from expected!");
error_diff_mismatch(
&actual,
&expected,
None,
Path::new(expected_filename),
)
.unwrap();
}
}

#[test]
fn test_multiple_header_contents() {
let actual = builder()
Expand Down
29 changes: 29 additions & 0 deletions bindgen/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,35 @@ options! {
self.options.input_headers.push(header.into().into_boxed_str());
self
}

/// Add input C/C++ header(s) to generate bindings for.
///
/// This can be used to generate bindings for a single header:
///
/// ```ignore
/// let bindings = bindgen::Builder::default()
/// .headers(["input.h"])
/// .generate()
/// .unwrap();
/// ```
///
/// Or for multiple headers:
///
/// ```ignore
/// let bindings = bindgen::Builder::default()
/// .headers(["first.h", "second.h", "third.h"])
/// .generate()
/// .unwrap();
/// ```
pub fn headers<I: IntoIterator>(mut self, headers: I) -> Builder
where
I::Item: Into<String>,
{
self.options
.input_headers
.extend(headers.into_iter().map(Into::into).map(Into::into));
self
}
},
// This field is handled specially inside the macro.
as_args: ignore,
Expand Down