summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml11
-rw-r--r--CONTRIBUTING.md31
-rw-r--r--Cargo.toml4
-rw-r--r--bindgen-integration/Cargo.toml4
-rw-r--r--src/main.rs5
-rw-r--r--tests/expectations/tests/libclang-3.8/auto.rs34
-rw-r--r--tests/expectations/tests/libclang-3.8/call-conv-field.rs42
-rw-r--r--tests/expectations/tests/libclang-3.8/const_bool.rs34
-rw-r--r--tests/expectations/tests/libclang-3.8/constant-evaluate.rs41
-rw-r--r--tests/expectations/tests/libclang-3.8/objc_template.rs (renamed from tests/expectations/tests/objc_template.rs)0
-rw-r--r--tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs56
-rw-r--r--tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs (renamed from tests/expectations/tests/type_alias_template_specialized.rs)0
-rw-r--r--tests/expectations/tests/libclang-3.9/auto.rs (renamed from tests/expectations/tests/auto.rs)0
-rw-r--r--tests/expectations/tests/libclang-3.9/call-conv-field.rs (renamed from tests/expectations/tests/call-conv-field.rs)2
-rw-r--r--tests/expectations/tests/libclang-3.9/const_bool.rs (renamed from tests/expectations/tests/const_bool.rs)0
-rw-r--r--tests/expectations/tests/libclang-3.9/constant-evaluate.rs (renamed from tests/expectations/tests/constant-evaluate.rs)0
-rw-r--r--tests/expectations/tests/libclang-3.9/objc_template.rs18
-rw-r--r--tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs (renamed from tests/expectations/tests/partial-specialization-and-inheritance.rs)0
-rw-r--r--tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs28
-rw-r--r--tests/expectations/tests/libclang-4/auto.rs31
-rw-r--r--tests/expectations/tests/libclang-4/call-conv-field.rs42
-rw-r--r--tests/expectations/tests/libclang-4/const_bool.rs25
-rw-r--r--tests/expectations/tests/libclang-4/constant-evaluate.rs20
-rw-r--r--tests/expectations/tests/libclang-4/objc_template.rs18
-rw-r--r--tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs44
-rw-r--r--tests/expectations/tests/libclang-4/type_alias_template_specialized.rs31
-rwxr-xr-xtests/stylo_sanity.rs4
-rw-r--r--tests/tests.rs27
28 files changed, 537 insertions, 15 deletions
diff --git a/.travis.yml b/.travis.yml
index f66c7d36..f3c48c7d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,16 +17,15 @@ env:
global:
- CARGO_TARGET_DIR=/tmp/bindgen
matrix:
- - LLVM_VERSION=3.7.1 BINDGEN_FEATURES=testing_only_llvm_stable
- - LLVM_VERSION=3.8.1 BINDGEN_FEATURES=testing_only_llvm_stable
- - LLVM_VERSION=3.9.0 BINDGEN_FEATURES=
- - LLVM_VERSION=4.0.0 BINDGEN_FEATURES=
+ - LLVM_VERSION=3.7.1 BINDGEN_FEATURES=testing_only_libclang_3_8
+ - LLVM_VERSION=3.8.1 BINDGEN_FEATURES=testing_only_libclang_3_8
+ - LLVM_VERSION=3.9.0 BINDGEN_FEATURES=testing_only_libclang_3_9
+ - LLVM_VERSION=4.0.0 BINDGEN_FEATURES=testing_only_libclang_4
matrix:
fast_finish: true
allow_failures:
- - env: LLVM_VERSION=4.0.0 BINDGEN_FEATURES=
- - env: LLVM_VERSION=3.7.1 BINDGEN_FEATURES=testing_only_llvm_stable
+ - env: LLVM_VERSION=3.7.1 BINDGEN_FEATURES=testing_only_libclang_3_8
cache:
directories:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 1d78497e..bc5c883d 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -14,7 +14,9 @@ out to us in a GitHub issue, or stop by
- [Testing](#testing)
- [Overview](#overview)
- [Running All Tests](#running-all-tests)
+ - [Running a Single Test](#running-a-single-test)
- [Authoring New Tests](#authoring-new-tests)
+ - [Test Expectations and `libclang` Versions](#test-expectations-and-libclang-versions)
- [Automatic code formatting](#automatic-code-formatting)
- [Generating Graphviz Dot Files](#generating-graphviz-dot-files)
- [Debug Logging](#debug-logging)
@@ -91,9 +93,17 @@ Run `cargo test` to compare generated Rust bindings to the expectations.
### Running All Tests
```
-$ cargo test [--all-features]
+$ cargo test --features testing_only_libclang_$VERSION
```
+Where `$VERSION` is one of:
+
+* `4`
+* `3_9`
+* `3_8`
+
+depending on which version of `libclang` you have installed.
+
### Running a Single Test
To generate bindings for a single test header, compile the bindings, and run the
@@ -124,6 +134,25 @@ Then verify the new Rust bindings compile and pass some basic tests:
$ cargo test -p tests_expectations
```
+### Test Expectations and `libclang` Versions
+
+If a test generates different bindings across different `libclang` versions (for
+example, because we take advantage of better/newer APIs when possible), then you
+can add multiple test expectations, one for each supported `libclang`
+version. Instead of having a single `tests/expectations/tests/my_test.rs` file,
+add each of:
+
+* `tests/expectations/tests/libclang-4/my_test.rs`
+* `tests/expectations/tests/libclang-3.9/my_test.rs`
+* `tests/expectations/tests/libclang-3.8/my_test.rs`
+
+If you need to update the test expectations for a test file that generates
+different bindings for different `libclang` versions, you *don't* need to have
+many version of `libclang` installed locally. Just make a work-in-progress pull
+request, and then when Travis CI fails, it will log a diff of the
+expectations. Use the diff to patch the appropriate expectation file locally and
+then update your pull request.
+
## Automatic code formatting
We use [`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) to enforce a
diff --git a/Cargo.toml b/Cargo.toml
index 8d477662..4dd3fe31 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -77,4 +77,6 @@ static = []
# on bindgen!
testing_only_docs = []
testing_only_extra_assertions = []
-testing_only_llvm_stable = []
+testing_only_libclang_4 = []
+testing_only_libclang_3_9 = []
+testing_only_libclang_3_8 = []
diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml
index 3b1083d4..304d1b0d 100644
--- a/bindgen-integration/Cargo.toml
+++ b/bindgen-integration/Cargo.toml
@@ -11,4 +11,6 @@ bindgen = { path = ".." }
gcc = "0.3"
[features]
-testing_only_llvm_stable = ["bindgen/testing_only_llvm_stable"]
+testing_only_libclang_4 = ["bindgen/testing_only_libclang_4"]
+testing_only_libclang_3_9 = ["bindgen/testing_only_libclang_3_9"]
+testing_only_libclang_3_8 = ["bindgen/testing_only_libclang_3_8"]
diff --git a/src/main.rs b/src/main.rs
index 603a6555..f202cc18 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -31,9 +31,12 @@ pub fn main() {
let bind_args: Vec<_> = env::args().collect();
let version = clang_version();
- let expected_version = if cfg!(feature = "testing_only_llvm_stable") {
+ let expected_version = if cfg!(feature = "testing_only_libclang_4") {
+ (4, 0)
+ } else if cfg!(feature = "testing_only_libclang_3_8") {
(3, 8)
} else {
+ // Default to 3.9.
(3, 9)
};
diff --git a/tests/expectations/tests/libclang-3.8/auto.rs b/tests/expectations/tests/libclang-3.8/auto.rs
new file mode 100644
index 00000000..cf7320f5
--- /dev/null
+++ b/tests/expectations/tests/libclang-3.8/auto.rs
@@ -0,0 +1,34 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Foo {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "_ZN3Foo4kFooE"]
+ pub static Foo_kFoo: bool;
+}
+#[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 ) ));
+}
+impl Clone for Foo {
+ fn clone(&self) -> Self { *self }
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Bar {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "_Z5Test2v"]
+ pub fn Test2() -> ::std::os::raw::c_uint;
+}
diff --git a/tests/expectations/tests/libclang-3.8/call-conv-field.rs b/tests/expectations/tests/libclang-3.8/call-conv-field.rs
new file mode 100644
index 00000000..31fb309c
--- /dev/null
+++ b/tests/expectations/tests/libclang-3.8/call-conv-field.rs
@@ -0,0 +1,42 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Copy)]
+pub struct JNINativeInterface_ {
+ pub GetVersion: ::std::option::Option<unsafe extern "stdcall" fn(env:
+ *mut ::std::os::raw::c_void)
+ -> ::std::os::raw::c_int>,
+ pub __hack: ::std::os::raw::c_ulonglong,
+}
+#[test]
+fn bindgen_test_layout_JNINativeInterface_() {
+ assert_eq!(::std::mem::size_of::<JNINativeInterface_>() , 16usize , concat
+ ! ( "Size of: " , stringify ! ( JNINativeInterface_ ) ));
+ assert_eq! (::std::mem::align_of::<JNINativeInterface_>() , 8usize ,
+ concat ! (
+ "Alignment of " , stringify ! ( JNINativeInterface_ ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const JNINativeInterface_ ) ) . GetVersion as *
+ const _ as usize } , 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( JNINativeInterface_ ) ,
+ "::" , stringify ! ( GetVersion ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const JNINativeInterface_ ) ) . __hack as *
+ const _ as usize } , 8usize , concat ! (
+ "Alignment of field: " , stringify ! ( JNINativeInterface_ ) ,
+ "::" , stringify ! ( __hack ) ));
+}
+impl Clone for JNINativeInterface_ {
+ fn clone(&self) -> Self { *self }
+}
+impl Default for JNINativeInterface_ {
+ fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+}
+extern "C" {
+ #[link_name = "_bar@0"]
+ pub fn bar();
+}
diff --git a/tests/expectations/tests/libclang-3.8/const_bool.rs b/tests/expectations/tests/libclang-3.8/const_bool.rs
new file mode 100644
index 00000000..cc150436
--- /dev/null
+++ b/tests/expectations/tests/libclang-3.8/const_bool.rs
@@ -0,0 +1,34 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+extern "C" {
+ #[link_name = "_ZL1k"]
+ pub static k: bool;
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct A {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "_ZN1A1kE"]
+ pub static A_k: bool;
+}
+#[test]
+fn bindgen_test_layout_A() {
+ assert_eq!(::std::mem::size_of::<A>() , 1usize , concat ! (
+ "Size of: " , stringify ! ( A ) ));
+ assert_eq! (::std::mem::align_of::<A>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( A ) ));
+}
+impl Clone for A {
+ fn clone(&self) -> Self { *self }
+}
+pub type foo = bool;
+extern "C" {
+ #[link_name = "_ZL2k2"]
+ pub static k2: foo;
+}
diff --git a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs
new file mode 100644
index 00000000..9089b442
--- /dev/null
+++ b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs
@@ -0,0 +1,41 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo;
+pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar;
+#[repr(u32)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum _bindgen_ty_1 { foo = 4, bar = 8, }
+pub type EasyToOverflow = ::std::os::raw::c_ulonglong;
+pub const k: EasyToOverflow = 2147483648;
+extern "C" {
+ #[link_name = "k_expr"]
+ pub static k_expr: EasyToOverflow;
+}
+extern "C" {
+ #[link_name = "BAZ"]
+ pub static BAZ: ::std::os::raw::c_longlong;
+}
+extern "C" {
+ #[link_name = "fuzz"]
+ pub static fuzz: f64;
+}
+extern "C" {
+ #[link_name = "BAZZ"]
+ pub static BAZZ: ::std::os::raw::c_char;
+}
+extern "C" {
+ #[link_name = "WAT"]
+ pub static WAT: ::std::os::raw::c_char;
+}
+extern "C" {
+ #[link_name = "bytestring"]
+ pub static mut bytestring: *const ::std::os::raw::c_char;
+}
+extern "C" {
+ #[link_name = "NOT_UTF8"]
+ pub static mut NOT_UTF8: *const ::std::os::raw::c_char;
+}
diff --git a/tests/expectations/tests/objc_template.rs b/tests/expectations/tests/libclang-3.8/objc_template.rs
index 16efa59e..16efa59e 100644
--- a/tests/expectations/tests/objc_template.rs
+++ b/tests/expectations/tests/libclang-3.8/objc_template.rs
diff --git a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs
new file mode 100644
index 00000000..e7e9572f
--- /dev/null
+++ b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs
@@ -0,0 +1,56 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Base {
+ pub _address: u8,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Derived {
+ pub b: bool,
+}
+#[test]
+fn __bindgen_test_layout__bindgen_ty_id_21_instantiation_1() {
+ assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! (
+ "Size of template specialization: " , stringify ! (
+ [u32; 2usize] ) ));
+ assert_eq!(::std::mem::align_of::<[u32; 2usize]>() , 4usize , concat ! (
+ "Alignment of template specialization: " , stringify ! (
+ [u32; 2usize] ) ));
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Usage {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "_ZN5Usage13static_memberE"]
+ pub static mut Usage_static_member: [u32; 2usize];
+}
+#[test]
+fn bindgen_test_layout_Usage() {
+ assert_eq!(::std::mem::size_of::<Usage>() , 1usize , concat ! (
+ "Size of: " , stringify ! ( Usage ) ));
+ assert_eq! (::std::mem::align_of::<Usage>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( Usage ) ));
+}
+extern "C" {
+ #[link_name = "_ZN5UsageC1Ev"]
+ pub fn Usage_Usage(this: *mut Usage);
+}
+impl Clone for Usage {
+ fn clone(&self) -> Self { *self }
+}
+impl Usage {
+ #[inline]
+ pub unsafe fn new() -> Self {
+ let mut __bindgen_tmp = ::std::mem::uninitialized();
+ Usage_Usage(&mut __bindgen_tmp);
+ __bindgen_tmp
+ }
+}
diff --git a/tests/expectations/tests/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs
index 7728ddeb..7728ddeb 100644
--- a/tests/expectations/tests/type_alias_template_specialized.rs
+++ b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs
diff --git a/tests/expectations/tests/auto.rs b/tests/expectations/tests/libclang-3.9/auto.rs
index 70743067..70743067 100644
--- a/tests/expectations/tests/auto.rs
+++ b/tests/expectations/tests/libclang-3.9/auto.rs
diff --git a/tests/expectations/tests/call-conv-field.rs b/tests/expectations/tests/libclang-3.9/call-conv-field.rs
index d6aa9e4e..39943119 100644
--- a/tests/expectations/tests/call-conv-field.rs
+++ b/tests/expectations/tests/libclang-3.9/call-conv-field.rs
@@ -1,7 +1,7 @@
/* automatically generated by rust-bindgen */
-#![allow(non_snake_case)]
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
#[repr(C)]
diff --git a/tests/expectations/tests/const_bool.rs b/tests/expectations/tests/libclang-3.9/const_bool.rs
index fd0273aa..fd0273aa 100644
--- a/tests/expectations/tests/const_bool.rs
+++ b/tests/expectations/tests/libclang-3.9/const_bool.rs
diff --git a/tests/expectations/tests/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs
index ffa3fff8..ffa3fff8 100644
--- a/tests/expectations/tests/constant-evaluate.rs
+++ b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs
diff --git a/tests/expectations/tests/libclang-3.9/objc_template.rs b/tests/expectations/tests/libclang-3.9/objc_template.rs
new file mode 100644
index 00000000..16efa59e
--- /dev/null
+++ b/tests/expectations/tests/libclang-3.9/objc_template.rs
@@ -0,0 +1,18 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+#![cfg(target_os="macos")]
+
+#[macro_use]
+extern crate objc;
+#[allow(non_camel_case_types)]
+pub type id = *mut objc::runtime::Object;
+pub trait Foo {
+ unsafe fn get(self)
+ -> id;
+}
+impl Foo for id {
+ unsafe fn get(self) -> id { msg_send!(self , get) }
+}
diff --git a/tests/expectations/tests/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs
index ec399304..ec399304 100644
--- a/tests/expectations/tests/partial-specialization-and-inheritance.rs
+++ b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs
diff --git a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs
new file mode 100644
index 00000000..7728ddeb
--- /dev/null
+++ b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs
@@ -0,0 +1,28 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Rooted {
+ pub ptr: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_Rooted() {
+ assert_eq!(::std::mem::size_of::<Rooted>() , 4usize , concat ! (
+ "Size of: " , stringify ! ( Rooted ) ));
+ assert_eq! (::std::mem::align_of::<Rooted>() , 4usize , concat ! (
+ "Alignment of " , stringify ! ( Rooted ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const Rooted ) ) . ptr as * const _ as usize }
+ , 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( Rooted ) , "::" ,
+ stringify ! ( ptr ) ));
+}
+impl Clone for Rooted {
+ fn clone(&self) -> Self { *self }
+}
+/// <div rustbindgen replaces="MaybeWrapped"></div>
+pub type MaybeWrapped<a> = a;
diff --git a/tests/expectations/tests/libclang-4/auto.rs b/tests/expectations/tests/libclang-4/auto.rs
new file mode 100644
index 00000000..70743067
--- /dev/null
+++ b/tests/expectations/tests/libclang-4/auto.rs
@@ -0,0 +1,31 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Foo {
+ pub _address: u8,
+}
+pub const Foo_kFoo: bool = true;
+#[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 ) ));
+}
+impl Clone for Foo {
+ fn clone(&self) -> Self { *self }
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Bar {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "_Z5Test2v"]
+ pub fn Test2() -> ::std::os::raw::c_uint;
+}
diff --git a/tests/expectations/tests/libclang-4/call-conv-field.rs b/tests/expectations/tests/libclang-4/call-conv-field.rs
new file mode 100644
index 00000000..39943119
--- /dev/null
+++ b/tests/expectations/tests/libclang-4/call-conv-field.rs
@@ -0,0 +1,42 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Copy)]
+pub struct JNINativeInterface_ {
+ pub GetVersion: ::std::option::Option<unsafe extern "stdcall" fn(env:
+ *mut ::std::os::raw::c_void)
+ -> ::std::os::raw::c_int>,
+ pub __hack: ::std::os::raw::c_ulonglong,
+}
+#[test]
+fn bindgen_test_layout_JNINativeInterface_() {
+ assert_eq!(::std::mem::size_of::<JNINativeInterface_>() , 16usize , concat
+ ! ( "Size of: " , stringify ! ( JNINativeInterface_ ) ));
+ assert_eq! (::std::mem::align_of::<JNINativeInterface_>() , 8usize ,
+ concat ! (
+ "Alignment of " , stringify ! ( JNINativeInterface_ ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const JNINativeInterface_ ) ) . GetVersion as *
+ const _ as usize } , 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( JNINativeInterface_ ) ,
+ "::" , stringify ! ( GetVersion ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const JNINativeInterface_ ) ) . __hack as *
+ const _ as usize } , 8usize , concat ! (
+ "Alignment of field: " , stringify ! ( JNINativeInterface_ ) ,
+ "::" , stringify ! ( __hack ) ));
+}
+impl Clone for JNINativeInterface_ {
+ fn clone(&self) -> Self { *self }
+}
+impl Default for JNINativeInterface_ {
+ fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+}
+extern "stdcall" {
+ #[link_name = "_bar@0"]
+ pub fn bar();
+}
diff --git a/tests/expectations/tests/libclang-4/const_bool.rs b/tests/expectations/tests/libclang-4/const_bool.rs
new file mode 100644
index 00000000..fd0273aa
--- /dev/null
+++ b/tests/expectations/tests/libclang-4/const_bool.rs
@@ -0,0 +1,25 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+pub const k: bool = true;
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct A {
+ pub _address: u8,
+}
+pub const A_k: bool = false;
+#[test]
+fn bindgen_test_layout_A() {
+ assert_eq!(::std::mem::size_of::<A>() , 1usize , concat ! (
+ "Size of: " , stringify ! ( A ) ));
+ assert_eq! (::std::mem::align_of::<A>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( A ) ));
+}
+impl Clone for A {
+ fn clone(&self) -> Self { *self }
+}
+pub type foo = bool;
+pub const k2: foo = true;
diff --git a/tests/expectations/tests/libclang-4/constant-evaluate.rs b/tests/expectations/tests/libclang-4/constant-evaluate.rs
new file mode 100644
index 00000000..ffa3fff8
--- /dev/null
+++ b/tests/expectations/tests/libclang-4/constant-evaluate.rs
@@ -0,0 +1,20 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo;
+pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar;
+#[repr(u32)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum _bindgen_ty_1 { foo = 4, bar = 8, }
+pub type EasyToOverflow = ::std::os::raw::c_ulonglong;
+pub const k: EasyToOverflow = 2147483648;
+pub const k_expr: EasyToOverflow = 0;
+pub const BAZ: ::std::os::raw::c_longlong = 24;
+pub const fuzz: f64 = 51.;
+pub const BAZZ: ::std::os::raw::c_char = 53;
+pub const WAT: ::std::os::raw::c_char = 0;
+pub const bytestring: &'static [u8; 4usize] = b"Foo\x00";
+pub const NOT_UTF8: [u8; 5usize] = [240, 40, 140, 40, 0];
diff --git a/tests/expectations/tests/libclang-4/objc_template.rs b/tests/expectations/tests/libclang-4/objc_template.rs
new file mode 100644
index 00000000..06a9a55f
--- /dev/null
+++ b/tests/expectations/tests/libclang-4/objc_template.rs
@@ -0,0 +1,18 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+#![cfg(target_os="macos")]
+
+#[macro_use]
+extern crate objc;
+#[allow(non_camel_case_types)]
+pub type id = *mut objc::runtime::Object;
+pub trait Foo {
+ unsafe fn get(self)
+ -> *mut ObjectType;
+}
+impl Foo for id {
+ unsafe fn get(self) -> *mut ObjectType { msg_send!(self , get) }
+}
diff --git a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs
new file mode 100644
index 00000000..ec399304
--- /dev/null
+++ b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs
@@ -0,0 +1,44 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Base {
+ pub _address: u8,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct Derived {
+ pub b: bool,
+}
+#[test]
+fn __bindgen_test_layout__bindgen_ty_id_20_instantiation_1() {
+ assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! (
+ "Size of template specialization: " , stringify ! (
+ [u32; 2usize] ) ));
+ assert_eq!(::std::mem::align_of::<[u32; 2usize]>() , 4usize , concat ! (
+ "Alignment of template specialization: " , stringify ! (
+ [u32; 2usize] ) ));
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Usage {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "_ZN5Usage13static_memberE"]
+ pub static mut Usage_static_member: [u32; 2usize];
+}
+#[test]
+fn bindgen_test_layout_Usage() {
+ assert_eq!(::std::mem::size_of::<Usage>() , 1usize , concat ! (
+ "Size of: " , stringify ! ( Usage ) ));
+ assert_eq! (::std::mem::align_of::<Usage>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( Usage ) ));
+}
+impl Clone for Usage {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs
new file mode 100644
index 00000000..e88178cf
--- /dev/null
+++ b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs
@@ -0,0 +1,31 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct Rooted {
+ pub ptr: MaybeWrapped<::std::os::raw::c_int>,
+}
+#[test]
+fn bindgen_test_layout_Rooted() {
+ assert_eq!(::std::mem::size_of::<Rooted>() , 4usize , concat ! (
+ "Size of: " , stringify ! ( Rooted ) ));
+ assert_eq! (::std::mem::align_of::<Rooted>() , 4usize , concat ! (
+ "Alignment of " , stringify ! ( Rooted ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const Rooted ) ) . ptr as * const _ as usize }
+ , 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( Rooted ) , "::" ,
+ stringify ! ( ptr ) ));
+}
+impl Clone for Rooted {
+ fn clone(&self) -> Self { *self }
+}
+impl Default for Rooted {
+ fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+}
+/// <div rustbindgen replaces="MaybeWrapped"></div>
+pub type MaybeWrapped<a> = a;
diff --git a/tests/stylo_sanity.rs b/tests/stylo_sanity.rs
index c75d65a4..c8a8a0d5 100755
--- a/tests/stylo_sanity.rs
+++ b/tests/stylo_sanity.rs
@@ -14,7 +14,9 @@ extern crate bindgen;
#[test]
#[cfg(not(any(debug_assertions,
feature = "testing_only_extra_assertions",
- feature = "testing_only_llvm_stable")))]
+ feature = "testing_only_libclang_3_8")))]
+#[cfg(any(feature = "testing_only_libclang_3_9",
+ feature = "testing_only_libclang_4"))]
fn sanity_check_can_generate_stylo_bindings() {
use std::time::Instant;
diff --git a/tests/tests.rs b/tests/tests.rs
index 1d5d8be0..46f83155 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -26,6 +26,30 @@ fn compare_generated_header(header: &PathBuf,
expected.push(file_name);
expected.set_extension("rs");
+ // If the expectation file doesn't exist, see if we have different test
+ // expectations for different libclang versions.
+ if !expected.is_file() {
+ let file_name = expected.file_name().unwrap().to_owned();
+ expected.pop();
+
+ if cfg!(feature = "testing_only_libclang_4") {
+ expected.push("libclang-4");
+ } else if cfg!(feature = "testing_only_libclang_3_9") {
+ expected.push("libclang-3.9");
+ } else if cfg!(feature = "testing_only_libclang_3_8") {
+ expected.push("libclang-3.8");
+ }
+
+ expected.push(file_name);
+
+ if !expected.is_file() {
+ panic!("missing test expectation file and/or 'testing_only_libclang_$VERSION' \
+ feature for header '{}'; looking for expectation file at '{}'",
+ header.display(),
+ expected.display());
+ }
+ }
+
// We skip the generate() error here so we get a full diff below
let output = match builder.generate() {
Ok(bindings) => bindings.to_string(),
@@ -87,9 +111,6 @@ fn create_bindgen_builder(header: &PathBuf) -> Result<Option<Builder>, Error> {
.and_then(shlex::split)
.unwrap();
flags.extend(extra_flags.into_iter());
- } else if line.contains("bindgen-unstable") &&
- cfg!(feature = "testing_only_llvm_stable") {
- return Ok(None);
} else if line.contains("bindgen-osx-only") {
let prepend_flags = ["--raw-line", "#![cfg(target_os=\"macos\")]"];
flags = prepend_flags.into_iter()