diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 572e1d4598..ceec9b188c 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -65,6 +65,7 @@ use ir::item::Item; use options::BindgenOptions; use parse::ParseError; +use clang_sys::Version; use std::borrow::Cow; use std::collections::hash_map::Entry; use std::env; @@ -644,6 +645,8 @@ pub enum BindgenError { ClangDiagnostic(String), /// Code generation reported an error. Codegen(CodegenError), + /// Clang version is too old. + ClangTooOld(String), } impl std::fmt::Display for BindgenError { @@ -664,6 +667,9 @@ impl std::fmt::Display for BindgenError { BindgenError::Codegen(err) => { write!(f, "codegen error: {}", err) } + BindgenError::ClangTooOld(version) => { + write!(f, "clang is too old, loaded version: {}", version) + } } } } @@ -744,6 +750,21 @@ impl Bindings { ) -> Result { ensure_libclang_is_loaded(); + match clang_sys::get_library().unwrap().version() { + None => { + return Err(BindgenError::ClangTooOld( + "3.4 or earlier".to_string(), + )) + } + Some(version) => { + if version < Version::V9_0 { + return Err(BindgenError::ClangTooOld(format!( + "{version:?}" + ))); + } + } + } + #[cfg(feature = "runtime")] debug!( "Generating bindings, libclang at {}", diff --git a/book/src/requirements.md b/book/src/requirements.md index b701234fad..6553b7c15c 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -7,7 +7,7 @@ This page lists the requirements for running `bindgen` and how to get them. `bindgen` leverages `libclang` to preprocess, parse, and type check C and C++ header files. -It is required to use Clang 5.0 or greater. +It is required to use Clang 9.0 or greater. ### Installing Clang