Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for clang below version 3.9 #1830

Merged
merged 6 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ env:
- LLVM_VERSION="9.0" BINDGEN_JOB="msrv"

# General matrix.
- LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE=
- LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
- LLVM_VERSION="3.8" BINDGEN_JOB="integration" BINDGEN_PROFILE=
- LLVM_VERSION="3.8" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release"
- LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime"
- LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime"

- LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE=
- LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
- LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE=
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@ testing_only_libclang_9 = []
testing_only_libclang_5 = []
testing_only_libclang_4 = []
testing_only_libclang_3_9 = []
testing_only_libclang_3_8 = []
1 change: 0 additions & 1 deletion bindgen-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"]
testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"]
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"]
62 changes: 10 additions & 52 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,13 @@ impl Cursor {

/// Get the mangled name of this cursor's referent.
pub fn mangling(&self) -> String {
if clang_Cursor_getMangling::is_loaded() {
unsafe { cxstring_into_string(clang_Cursor_getMangling(self.x)) }
} else {
self.spelling()
}
unsafe { cxstring_into_string(clang_Cursor_getMangling(self.x)) }
}

/// Gets the C++ manglings for this cursor, or an error if the function is
/// not loaded or the manglings are not available.
/// Gets the C++ manglings for this cursor, or an error if the manglings
/// are not available.
pub fn cxx_manglings(&self) -> Result<Vec<String>, ()> {
use clang_sys::*;
if !clang_Cursor_getCXXManglings::is_loaded() {
return Err(());
}
unsafe {
let manglings = clang_Cursor_getCXXManglings(self.x);
if manglings.is_null() {
Expand Down Expand Up @@ -240,14 +233,8 @@ impl Cursor {
}

/// Is this Cursor pointing to a function-like macro definition?
/// Returns None if this cannot be determined with the available libclang
/// (it requires 3.9 or greater).
pub fn is_macro_function_like(&self) -> Option<bool> {
if clang_Cursor_isMacroFunctionLike::is_loaded() {
Some(unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 })
} else {
None
}
pub fn is_macro_function_like(&self) -> bool {
unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 }
}

/// Get the kind of referent this cursor is pointing to.
Expand Down Expand Up @@ -480,8 +467,7 @@ impl Cursor {

/// Is the referent an inlined function?
pub fn is_inlined_function(&self) -> bool {
clang_Cursor_isFunctionInlined::is_loaded() &&
unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 }
unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 }
}

/// Get the width of this cursor's referent bit field, or `None` if the
Expand Down Expand Up @@ -592,11 +578,7 @@ impl Cursor {

/// Get the visibility of this cursor's referent.
pub fn visibility(&self) -> CXVisibilityKind {
if clang_getCursorVisibility::is_loaded() {
unsafe { clang_getCursorVisibility(self.x) }
} else {
CXVisibility_Default
}
unsafe { clang_getCursorVisibility(self.x) }
}

/// Given that this cursor's referent is a function, return cursors to its
Expand Down Expand Up @@ -641,16 +623,11 @@ impl Cursor {
/// Is this cursor's referent a field declaration that is marked as
/// `mutable`?
pub fn is_mutable_field(&self) -> bool {
clang_CXXField_isMutable::is_loaded() &&
unsafe { clang_CXXField_isMutable(self.x) != 0 }
unsafe { clang_CXXField_isMutable(self.x) != 0 }
}

/// Get the offset of the field represented by the Cursor.
pub fn offset_of_field(&self) -> Result<usize, LayoutError> {
if !clang_Cursor_getOffsetOfField::is_loaded() {
return Err(LayoutError::from(-1));
}

let offset = unsafe { clang_Cursor_getOffsetOfField(self.x) };

if offset < 0 {
Expand Down Expand Up @@ -1117,13 +1094,6 @@ impl Type {
/// Get the number of template arguments this type has, or `None` if it is
/// not some kind of template.
pub fn num_template_args(&self) -> Option<u32> {
// If an old libclang is loaded, we have no hope of answering this
// question correctly. However, that's no reason to panic when
// generating bindings for simple C headers with an old libclang.
if !clang_Type_getNumTemplateArguments::is_loaded() {
return None;
}

let n = unsafe { clang_Type_getNumTemplateArguments(self.x) };
if n >= 0 {
Some(n as u32)
Expand Down Expand Up @@ -1253,11 +1223,7 @@ impl Type {
pub fn named(&self) -> Type {
unsafe {
Type {
x: if clang_Type_getNamedType::is_loaded() {
clang_Type_getNamedType(self.x)
} else {
self.x
},
x: clang_Type_getNamedType(self.x),
}
}
}
Expand Down Expand Up @@ -1867,11 +1833,7 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
format!(" {}spelling = \"{}\"", prefix, ty.spelling()),
);
let num_template_args =
if clang_Type_getNumTemplateArguments::is_loaded() {
unsafe { clang_Type_getNumTemplateArguments(ty.x) }
} else {
-1
};
unsafe { clang_Type_getNumTemplateArguments(ty.x) };
if num_template_args >= 0 {
print_indent(
depth,
Expand Down Expand Up @@ -1968,10 +1930,6 @@ pub struct EvalResult {
impl EvalResult {
/// Evaluate `cursor` and return the result.
pub fn new(cursor: Cursor) -> Option<Self> {
if !clang_Cursor_Evaluate::is_loaded() {
return None;
}

// Work around https://bugs.llvm.org/show_bug.cgi?id=42532, see:
// * https://github.com/rust-lang/rust-bindgen/issues/283
// * https://github.com/rust-lang/rust-bindgen/issues/1590
Expand Down
29 changes: 4 additions & 25 deletions src/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,10 @@ fn handle_function_macro(
tokens: &[ClangToken],
callbacks: &dyn crate::callbacks::ParseCallbacks,
) -> Result<(), ParseError> {
fn is_abutting(a: &ClangToken, b: &ClangToken) -> bool {
unsafe {
clang_sys::clang_equalLocations(
clang_sys::clang_getRangeEnd(a.extent),
clang_sys::clang_getRangeStart(b.extent),
) != 0
}
}

let is_functional_macro =
// If we have libclang >= 3.9, we can use `is_macro_function_like()` and
// avoid checking for abutting tokens ourselves.
cursor.is_macro_function_like().unwrap_or_else(|| {
// If we cannot get a definitive answer from clang, we instead check
// for a parenthesis token immediately adjacent to (that is,
// abutting) the first token in the macro definition.
// TODO: Once we don't need the fallback check here, we can hoist
// the `is_macro_function_like` check into this function's caller,
// and thus avoid allocating the `tokens` vector for non-functional
// macros.
match tokens.get(0..2) {
Some([a, b]) => is_abutting(&a, &b) && b.spelling() == b"(",
_ => false,
}
});
// TODO: Hoist the `is_macro_function_like` check into this function's
// caller, and thus avoid allocating the `tokens` vector for non-functional
// macros.
let is_functional_macro = cursor.is_macro_function_like();

if !is_functional_macro {
return Ok(());
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ fn clang_version_check() {
Some((4, 0))
} else if cfg!(feature = "testing_only_libclang_3_9") {
Some((3, 9))
} else if cfg!(feature = "testing_only_libclang_3_8") {
Some((3, 8))
} else {
None
};
Expand Down
1 change: 0 additions & 1 deletion tests/expectations/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::io::Write;
use std::path::Path;

const LIBCLANG_VERSION_DIRS: &'static [&'static str] = &[
"libclang-3.8",
"libclang-3.9",
"libclang-4",
"libclang-5",
Expand Down
15 changes: 0 additions & 15 deletions tests/expectations/tests/libclang-3.8/abi_variadic_function.rs

This file was deleted.

38 changes: 0 additions & 38 deletions tests/expectations/tests/libclang-3.8/auto.rs

This file was deleted.

61 changes: 0 additions & 61 deletions tests/expectations/tests/libclang-3.8/call-conv-field.rs

This file was deleted.

38 changes: 0 additions & 38 deletions tests/expectations/tests/libclang-3.8/const_bool.rs

This file was deleted.

Loading