From 03105052276ab685c89200dcbccb708700aae0f1 Mon Sep 17 00:00:00 2001 From: Christiaan Biesterbosch Date: Mon, 16 Sep 2024 19:34:35 +0200 Subject: [PATCH] Require libclang 9.0 or newer Adds a check for the loaded libclang version and logs a warning if the version is unsupported. Will not print a warning if libclang is statically linked. --- bindgen/lib.rs | 12 ++++++++++++ book/src/requirements.md | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 572e1d4598..1a9932b534 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -744,6 +744,18 @@ impl Bindings { ) -> Result { ensure_libclang_is_loaded(); + #[cfg(feature = "runtime")] + match clang_sys::get_library().unwrap().version() { + None => { + warn!("Could not detect a Clang version, make sure you are using libclang 9 or newer"); + } + Some(version) => { + if version < clang_sys::Version::V9_0 { + warn!("Detected Clang version {version:?} which is unsupported and can cause invalid code generation, use libclang 9 or newer"); + } + } + } + #[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