summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ir/context.rs20
-rw-r--r--src/ir/item.rs5
-rw-r--r--src/lib.rs12
-rw-r--r--src/options.rs14
4 files changed, 50 insertions, 1 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index b2e6f985..9afd16d6 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -2296,7 +2296,8 @@ If you encounter an error missing from this list, please file an issue or a PR!"
// game.
if self.options().allowlisted_types.is_empty() &&
self.options().allowlisted_functions.is_empty() &&
- self.options().allowlisted_vars.is_empty()
+ self.options().allowlisted_vars.is_empty() &&
+ self.options().allowlisted_files.is_empty()
{
return true;
}
@@ -2307,6 +2308,23 @@ If you encounter an error missing from this list, please file an issue or a PR!"
return true;
}
+ // Items with a source location in an explicitly allowlisted file
+ // are always included.
+ if !self.options().allowlisted_files.is_empty() {
+ if let Some(location) = item.location() {
+ let (file, _, _, _) = location.location();
+ if let Some(filename) = file.name() {
+ if self
+ .options()
+ .allowlisted_files
+ .matches(&filename)
+ {
+ return true;
+ }
+ }
+ }
+ }
+
let name = item.path_for_allowlisting(self)[1..].join("::");
debug!("allowlisted_items: testing {:?}", name);
match *item.kind() {
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 8692575f..aed575ca 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -530,6 +530,11 @@ impl Item {
&mut self.kind
}
+ /// Where in the source is this item located?
+ pub fn location(&self) -> Option<&clang::SourceLocation> {
+ self.location.as_ref()
+ }
+
/// Get an identifier that differentiates this item from its siblings.
///
/// This should stay relatively stable in the face of code motion outside or
diff --git a/src/lib.rs b/src/lib.rs
index 39f55f04..ea5c61b4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -313,6 +313,7 @@ impl Builder {
(&self.options.allowlisted_functions, "--allowlist-function"),
(&self.options.allowlisted_types, "--allowlist-type"),
(&self.options.allowlisted_vars, "--allowlist-var"),
+ (&self.options.allowlisted_files, "--allowlist-file"),
(&self.options.no_partialeq_types, "--no-partialeq"),
(&self.options.no_copy_types, "--no-copy"),
(&self.options.no_debug_types, "--no-debug"),
@@ -908,6 +909,12 @@ impl Builder {
self
}
+ /// Allowlist the given file so that its contents appear in the generated bindings.
+ pub fn allowlist_file<T: AsRef<str>>(mut self, arg: T) -> Builder {
+ self.options.allowlisted_files.insert(arg);
+ self
+ }
+
/// Deprecated: use allowlist_var instead.
#[deprecated(note = "use allowlist_var instead")]
pub fn whitelist_var<T: AsRef<str>>(self, arg: T) -> Builder {
@@ -1705,6 +1712,9 @@ struct BindgenOptions {
/// Allowlisted variables. See docs for `allowlisted_types` for more.
allowlisted_vars: RegexSet,
+ /// The set of files whose contents should be allowlisted.
+ allowlisted_files: RegexSet,
+
/// The default style of code to generate for enums
default_enum_style: codegen::EnumVariation,
@@ -1984,6 +1994,7 @@ impl BindgenOptions {
&mut self.allowlisted_vars,
&mut self.allowlisted_types,
&mut self.allowlisted_functions,
+ &mut self.allowlisted_files,
&mut self.blocklisted_types,
&mut self.blocklisted_functions,
&mut self.blocklisted_items,
@@ -2042,6 +2053,7 @@ impl Default for BindgenOptions {
allowlisted_types: Default::default(),
allowlisted_functions: Default::default(),
allowlisted_vars: Default::default(),
+ allowlisted_files: Default::default(),
default_enum_style: Default::default(),
bitfield_enums: Default::default(),
newtype_enums: Default::default(),
diff --git a/src/options.rs b/src/options.rs
index 67bcda74..04d42ed5 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -418,6 +418,14 @@ where
.takes_value(true)
.multiple_occurrences(true)
.number_of_values(1),
+ Arg::new("allowlist-file")
+ .alias("allowlist-file")
+ .long("allowlist-file")
+ .help("Allowlist all contents of <path>.")
+ .value_name("path")
+ .takes_value(true)
+ .multiple_occurrences(true)
+ .number_of_values(1),
Arg::new("verbose")
.long("verbose")
.help("Print verbose error messages."),
@@ -871,6 +879,12 @@ where
}
}
+ if let Some(hidden_files) = matches.values_of("allowlist-file") {
+ for file in hidden_files {
+ builder = builder.allowlist_file(file);
+ }
+ }
+
if let Some(args) = matches.values_of("clang-args") {
for arg in args {
builder = builder.clang_arg(arg);