summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs28
-rw-r--r--tests/expectations/tests/test_multiple_header_calls_in_builder.rs17
-rw-r--r--tests/tests.rs26
3 files changed, 70 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ca92d842..5d8237fb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -416,8 +416,34 @@ impl Builder {
output_vector
}
- /// Set the input C/C++ header.
+ /// Add an input C/C++ header to generate bindings for.
+ ///
+ /// This can be used to generate bindings to a single header:
+ ///
+ /// ```ignore
+ /// let bindings = bindgen::Builder::default()
+ /// .header("input.h")
+ /// .generate()
+ /// .unwrap();
+ /// ```
+ ///
+ /// Or you can invoke it multiple times to generate bindings to multiple
+ /// headers:
+ ///
+ /// ```ignore
+ /// let bindings = bindgen::Builder::default()
+ /// .header("first.h")
+ /// .header("second.h")
+ /// .header("third.h")
+ /// .generate()
+ /// .unwrap();
+ /// ```
pub fn header<T: Into<String>>(mut self, header: T) -> Builder {
+ if let Some(prev_header) = self.options.input_header.take() {
+ self.options.clang_args.push("-include".into());
+ self.options.clang_args.push(prev_header);
+ }
+
let header = header.into();
self.options.input_header = Some(header);
self
diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs
new file mode 100644
index 00000000..58ec6fff
--- /dev/null
+++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs
@@ -0,0 +1,17 @@
+/* automatically generated by rust-bindgen */
+
+extern "C" {
+ #[link_name = "foo"]
+ pub static mut foo:
+ ::std::option::Option<unsafe extern "C" fn(x:
+ ::std::os::raw::c_int,
+ y:
+ ::std::os::raw::c_int)
+ -> ::std::os::raw::c_int>;
+}
+#[repr(u32)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum Foo { Bar = 0, Qux = 1, }
+#[repr(i32)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum Neg { MinusOne = -1, One = 1, }
diff --git a/tests/tests.rs b/tests/tests.rs
index bb965bd7..c7e03cb5 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -160,3 +160,29 @@ extern \"C\" {
}
");
}
+
+#[test]
+fn test_multiple_header_calls_in_builder() {
+ let actual = builder()
+ .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/func_ptr.h"))
+ .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/enum.h"))
+ .generate()
+ .unwrap()
+ .to_string();
+
+ let expected = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs"));
+
+ if actual != expected {
+ println!("Generated bindings differ from expected!");
+
+ for diff in diff::lines(&actual, &expected) {
+ match diff {
+ diff::Result::Left(l) => println!("-{}", l),
+ diff::Result::Both(l, _) => println!(" {}", l),
+ diff::Result::Right(r) => println!("+{}", r),
+ }
+ }
+
+ panic!();
+ }
+}