diff options
author | Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> | 2022-11-02 15:30:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 15:30:34 -0500 |
commit | 9c32b460481903d90c6ac5df277bfa853a0558d8 (patch) | |
tree | 6ee9ed2f853a78942314fb71df3868b89125cc86 /bindgen/lib.rs | |
parent | a673a6bc9b83675a7468379e79dcf5d5659c4623 (diff) |
Add the `--override-abi` option (#2329)
* Add the `--override-abi` option.
This option can be used from the CLI with the <abi>:<regex> syntax and
it overrides the ABI of a function if it matches <regex>.
Fixes #2257
Diffstat (limited to 'bindgen/lib.rs')
-rw-r--r-- | bindgen/lib.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 5e04acfe..10410734 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -74,6 +74,7 @@ pub use crate::features::{ RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS, }; use crate::ir::context::{BindgenContext, ItemId}; +pub use crate::ir::function::Abi; use crate::ir::item::Item; use crate::parse::{ClangItemParser, ParseError}; use crate::regex_set::RegexSet; @@ -364,6 +365,13 @@ impl Builder { } } + for (abi, set) in &self.options.abi_overrides { + for item in set.get_items() { + output_vector.push("--override-abi".to_owned()); + output_vector.push(format!("{}={}", item, abi)); + } + } + if !self.options.layout_tests { output_vector.push("--no-layout-tests".into()); } @@ -1774,6 +1782,16 @@ impl Builder { self.options.c_naming = doit; self } + + /// Override the ABI of a given function. Regular expressions are supported. + pub fn override_abi<T: Into<String>>(mut self, abi: Abi, arg: T) -> Self { + self.options + .abi_overrides + .entry(abi) + .or_default() + .insert(arg.into()); + self + } } /// Configuration options for generated bindings. @@ -2109,11 +2127,13 @@ struct BindgenOptions { /// Deduplicate `extern` blocks. merge_extern_blocks: bool, + + abi_overrides: HashMap<Abi, RegexSet>, } impl BindgenOptions { fn build(&mut self) { - let mut regex_sets = [ + let regex_sets = [ &mut self.allowlisted_vars, &mut self.allowlisted_types, &mut self.allowlisted_functions, @@ -2143,7 +2163,7 @@ impl BindgenOptions { &mut self.must_use_types, ]; let record_matches = self.record_matches; - for regex_set in &mut regex_sets { + for regex_set in self.abi_overrides.values_mut().chain(regex_sets) { regex_set.build(record_matches); } } @@ -2280,6 +2300,7 @@ impl Default for BindgenOptions { vtable_generation: false, sort_semantically: false, merge_extern_blocks: false, + abi_overrides: Default::default(), } } } |