Skip to content

Commit fc29b51

Browse files
author
bors-servo
authored
Auto merge of #335 - emilio:dlopen, r=<try>
[rfc] Use a dynamically loaded clang to do as much as we can with old clang versions, and experiment with new ones. It's a pity that we don't support clang 3.7 and similar for generating C bindings, when it should be straight-forward. This change should allow us to support older clang versions, and also experiment with pre-release clang APIs if needed. This depends on: KyleMayes/clang-sys#44
2 parents 861e3ce + 6c565fd commit fc29b51

File tree

5 files changed

+17
-36
lines changed

5 files changed

+17
-36
lines changed

bindgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ version = "0.17.0"
1515
workspace = ".."
1616

1717
[dependencies]
18-
clang-sys = "0.11.1"
18+
clang-sys = "0.12"
1919
clap = "2"
2020
libbindgen = { path = "../libbindgen" }
2121
log = "0.3"

libbindgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ quasi_codegen = "0.26"
2626
[dependencies]
2727
cexpr = "0.2"
2828
cfg-if = "0.1.0"
29-
clang-sys = { version = "0.11.1", features = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9"] }
29+
clang-sys = { version = "0.12", features = ["runtime", "clang_3_9"] }
3030
lazy_static = "0.2.1"
3131
libc = "0.2"
3232
rustc-serialize = "0.3.19"

libbindgen/src/clang.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -349,19 +349,9 @@ impl Cursor {
349349
}
350350

351351
/// Is the referent an inlined function?
352-
#[cfg(not(feature="llvm_stable"))]
353352
pub fn is_inlined_function(&self) -> bool {
354-
unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 }
355-
}
356-
357-
// TODO: Remove this when LLVM 3.9 is released.
358-
//
359-
// This is currently used for CI purposes.
360-
361-
/// Is the referent an inlined function?
362-
#[cfg(feature="llvm_stable")]
363-
pub fn is_inlined_function(&self) -> bool {
364-
false
353+
clang_Cursor_isFunctionInlined::is_loaded() &&
354+
unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 }
365355
}
366356

367357
/// Get the width of this cursor's referent bit field, or `None` if the
@@ -762,7 +752,6 @@ impl Type {
762752

763753
/// For elaborated types (types which use `class`, `struct`, or `union` to
764754
/// disambiguate types from local bindings), get the underlying type.
765-
#[cfg(not(feature="llvm_stable"))]
766755
pub fn named(&self) -> Type {
767756
unsafe {
768757
Type {
@@ -1306,28 +1295,13 @@ pub struct EvalResult {
13061295
x: CXEvalResult,
13071296
}
13081297

1309-
#[cfg(feature = "llvm_stable")]
1310-
impl EvalResult {
1311-
/// Create a dummy EvalResult.
1312-
pub fn new(_: Cursor) -> Option<Self> {
1313-
None
1314-
}
1315-
1316-
/// Not useful in llvm 3.8.
1317-
pub fn as_double(&self) -> Option<f64> {
1318-
None
1319-
}
1320-
1321-
/// Not useful in llvm 3.8.
1322-
pub fn as_int(&self) -> Option<i32> {
1323-
None
1324-
}
1325-
}
1326-
1327-
#[cfg(not(feature = "llvm_stable"))]
13281298
impl EvalResult {
13291299
/// Evaluate `cursor` and return the result.
13301300
pub fn new(cursor: Cursor) -> Option<Self> {
1301+
if !clang_Cursor_Evaluate::is_loaded() {
1302+
return None;
1303+
}
1304+
13311305
// Clang has an internal assertion we can trigger if we try to evaluate
13321306
// a cursor containing a variadic template type reference. Triggering
13331307
// the assertion aborts the process, and we don't want that. Clang
@@ -1379,7 +1353,6 @@ impl EvalResult {
13791353
}
13801354
}
13811355

1382-
#[cfg(not(feature = "llvm_stable"))]
13831356
impl Drop for EvalResult {
13841357
fn drop(&mut self) {
13851358
unsafe { clang_EvalResult_dispose(self.x) };

libbindgen/src/ir/ty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,6 @@ impl Type {
854854
.expect("Not able to resolve array element?");
855855
TypeKind::Array(inner, ty.num_elements().unwrap())
856856
}
857-
#[cfg(not(feature="llvm_stable"))]
858857
CXType_Elaborated => {
859858
return Self::from_clang_ty(potential_id,
860859
&ty.named(),

libbindgen/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ impl<'ctx> Bindings<'ctx> {
511511
span: Option<Span>)
512512
-> Result<Bindings<'ctx>, ()> {
513513
let span = span.unwrap_or(DUMMY_SP);
514+
if !clang_sys::is_loaded() {
515+
// TODO(emilio): Return meaningful error (breaking).
516+
clang_sys::load().expect("Unable to find libclang");
517+
}
514518

515519
// TODO: Make this path fixup configurable?
516520
if let Some(clang) = clang_sys::support::Clang::find(None) {
@@ -691,6 +695,11 @@ pub struct ClangVersion {
691695

692696
/// Get the major and the minor semvar numbers of Clang's version
693697
pub fn clang_version() -> ClangVersion {
698+
if !clang_sys::is_loaded() {
699+
// TODO(emilio): Return meaningful error (breaking).
700+
clang_sys::load().expect("Unable to find libclang");
701+
}
702+
694703
let raw_v: String = clang::extract_clang_version();
695704
let split_v: Option<Vec<&str>> = raw_v.split_whitespace()
696705
.nth(2)

0 commit comments

Comments
 (0)