Skip to content

Commit 7822b96

Browse files
author
bors-servo
authored
Auto merge of #70 - emilio:llvm3.9, r=<try>
Make the switch to LLVM3.9. r? @nox I don't know if this will pass CI yet, let's see.
2 parents 2034f77 + ddf9678 commit 7822b96

17 files changed

+92
-58
lines changed

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ language: rust
22
addons:
33
apt:
44
sources:
5-
- llvm-toolchain-precise-3.8
5+
- llvm-toolchain-precise-3.9
66
- ubuntu-toolchain-r-test
77
packages:
8-
- libclang-3.8-dev
9-
- llvm-3.8-dev
8+
- libclang-3.9-dev
9+
- llvm-3.9-dev
1010
env:
11-
- LLVM_VERSION=3.8
11+
- LLVM_VERSION=3.9
1212
rust:
1313
- stable
1414
- nightly
@@ -39,7 +39,7 @@ before_script:
3939
- echo $LIBCLANG_PATH
4040

4141
script:
42-
- cargo build --verbose --features llvm_stable
42+
- cargo build --verbose
4343
- make test
4444
- git add -A
4545
- git diff @

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ features = ["with-syntex"]
4343
version = "0.20"
4444

4545
[features]
46-
llvm_stable = []
4746
static = []
4847

4948
[lib]

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ BINDGEN := ./target/debug/bindgen
99

1010
.PHONY: $(BINDGEN)
1111
$(BINDGEN):
12-
[ -f $@ ] || cargo build --features llvm_stable
12+
[ -f $@ ] || cargo build
1313

1414
.PHONY: test
1515
test: regen-tests

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,14 @@ Those instructions list optional steps. For bindgen:
6464

6565
## Building
6666

67+
Just run:
68+
6769
```
68-
$ cargo build --features llvm_stable
70+
cargo build
6971
```
7072

71-
If you want a build with extra features (llvm 3.9) then you can use:
73+
This version of bindgen requires LLVM 3.9, so if you don't have it installed in
74+
your `PATH`, you'll need to build it (see below) and do something like:
7275

7376
```
7477
$ LIBCLANG_PATH=path/to/clang-3.9/build/lib \

build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@ mod codegen {
1515
}
1616

1717
fn main() {
18+
use std::env;
19+
1820
codegen::main();
21+
if let Ok(path) = env::var("LIBCLANG_PATH") {
22+
println!("cargo:rustc-link-search=native={}", path);
23+
}
1924
}

src/bin/bindgen.rs

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Options:
5656
5757
--ignore-methods Avoid generating all kind of methods.
5858
59+
--keep-inline-functions Generate code for inline functions anyway.
60+
5961
--enable-cxx-namespaces Enable support for C++ namespaces.
6062
6163
--no-type-renaming Don't rename types.
@@ -158,6 +160,9 @@ fn parse_args_or_exit(args: Vec<String>) -> (BindgenOptions, Box<io::Write>) {
158160
"--ignore-functions" => {
159161
options.ignore_functions = true;
160162
}
163+
"--keep-inline-functions" => {
164+
options.keep_inline_functions = true;
165+
}
161166
"--no-bitfield-methods" => {
162167
options.gen_bitfield_methods = false;
163168
}

src/clang.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ pub struct Cursor {
1717

1818
impl fmt::Debug for Cursor {
1919
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
20-
write!(fmt, "Cursor({} kind: {}, loc: {}, usr: {:?})",
21-
self.spelling(), kind_to_str(self.kind()), self.location(), self.usr())
20+
write!(fmt, "Cursor({} kind: {} ({}), loc: {}, usr: {:?})",
21+
self.spelling(), kind_to_str(self.kind()), self.kind(),
22+
self.location(), self.usr())
2223
}
2324
}
2425

@@ -211,19 +212,10 @@ impl Cursor {
211212
}
212213
}
213214

214-
#[cfg(not(feature="llvm_stable"))]
215215
pub fn is_inlined_function(&self) -> bool {
216216
unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 }
217217
}
218218

219-
// TODO: Remove this when LLVM 3.9 is released.
220-
//
221-
// This is currently used for CI purposes.
222-
#[cfg(feature="llvm_stable")]
223-
pub fn is_inlined_function(&self) -> bool {
224-
false
225-
}
226-
227219
// bitfield
228220
pub fn bit_width(&self) -> Option<u32> {
229221
unsafe {
@@ -392,9 +384,9 @@ impl Eq for Type {}
392384

393385
impl fmt::Debug for Type {
394386
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
395-
write!(fmt, "Type({}, kind: {}, decl: {:?}, canon: {:?})",
396-
self.spelling(), type_to_str(self.kind()), self.declaration(),
397-
self.declaration().canonical())
387+
write!(fmt, "Type({}, kind: {} ({}), decl: {:?}, canon: {:?})",
388+
self.spelling(), type_to_str(self.kind()), self.kind(),
389+
self.declaration(), self.declaration().canonical())
398390
}
399391
}
400392

@@ -573,7 +565,6 @@ impl Type {
573565
}
574566
}
575567

576-
#[cfg(not(feature="llvm_stable"))]
577568
pub fn named(&self) -> Type {
578569
unsafe {
579570
Type { x: clang_Type_getNamedType(self.x) }
@@ -1093,9 +1084,7 @@ pub fn type_to_str(x: Enum_CXTypeKind) -> &'static str {
10931084
CXType_VariableArray => "VariableArray",
10941085
CXType_DependentSizedArray => "DependentSizedArray",
10951086
CXType_MemberPointer => "MemberPointer",
1096-
#[cfg(not(feature="llvm_stable"))]
10971087
CXType_Auto => "Auto",
1098-
#[cfg(not(feature="llvm_stable"))]
10991088
CXType_Elaborated => "Elaborated",
11001089
_ => "?"
11011090
}

src/clangll.rs

-4
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,7 @@ pub const CXType_IncompleteArray: c_uint = 114;
408408
pub const CXType_VariableArray: c_uint = 115;
409409
pub const CXType_DependentSizedArray: c_uint = 116;
410410
pub const CXType_MemberPointer: c_uint = 117;
411-
#[cfg(not(feature="llvm_stable"))]
412411
pub const CXType_Auto: c_uint = 118;
413-
#[cfg(not(feature="llvm_stable"))]
414412
pub const CXType_Elaborated: c_uint = 119;
415413
pub type Enum_CXCallingConv = c_uint;
416414
pub const CXCallingConv_Default: c_uint = 0;
@@ -1113,10 +1111,8 @@ extern "C" {
11131111
pub fn clang_Type_getNumTemplateArguments(T: CXType) -> c_int;
11141112
pub fn clang_Type_getTemplateArgumentAsType(T: CXType, i: c_int) ->
11151113
CXType;
1116-
#[cfg(not(feature="llvm_stable"))]
11171114
pub fn clang_Type_getNamedType(CT: CXType) -> CXType;
11181115
pub fn clang_Cursor_isBitField(C: CXCursor) -> c_uint;
1119-
#[cfg(not(feature="llvm_stable"))]
11201116
pub fn clang_Cursor_isFunctionInlined(C: CXCursor) -> c_uint;
11211117
pub fn clang_isVirtualBase(arg1: CXCursor) -> c_uint;
11221118
pub fn clang_getCXXAccessSpecifier(arg1: CXCursor) ->

src/ir/comp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl CompInfo {
583583
return CXChildVisit_Continue;
584584
}
585585

586-
if cur.is_inlined_function() {
586+
if cur.is_inlined_function() && !ctx.options().keep_inline_functions {
587587
return CXChildVisit_Continue;
588588
}
589589

src/ir/function.rs

+5
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ impl FunctionSig {
104104
use clangll::*;
105105
debug!("FunctionSig::from_ty {:?} {:?}", ty, cursor);
106106

107+
if cursor.is_inlined_function() && !ctx.options().keep_inline_functions {
108+
return Err(ParseError::Continue);
109+
}
110+
107111
// Don't parse operatorxx functions in C++
108112
let spelling = cursor.spelling();
109113
if spelling.starts_with("operator") {
@@ -115,6 +119,7 @@ impl FunctionSig {
115119
} else {
116120
ty.declaration()
117121
};
122+
118123
let mut args: Vec<_> = match cursor.kind() {
119124
CXCursor_FunctionDecl |
120125
CXCursor_CXXMethod => {

src/ir/ty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ impl Type {
543543
.expect("Not able to resolve array element?");
544544
TypeKind::Array(inner, ty.array_size())
545545
}
546-
#[cfg(not(feature="llvm_stable"))]
547546
CXType_Elaborated => {
548547
return Self::from_clang_ty(potential_id, &ty.named(),
549548
location, parent_id, ctx);

src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ pub struct BindgenOptions {
173173
pub emit_ast: bool,
174174
pub ignore_functions: bool,
175175
pub ignore_methods: bool,
176+
/// Whether to generate code for inline functions. If you do this, you need
177+
/// to make sure you compile the C++ code with a flag like
178+
/// -fkeep-inline-functions
179+
pub keep_inline_functions: bool,
176180
pub gen_bitfield_methods: bool,
177181
pub fail_on_unknown_type: bool,
178182
pub enable_cxx_namespaces: bool,
@@ -208,6 +212,7 @@ impl Default for BindgenOptions {
208212
emit_ast: false,
209213
ignore_functions: false,
210214
ignore_methods: false,
215+
keep_inline_functions: false,
211216
gen_bitfield_methods: true,
212217
fail_on_unknown_type: true,
213218
rename_types: true,

tests/expectations/class_with_typedef.rs

+4-26
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,16 @@ fn bindgen_test_layout_C() {
2222
assert_eq!(::std::mem::align_of::<C>() , 8usize);
2323
}
2424
extern "C" {
25-
#[link_name = "_ZN1C6methodEi"]
26-
pub fn C_method(this: *mut C, c: C_MyInt);
27-
}
28-
extern "C" {
29-
#[link_name = "_ZN1C9methodRefERi"]
30-
pub fn C_methodRef(this: *mut C, c: *mut C_MyInt);
31-
}
32-
extern "C" {
33-
#[link_name = "_ZN1C16complexMethodRefERPKc"]
34-
pub fn C_complexMethodRef(this: *mut C, c: *mut C_Lookup);
35-
}
36-
extern "C" {
37-
#[link_name = "_ZN1C13anotherMethodEi"]
38-
pub fn C_anotherMethod(this: *mut C, c: AnotherInt);
25+
#[link_name = "_ZN1C16notInlinedMethodEi"]
26+
pub fn C_notInlinedMethod(this: *mut C, c: C_MyInt);
3927
}
4028
impl Clone for C {
4129
fn clone(&self) -> Self { *self }
4230
}
4331
impl C {
4432
#[inline]
45-
pub unsafe fn method(&mut self, c: C_MyInt) { C_method(&mut *self, c) }
46-
#[inline]
47-
pub unsafe fn methodRef(&mut self, c: *mut C_MyInt) {
48-
C_methodRef(&mut *self, c)
49-
}
50-
#[inline]
51-
pub unsafe fn complexMethodRef(&mut self, c: *mut C_Lookup) {
52-
C_complexMethodRef(&mut *self, c)
53-
}
54-
#[inline]
55-
pub unsafe fn anotherMethod(&mut self, c: AnotherInt) {
56-
C_anotherMethod(&mut *self, c)
33+
pub unsafe fn notInlinedMethod(&mut self, c: C_MyInt) {
34+
C_notInlinedMethod(&mut *self, c)
5735
}
5836
}
5937
#[repr(C)]
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
extern "C" {
8+
#[link_name = "_Z3foov"]
9+
pub fn foo() -> bool;
10+
}
11+
#[repr(C)]
12+
#[derive(Debug, Copy)]
13+
pub struct C {
14+
pub _address: u8,
15+
}
16+
#[test]
17+
fn bindgen_test_layout_C() {
18+
assert_eq!(::std::mem::size_of::<C>() , 1usize);
19+
assert_eq!(::std::mem::align_of::<C>() , 1usize);
20+
}
21+
extern "C" {
22+
#[link_name = "_ZN1C3fooEv"]
23+
pub fn C_foo();
24+
}
25+
extern "C" {
26+
#[link_name = "_ZN1C3barEv"]
27+
pub fn C_bar() -> bool;
28+
}
29+
impl Clone for C {
30+
fn clone(&self) -> Self { *self }
31+
}
32+
impl C {
33+
#[inline]
34+
pub unsafe fn foo() { C_foo() }
35+
#[inline]
36+
pub unsafe fn bar() -> bool { C_bar() }
37+
}

tests/headers/class_with_typedef.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class C {
1616
void methodRef(MyInt& c) {};
1717
void complexMethodRef(Lookup& c) {};
1818
void anotherMethod(AnotherInt c) {};
19+
void notInlinedMethod(MyInt c);
1920
};
2021

2122
class D: public C {

tests/headers/inlined_functions.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// bindgen-flags: --keep-inline-functions
2+
3+
inline bool foo() {
4+
return true;
5+
}
6+
7+
class C {
8+
public:
9+
static void foo() { }
10+
static bool bar() { return false; }
11+
};

tests/tools/run-bindgen.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
# https://forums.developer.apple.com/thread/9233
4141
if "DYLD_LIBRARY_PATH" not in env and "LIBCLANG_PATH" in env:
4242
env["DYLD_LIBRARY_PATH"] = env["LIBCLANG_PATH"]
43+
4344
subprocess.check_call(base_command, cwd=os.getcwd(), env=env)
4445

4546

0 commit comments

Comments
 (0)