diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-03-20 14:37:41 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-03-20 14:37:41 +0100 |
commit | b4f103bc91fa73f355fc183d79100f23bfd96c6b (patch) | |
tree | e920b6eff601bd80b409ddd3f7b4a23c9e834fad | |
parent | 15a18fa820d1b9d7e97bd317eb210d0363f95ee3 (diff) |
options: Allow force-generating inline functions.
-rw-r--r-- | src/ir/function.rs | 3 | ||||
-rw-r--r-- | src/lib.rs | 14 | ||||
-rw-r--r-- | src/options.rs | 7 | ||||
-rw-r--r-- | tests/expectations/tests/generate-inline.rs | 33 | ||||
-rw-r--r-- | tests/headers/generate-inline.hpp | 12 |
5 files changed, 68 insertions, 1 deletions
diff --git a/src/ir/function.rs b/src/ir/function.rs index 941694ff..fd88b657 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -310,7 +310,8 @@ impl ClangSubItemParser for Function { return Err(ParseError::Continue); } - if cursor.is_inlined_function() { + if !context.options().generate_inline_functions && + cursor.is_inlined_function() { return Err(ParseError::Continue); } @@ -415,6 +415,16 @@ impl Builder { self } + /// Whether inline functions should be generated or not. + /// + /// Note that they will usually not work. However you can use + /// `-fkeep-inline-functions` or `-fno-inline-functions` if you are + /// responsible of compiling the library to make them callable. + pub fn generate_inline_functions(mut self, doit: bool) -> Self { + self.options.generate_inline_functions = doit; + self + } + /// Ignore functions. pub fn ignore_functions(mut self) -> Builder { self.options.codegen_config.functions = false; @@ -584,6 +594,9 @@ pub struct BindgenOptions { /// documentation for more details. pub generate_comments: bool, + /// Whether to generate inline functions. Defaults to false. + pub generate_inline_functions: bool, + /// Wether to whitelist types recursively. Defaults to true. pub whitelist_recursively: bool, @@ -654,6 +667,7 @@ impl Default for BindgenOptions { codegen_config: CodegenConfig::all(), conservative_inline_namespaces: false, generate_comments: true, + generate_inline_functions: false, whitelist_recursively: true, objc_extern_crate: false, enable_mangling: true, diff --git a/src/options.rs b/src/options.rs index 15146b39..f1c8479a 100644 --- a/src/options.rs +++ b/src/options.rs @@ -177,6 +177,9 @@ pub fn builder_from_flags<I> .takes_value(true) .multiple(true) .number_of_values(1), + Arg::with_name("generate-inline-functions") + .long("generate-inline-functions") + .help("Whether inline functions should be generated."), Arg::with_name("whitelist-type") .long("whitelist-type") .help("Whitelist the type. Other non-whitelisted types will \ @@ -357,6 +360,10 @@ pub fn builder_from_flags<I> builder = builder.conservative_inline_namespaces(); } + if matches.is_present("generate-inline-functions") { + builder = builder.generate_inline_functions(true); + } + if let Some(whitelist) = matches.values_of("whitelist-function") { for regex in whitelist { builder = builder.whitelisted_function(regex); diff --git a/tests/expectations/tests/generate-inline.rs b/tests/expectations/tests/generate-inline.rs new file mode 100644 index 00000000..72057414 --- /dev/null +++ b/tests/expectations/tests/generate-inline.rs @@ -0,0 +1,33 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct Foo { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); +} +extern "C" { + #[link_name = "_ZN3Foo3barEv"] + pub fn Foo_bar() -> ::std::os::raw::c_int; +} +impl Clone for Foo { + fn clone(&self) -> Self { *self } +} +impl Foo { + #[inline] + pub unsafe fn bar() -> ::std::os::raw::c_int { Foo_bar() } +} +extern "C" { + #[link_name = "_Z3foov"] + pub fn foo() -> ::std::os::raw::c_int; +} diff --git a/tests/headers/generate-inline.hpp b/tests/headers/generate-inline.hpp new file mode 100644 index 00000000..922ee1ca --- /dev/null +++ b/tests/headers/generate-inline.hpp @@ -0,0 +1,12 @@ +// bindgen-flags: --generate-inline-functions + +class Foo { + public: + static inline int bar() { + return 42; + } +}; + +inline int foo() { + return 42; +} |