Skip to content

Commit 170d009

Browse files
author
Aatif Syed
committed
add Builder functions for including folder(s) and headers
1 parent 66388de commit 170d009

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

bindgen/lib.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,64 @@ impl Builder {
658658
/// .generate()
659659
/// .unwrap();
660660
/// ```
661+
///
662+
/// Prefer to use the [Builder::headers] method.
663+
#[doc(hidden)]
661664
pub fn header<T: Into<String>>(mut self, header: T) -> Builder {
662665
self.options.input_headers.push(header.into());
663666
self
664667
}
665668

669+
/// Add input C/C++ headers to generate bindings for.
670+
///
671+
/// This can be used to generate bindings to a single header:
672+
///
673+
/// ```ignore
674+
/// let bindings = bindgen::Builder::default()
675+
/// .headers(["input.h"])
676+
/// .generate()
677+
/// .unwrap();
678+
/// ```
679+
///
680+
/// Or to multiple headers:
681+
/// ```
682+
/// bindgen::Builder::default()
683+
/// .headers([
684+
/// "input1.h",
685+
/// "input2.h"
686+
/// ])
687+
/// // ...
688+
/// # ;
689+
/// ```
690+
pub fn headers<T: Into<String>>(
691+
mut self,
692+
headers: impl IntoIterator<Item = T>,
693+
) -> Builder {
694+
self.options
695+
.input_headers
696+
.extend(headers.into_iter().map(Into::into));
697+
self
698+
}
699+
700+
/// Include multiple folders for system header file resolution.
701+
///
702+
/// To add only a single file, use an array of length 1
703+
/// ```
704+
/// bindgen::Builder::default()
705+
/// .include_directories(["/usr/lib/include/"])
706+
/// // ...
707+
/// # ;
708+
/// ```
709+
pub fn include_directories<T: Into<String>>(
710+
mut self,
711+
paths: impl IntoIterator<Item = T>,
712+
) -> Builder {
713+
for path in paths {
714+
self = self.clang_arg(format!("-I{}", path.into()));
715+
}
716+
self
717+
}
718+
666719
/// Add a depfile output which will be written alongside the generated bindings.
667720
pub fn depfile<H: Into<String>, D: Into<PathBuf>>(
668721
mut self,

0 commit comments

Comments
 (0)