diff options
-rw-r--r-- | src/codegen/mod.rs | 5 | ||||
-rw-r--r-- | src/lib.rs | 16 | ||||
-rw-r--r-- | src/options.rs | 7 | ||||
-rw-r--r-- | tests/tests.rs | 1 |
4 files changed, 27 insertions, 2 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 5ce42c34..3face264 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1045,7 +1045,8 @@ impl<'a> CodeGenerator for Vtable<'a> { // For now, we will only generate vtables for classes that: // - do not inherit from others (compilers merge VTable from primary parent class). // - do not contain a virtual destructor (requires ordering; platforms generate different vtables). - if self.comp_info.base_members().is_empty() && + if ctx.options().vtable_generation && + self.comp_info.base_members().is_empty() && self.comp_info.destructor().is_none() { let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx)); @@ -1793,7 +1794,7 @@ impl CodeGenerator for CompInfo { if !is_opaque { if item.has_vtable_ptr(ctx) { - let vtable = Vtable::new(item.id(), &self); + let vtable = Vtable::new(item.id(), self); vtable.codegen(ctx, result, item); let vtable_type = vtable @@ -569,6 +569,10 @@ impl Builder { output_vector.push("--explicit-padding".into()); } + if self.options.vtable_generation { + output_vector.push("--vtable-generation".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1450,6 +1454,14 @@ impl Builder { self } + /// If true, enables experimental support to generate vtable functions. + /// + /// Should mostly work, though some edge cases are likely to be broken. + pub fn vtable_generation(mut self, doit: bool) -> Self { + self.options.vtable_generation = doit; + self + } + /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result<Bindings, BindgenError> { // Add any extra arguments from the environment to the clang command line. @@ -1981,6 +1993,9 @@ struct BindgenOptions { /// Always output explicit padding fields force_explicit_padding: bool, + + /// Emit vtable functions. + vtable_generation: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -2128,6 +2143,7 @@ impl Default for BindgenOptions { translate_enum_integer_types: false, c_naming: false, force_explicit_padding: false, + vtable_generation: false, } } } diff --git a/src/options.rs b/src/options.rs index 04d42ed5..081aad61 100644 --- a/src/options.rs +++ b/src/options.rs @@ -542,6 +542,9 @@ where Arg::new("explicit-padding") .long("explicit-padding") .help("Always output explicit padding fields."), + Arg::new("vtable-generation") + .long("vtable-generation") + .help("Enables generation of vtable functions."), ]) // .args() .get_matches_from(args); @@ -1008,6 +1011,10 @@ where builder = builder.explicit_padding(true); } + if matches.is_present("vtable-generation") { + builder = builder.vtable_generation(true); + } + let verbose = matches.is_present("verbose"); Ok((builder, output, verbose)) diff --git a/tests/tests.rs b/tests/tests.rs index 274c5683..1f116c93 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -365,6 +365,7 @@ fn create_bindgen_builder(header: &Path) -> Result<BuilderState, Error> { "--no-rustfmt-bindings", "--with-derive-default", "--disable-header-comment", + "--vtable-generation", header_str, "--raw-line", "", |