Add the ability to specify additional includes
This commit is contained in:
+12
-1
@@ -82,12 +82,23 @@ impl Bindings {
|
||||
out.write("#include <stdlib.h>");
|
||||
out.new_line();
|
||||
out.write("#include <stdbool.h>");
|
||||
out.new_line();
|
||||
} else {
|
||||
out.write("#include <cstdint>");
|
||||
out.new_line();
|
||||
out.write("#include <cstdlib>");
|
||||
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);
|
||||
|
||||
@@ -38,6 +38,18 @@ impl Builder {
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn with_include<S: AsRef<str>>(mut self, include: S) -> Builder {
|
||||
self.config.includes.push(String::from(include.as_ref()));
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn with_sys_include<S: AsRef<str>>(mut self, include: S) -> Builder {
|
||||
self.config.sys_includes.push(String::from(include.as_ref()));
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn with_trailer<S: AsRef<str>>(mut self, trailer: S) -> Builder {
|
||||
self.config.trailer = Some(String::from(trailer.as_ref()));
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -307,6 +307,10 @@ impl Default for ParseConfig {
|
||||
pub struct Config {
|
||||
/// Optional text to output at the beginning of the file
|
||||
pub header: Option<String>,
|
||||
/// A list of additional includes to put at the beginning of the generated header
|
||||
pub includes: Vec<String>,
|
||||
/// A list of additional system includes to put at the beginning of the generated header
|
||||
pub sys_includes: Vec<String>,
|
||||
/// Optional text to output at the end of the file
|
||||
pub trailer: Option<String>,
|
||||
/// 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,
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <math.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1 @@
|
||||
sys_includes = ["math.h"]
|
||||
Reference in New Issue
Block a user