Add no_includes option
This commit is contained in:
@@ -65,9 +65,7 @@ impl Bindings {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write<F: Write>(&self, file: F) {
|
||||
let mut out = SourceWriter::new(file, &self.config);
|
||||
|
||||
pub fn write_headers<F: Write>(&self, out: &mut SourceWriter<F>) {
|
||||
if let Some(ref f) = self.config.header {
|
||||
out.new_line_if_not_start();
|
||||
write!(out, "{}", f);
|
||||
@@ -119,6 +117,14 @@ impl Bindings {
|
||||
write!(out, "#include \"{}\"", include);
|
||||
out.new_line();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write<F: Write>(&self, file: F) {
|
||||
let mut out = SourceWriter::new(file, &self.config);
|
||||
|
||||
if !self.config.no_includes {
|
||||
self.write_headers(&mut out);
|
||||
}
|
||||
|
||||
for constant in &self.constants {
|
||||
if constant.ty.is_primitive_or_ptr_primitive() {
|
||||
|
||||
@@ -40,6 +40,12 @@ impl Builder {
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn with_no_includes(mut self) -> Builder {
|
||||
self.config.no_includes = true;
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn with_include<S: AsRef<str>>(mut self, include: S) -> Builder {
|
||||
self.config.includes.push(String::from(include.as_ref()));
|
||||
|
||||
@@ -534,6 +534,11 @@ pub struct Config {
|
||||
pub trailer: Option<String>,
|
||||
/// Optional name to use for an include guard
|
||||
pub include_guard: Option<String>,
|
||||
/// Generates no includes at all. Overrides all other include options
|
||||
///
|
||||
/// This option is useful when using cbindgen with tools such as python's cffi which
|
||||
/// doesn't understand include directives
|
||||
pub no_includes: bool,
|
||||
/// Optional text to output at major sections to deter manual editing
|
||||
pub autogen_warning: Option<String>,
|
||||
/// Include a comment with the version of cbindgen used to generate the file
|
||||
@@ -584,6 +589,7 @@ impl Default for Config {
|
||||
include_guard: None,
|
||||
autogen_warning: None,
|
||||
include_version: false,
|
||||
no_includes: false,
|
||||
namespace: None,
|
||||
namespaces: None,
|
||||
braces: Braces::SameLine,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
void root(void);
|
||||
@@ -0,0 +1 @@
|
||||
void root(void);
|
||||
@@ -0,0 +1,5 @@
|
||||
extern "C" {
|
||||
|
||||
void root();
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1 @@
|
||||
void root(void);
|
||||
@@ -0,0 +1,3 @@
|
||||
#[no_mangle]
|
||||
pub extern "C" fn root() {
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
no_includes = true
|
||||
Reference in New Issue
Block a user