Skip to content

Commit

Permalink
Require libclang 9.0 or newer
Browse files Browse the repository at this point in the history
Adds a check for the loaded libclang version and returns an error
if the version is unsupported.
  • Loading branch information
Kriskras99 committed Sep 16, 2024
1 parent f518815 commit b07799e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
}
Expand Down Expand Up @@ -744,6 +750,21 @@ impl Bindings {
) -> Result<Bindings, BindgenError> {
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 {}",
Expand Down
2 changes: 1 addition & 1 deletion book/src/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b07799e

Please sign in to comment.