diff --git a/src/bindgen/bindings.rs b/src/bindgen/bindings.rs index 4b34805..8268600 100644 --- a/src/bindgen/bindings.rs +++ b/src/bindgen/bindings.rs @@ -82,12 +82,23 @@ impl Bindings { out.write("#include "); out.new_line(); out.write("#include "); + out.new_line(); } else { out.write("#include "); out.new_line(); out.write("#include "); + out.new_line(); + } + + for include in &self.config.sys_includes { + write!(out, "#include <{}>", include); + out.new_line(); + } + + for include in &self.config.includes { + write!(out, "#include \"{}\"", include); + out.new_line(); } - out.new_line(); if self.config.language == Language::Cxx { self.open_namespaces(&mut out); diff --git a/src/bindgen/builder.rs b/src/bindgen/builder.rs index 0b4dd54..5c06da6 100644 --- a/src/bindgen/builder.rs +++ b/src/bindgen/builder.rs @@ -38,6 +38,18 @@ impl Builder { self } + #[allow(unused)] + pub fn with_include>(mut self, include: S) -> Builder { + self.config.includes.push(String::from(include.as_ref())); + self + } + + #[allow(unused)] + pub fn with_sys_include>(mut self, include: S) -> Builder { + self.config.sys_includes.push(String::from(include.as_ref())); + self + } + #[allow(unused)] pub fn with_trailer>(mut self, trailer: S) -> Builder { self.config.trailer = Some(String::from(trailer.as_ref())); diff --git a/src/bindgen/cargo/cargo.rs b/src/bindgen/cargo/cargo.rs index c0bc7d3..746104f 100644 --- a/src/bindgen/cargo/cargo.rs +++ b/src/bindgen/cargo/cargo.rs @@ -173,13 +173,16 @@ impl Cargo { let kind_staticlib = String::from("staticlib"); let kind_rlib = String::from("rlib"); let kind_cdylib = String::from("cdylib"); + let kind_dylib = String::from("dylib"); for meta_package in &self.metadata.packages { if meta_package.name == package.name && meta_package.version == package.version { for target in &meta_package.targets { - if target.kind.contains(&kind_lib) || target.kind.contains(&kind_staticlib) + if target.kind.contains(&kind_lib) + || target.kind.contains(&kind_staticlib) || target.kind.contains(&kind_rlib) || target.kind.contains(&kind_cdylib) + || target.kind.contains(&kind_dylib) { return Some(PathBuf::from(&target.src_path)); } diff --git a/src/bindgen/config.rs b/src/bindgen/config.rs index c5f82e6..c1ad525 100644 --- a/src/bindgen/config.rs +++ b/src/bindgen/config.rs @@ -307,6 +307,10 @@ impl Default for ParseConfig { pub struct Config { /// Optional text to output at the beginning of the file pub header: Option, + /// A list of additional includes to put at the beginning of the generated header + pub includes: Vec, + /// A list of additional system includes to put at the beginning of the generated header + pub sys_includes: Vec, /// Optional text to output at the end of the file pub trailer: Option, /// Optional name to use for an include guard @@ -351,6 +355,8 @@ impl Default for Config { fn default() -> Config { Config { header: None, + includes: Vec::new(), + sys_includes: Vec::new(), trailer: None, include_guard: None, autogen_warning: None, diff --git a/tests/expectations/include.c b/tests/expectations/include.c new file mode 100644 index 0000000..c5d195b --- /dev/null +++ b/tests/expectations/include.c @@ -0,0 +1,4 @@ +#include +#include +#include +#include diff --git a/tests/expectations/include.cpp b/tests/expectations/include.cpp new file mode 100644 index 0000000..b4310b0 --- /dev/null +++ b/tests/expectations/include.cpp @@ -0,0 +1,7 @@ +#include +#include +#include + +extern "C" { + +} // extern "C" diff --git a/tests/rust/include.rs b/tests/rust/include.rs new file mode 100644 index 0000000..e69de29 diff --git a/tests/rust/include.toml b/tests/rust/include.toml new file mode 100644 index 0000000..7d4e0d4 --- /dev/null +++ b/tests/rust/include.toml @@ -0,0 +1 @@ +sys_includes = ["math.h"]