diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/bin/bindgen.rs | 15 | ||||
-rwxr-xr-x | src/clang.rs | 5 | ||||
-rwxr-xr-x | src/lib.rs | 34 |
3 files changed, 53 insertions, 1 deletions
diff --git a/src/bin/bindgen.rs b/src/bin/bindgen.rs index 17385d85..2127ea49 100755 --- a/src/bin/bindgen.rs +++ b/src/bin/bindgen.rs @@ -8,7 +8,7 @@ extern crate log; extern crate clang_sys; extern crate rustc_serialize; -use bindgen::{BindgenOptions, Bindings, LinkType}; +use bindgen::{BindgenOptions, Bindings, LinkType, ClangVersion, clang_version}; use std::default::Default; use std::env; use std::fs; @@ -232,6 +232,19 @@ pub fn main() { let mut bind_args: Vec<_> = env::args().collect(); + let version = clang_version(); + let expected_version = if cfg!(feature = "llvm_stable") { (3,8) } else { (3,9) }; + + info!("Clang Version: {}", version.full); + + match version.parsed { + None => warn!("Couldn't parse libclang version"), + Some(version) if version != expected_version => { + error!("Using clang {:?}, expected {:?}", version, expected_version); + } + _ => {} + } + if let Some(clang) = clang_sys::support::Clang::find(None) { let has_clang_args = bind_args.iter().rposition(|arg| *arg == "--").is_some(); diff --git a/src/clang.rs b/src/clang.rs index 18216125..b335a585 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -1175,3 +1175,8 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> Enum_CXVisitorResult { print_indent(depth, ")"); CXChildVisit_Continue } + +/// Try to extract the clang version to a string +pub fn extract_clang_version() -> String { + unsafe { clang_getClangVersion().into() } +} @@ -491,3 +491,37 @@ fn parse(context: &mut BindgenContext) { assert!(context.current_module() == context.root_module(), "How did this happen?"); } + +/// Extracted Clang version data +#[derive(Debug)] +pub struct ClangVersion { + /// Major and minor semvar, if parsing was successful + pub parsed: Option<(u32,u32)>, + /// full version string + pub full: String, +} + +/// Get the major and the minor semvar numbers of Clang's version +pub fn clang_version() -> ClangVersion { + let raw_v: String = clang::extract_clang_version(); + let split_v: Option<Vec<&str>> = raw_v + .split_whitespace() + .nth(2) + .map(|v| v.split('.').collect()); + match split_v { + Some(v) => { + if v.len() >= 2 { + let maybe_major = v[0].parse::<u32>(); + let maybe_minor = v[1].parse::<u32>(); + match (maybe_major,maybe_minor) { + (Ok(major),Ok(minor)) => return ClangVersion { parsed: Some((major,minor)), full: raw_v.clone() }, + _ => {}, + } + } + }, + None => {}, + }; + ClangVersion { parsed: None, full: raw_v.clone() } +} + + |