Skip to content

Commit cc6f3b2

Browse files
author
bors-servo
authored
Auto merge of #595 - emilio:force-inline, r=SimonSapin
options: Allow force-generating inline functions.
2 parents 15a18fa + b4f103b commit cc6f3b2

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

src/ir/function.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ impl ClangSubItemParser for Function {
310310
return Err(ParseError::Continue);
311311
}
312312

313-
if cursor.is_inlined_function() {
313+
if !context.options().generate_inline_functions &&
314+
cursor.is_inlined_function() {
314315
return Err(ParseError::Continue);
315316
}
316317

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,16 @@ impl Builder {
415415
self
416416
}
417417

418+
/// Whether inline functions should be generated or not.
419+
///
420+
/// Note that they will usually not work. However you can use
421+
/// `-fkeep-inline-functions` or `-fno-inline-functions` if you are
422+
/// responsible of compiling the library to make them callable.
423+
pub fn generate_inline_functions(mut self, doit: bool) -> Self {
424+
self.options.generate_inline_functions = doit;
425+
self
426+
}
427+
418428
/// Ignore functions.
419429
pub fn ignore_functions(mut self) -> Builder {
420430
self.options.codegen_config.functions = false;
@@ -584,6 +594,9 @@ pub struct BindgenOptions {
584594
/// documentation for more details.
585595
pub generate_comments: bool,
586596

597+
/// Whether to generate inline functions. Defaults to false.
598+
pub generate_inline_functions: bool,
599+
587600
/// Wether to whitelist types recursively. Defaults to true.
588601
pub whitelist_recursively: bool,
589602

@@ -654,6 +667,7 @@ impl Default for BindgenOptions {
654667
codegen_config: CodegenConfig::all(),
655668
conservative_inline_namespaces: false,
656669
generate_comments: true,
670+
generate_inline_functions: false,
657671
whitelist_recursively: true,
658672
objc_extern_crate: false,
659673
enable_mangling: true,

src/options.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ pub fn builder_from_flags<I>
177177
.takes_value(true)
178178
.multiple(true)
179179
.number_of_values(1),
180+
Arg::with_name("generate-inline-functions")
181+
.long("generate-inline-functions")
182+
.help("Whether inline functions should be generated."),
180183
Arg::with_name("whitelist-type")
181184
.long("whitelist-type")
182185
.help("Whitelist the type. Other non-whitelisted types will \
@@ -357,6 +360,10 @@ pub fn builder_from_flags<I>
357360
builder = builder.conservative_inline_namespaces();
358361
}
359362

363+
if matches.is_present("generate-inline-functions") {
364+
builder = builder.generate_inline_functions(true);
365+
}
366+
360367
if let Some(whitelist) = matches.values_of("whitelist-function") {
361368
for regex in whitelist {
362369
builder = builder.whitelisted_function(regex);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Default, Copy)]
9+
pub struct Foo {
10+
pub _address: u8,
11+
}
12+
#[test]
13+
fn bindgen_test_layout_Foo() {
14+
assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
15+
"Size of: " , stringify ! ( Foo ) ));
16+
assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
17+
"Alignment of " , stringify ! ( Foo ) ));
18+
}
19+
extern "C" {
20+
#[link_name = "_ZN3Foo3barEv"]
21+
pub fn Foo_bar() -> ::std::os::raw::c_int;
22+
}
23+
impl Clone for Foo {
24+
fn clone(&self) -> Self { *self }
25+
}
26+
impl Foo {
27+
#[inline]
28+
pub unsafe fn bar() -> ::std::os::raw::c_int { Foo_bar() }
29+
}
30+
extern "C" {
31+
#[link_name = "_Z3foov"]
32+
pub fn foo() -> ::std::os::raw::c_int;
33+
}

tests/headers/generate-inline.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// bindgen-flags: --generate-inline-functions
2+
3+
class Foo {
4+
public:
5+
static inline int bar() {
6+
return 42;
7+
}
8+
};
9+
10+
inline int foo() {
11+
return 42;
12+
}

0 commit comments

Comments
 (0)