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:
Luca Barbato
2019-11-24 11:28:40 +01:00
committed by Emilio Cobos Álvarez
parent d0d6716556
commit 1a824c04f2
14 changed files with 136 additions and 0 deletions
+2
View File
@@ -396,6 +396,8 @@ no_includes = false
# default: false
cpp_compat = false
# A list of lines to add verbatim after the includes block
after_includes = "#define VERSION 1"
+6
View File
@@ -156,6 +156,7 @@ impl Bindings {
if self.config.no_includes
&& self.config.sys_includes.is_empty()
&& self.config.includes.is_empty()
&& self.config.after_includes.is_none()
{
return;
}
@@ -200,6 +201,11 @@ impl Bindings {
write!(out, "#include \"{}\"", include);
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) {
+6
View File
@@ -60,6 +60,12 @@ impl Builder {
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)]
pub fn with_trailer<S: AsRef<str>>(mut self, trailer: S) -> Builder {
self.config.trailer = Some(String::from(trailer.as_ref()));
+3
View File
@@ -701,6 +701,8 @@ pub struct Config {
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 verbatim code added after the include blocks
pub after_includes: Option<String>,
/// Optional text to output at the end of the file
pub trailer: Option<String>,
/// Optional name to use for an include guard
@@ -768,6 +770,7 @@ impl Default for Config {
header: None,
includes: Vec::new(),
sys_includes: Vec::new(),
after_includes: None,
trailer: None,
include_guard: None,
pragma_once: false,
+1
View File
@@ -24,6 +24,7 @@ using_namespaces = []
sys_includes = []
includes = []
no_includes = false
after_includes = ""
+12
View File
@@ -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 */
+12
View File
@@ -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 */
+20
View File
@@ -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 */
+16
View File
@@ -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
+12
View File
@@ -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 */
+20
View File
@@ -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 */
+3
View File
@@ -0,0 +1,3 @@
#[no_mangle]
pub extern "C" fn root() {
}
+3
View File
@@ -0,0 +1,3 @@
include_guard = "INCLUDE_GUARD_H"
no_includes = false
after_includes = "#define VERSION 1"