summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 433198b0..8f838c15 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -175,6 +175,14 @@ impl Builder {
self
}
+ /// Add `contents` as an input C/C++ header named `name`.
+ ///
+ /// The file `name` will be added to the clang arguments.
+ pub fn header_contents(mut self, name: &str, contents: &str) -> Builder {
+ self.options.input_unsaved_files.push(clang::UnsavedFile::new(name, contents));
+ self
+ }
+
/// Set the output graphviz file.
pub fn emit_ir_graphviz<T: Into<String>>(mut self, path: T) -> Builder {
let path = path.into();
@@ -573,6 +581,9 @@ pub struct BindgenOptions {
/// The input header file.
pub input_header: Option<String>,
+ /// Unsaved files for input.
+ pub input_unsaved_files: Vec<clang::UnsavedFile>,
+
/// Generate a dummy C/C++ file that includes the header and has dummy uses
/// of all types defined therein. See the `uses` module for more.
pub dummy_uses: Option<String>,
@@ -662,6 +673,7 @@ impl Default for BindgenOptions {
raw_lines: vec![],
clang_args: vec![],
input_header: None,
+ input_unsaved_files: vec![],
dummy_uses: None,
parse_callbacks: None,
codegen_config: CodegenConfig::all(),
@@ -754,6 +766,10 @@ impl<'ctx> Bindings<'ctx> {
options.clang_args.push(h.clone())
}
+ for f in options.input_unsaved_files.iter() {
+ options.clang_args.push(f.name.to_str().unwrap().to_owned())
+ }
+
let mut context = BindgenContext::new(options);
try!(parse(&mut context));