Add support for verbatim content after includes
Let the user add raw C code in the generated header after the include blocks. It matches what bindgen provides with the raw_lines option.
This commit is contained in:
committed by
Emilio Cobos Álvarez
parent
d0d6716556
commit
1a824c04f2
@@ -396,6 +396,8 @@ no_includes = false
|
|||||||
# default: false
|
# default: false
|
||||||
cpp_compat = false
|
cpp_compat = false
|
||||||
|
|
||||||
|
# A list of lines to add verbatim after the includes block
|
||||||
|
after_includes = "#define VERSION 1"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ impl Bindings {
|
|||||||
if self.config.no_includes
|
if self.config.no_includes
|
||||||
&& self.config.sys_includes.is_empty()
|
&& self.config.sys_includes.is_empty()
|
||||||
&& self.config.includes.is_empty()
|
&& self.config.includes.is_empty()
|
||||||
|
&& self.config.after_includes.is_none()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -200,6 +201,11 @@ impl Bindings {
|
|||||||
write!(out, "#include \"{}\"", include);
|
write!(out, "#include \"{}\"", include);
|
||||||
out.new_line();
|
out.new_line();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(ref line) = self.config.after_includes {
|
||||||
|
write!(out, "{}", line);
|
||||||
|
out.new_line();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write<F: Write>(&self, file: F) {
|
pub fn write<F: Write>(&self, file: F) {
|
||||||
|
|||||||
@@ -60,6 +60,12 @@ impl Builder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn with_after_include<S: AsRef<str>>(mut self, line: S) -> Builder {
|
||||||
|
self.config.after_includes = Some(String::from(line.as_ref()));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn with_trailer<S: AsRef<str>>(mut self, trailer: S) -> Builder {
|
pub fn with_trailer<S: AsRef<str>>(mut self, trailer: S) -> Builder {
|
||||||
self.config.trailer = Some(String::from(trailer.as_ref()));
|
self.config.trailer = Some(String::from(trailer.as_ref()));
|
||||||
|
|||||||
@@ -701,6 +701,8 @@ pub struct Config {
|
|||||||
pub includes: Vec<String>,
|
pub includes: Vec<String>,
|
||||||
/// A list of additional system includes to put at the beginning of the generated header
|
/// A list of additional system includes to put at the beginning of the generated header
|
||||||
pub sys_includes: Vec<String>,
|
pub sys_includes: Vec<String>,
|
||||||
|
/// Optional verbatim code added after the include blocks
|
||||||
|
pub after_includes: Option<String>,
|
||||||
/// Optional text to output at the end of the file
|
/// Optional text to output at the end of the file
|
||||||
pub trailer: Option<String>,
|
pub trailer: Option<String>,
|
||||||
/// Optional name to use for an include guard
|
/// Optional name to use for an include guard
|
||||||
@@ -768,6 +770,7 @@ impl Default for Config {
|
|||||||
header: None,
|
header: None,
|
||||||
includes: Vec::new(),
|
includes: Vec::new(),
|
||||||
sys_includes: Vec::new(),
|
sys_includes: Vec::new(),
|
||||||
|
after_includes: None,
|
||||||
trailer: None,
|
trailer: None,
|
||||||
include_guard: None,
|
include_guard: None,
|
||||||
pragma_once: false,
|
pragma_once: false,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ using_namespaces = []
|
|||||||
sys_includes = []
|
sys_includes = []
|
||||||
includes = []
|
includes = []
|
||||||
no_includes = false
|
no_includes = false
|
||||||
|
after_includes = ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef INCLUDE_GUARD_H
|
||||||
|
#define INCLUDE_GUARD_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define VERSION 1
|
||||||
|
|
||||||
|
void root(void);
|
||||||
|
|
||||||
|
#endif /* INCLUDE_GUARD_H */
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef INCLUDE_GUARD_H
|
||||||
|
#define INCLUDE_GUARD_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define VERSION 1
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
void root(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif /* INCLUDE_GUARD_H */
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef INCLUDE_GUARD_H
|
||||||
|
#define INCLUDE_GUARD_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define VERSION 1
|
||||||
|
|
||||||
|
void root(void);
|
||||||
|
|
||||||
|
#endif /* INCLUDE_GUARD_H */
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef INCLUDE_GUARD_H
|
||||||
|
#define INCLUDE_GUARD_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define VERSION 1
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
void root(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif /* INCLUDE_GUARD_H */
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef INCLUDE_GUARD_H
|
||||||
|
#define INCLUDE_GUARD_H
|
||||||
|
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <new>
|
||||||
|
#define VERSION 1
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void root();
|
||||||
|
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
|
#endif // INCLUDE_GUARD_H
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef INCLUDE_GUARD_H
|
||||||
|
#define INCLUDE_GUARD_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define VERSION 1
|
||||||
|
|
||||||
|
void root(void);
|
||||||
|
|
||||||
|
#endif /* INCLUDE_GUARD_H */
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef INCLUDE_GUARD_H
|
||||||
|
#define INCLUDE_GUARD_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define VERSION 1
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
void root(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif /* INCLUDE_GUARD_H */
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn root() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
include_guard = "INCLUDE_GUARD_H"
|
||||||
|
no_includes = false
|
||||||
|
after_includes = "#define VERSION 1"
|
||||||
Reference in New Issue
Block a user