KyleMayes / clang-sys

Rust bindings for libclang.
Apache License 2.0
128 stars 65 forks source link

"This crate only supports `libclang` 3.5 and later" with libclang 3.8 identified #163

Closed ydirson closed 1 month ago

ydirson commented 7 months ago

In a nuber f situations, eg. https://gitlab.com/xen-project/xen-guest-agent/-/jobs/5550556953 I find the following confusing error message:

  A `libclang` function was called that is not supported by the loaded `libclang` instance.

      called function = `clang_getTranslationUnitTargetInfo`
      loaded `libclang` instance = 3.8.x

  This crate only supports `libclang` 3.5 and later.

There is obviously a problem with the environment, but the error message is obviously wrong.

Digging with this little debug patch:

diff --git a/src/link.rs b/src/link.rs
index 07c4be3..3ae29de 100644
--- a/src/link.rs
+++ b/src/link.rs
@@ -173,6 +173,7 @@ macro_rules! link {
             pub unsafe fn $name($($pname: $pty), *) $(-> $ret)* {
                 let f = with_library(|library| {
                     if let Some(function) = library.functions.$name {
+                        eprintln!("found {} in {:?}", stringify!($name), library.path);
                         function
                     } else {
                         panic!(

... I see:

  --- stdout
  cargo:rustc-link-lib=xenstore

  --- stderr
  found clang_createIndex in "/usr/lib/llvm-3.8/lib/libclang-3.8.0.so"
  found clang_parseTranslationUnit in "/usr/lib/llvm-3.8/lib/libclang-3.8.0.so"
  thread 'main' panicked at /data/src/clang-sys/src/lib.rs:1735:1:

  A `libclang` function was called that is not supported by the loaded `libclang` instance.

      called function = `clang_getTranslationUnitTargetInfo`
      loaded `libclang` instance = 3.8.x

  This crate only supports `libclang` 3.5 and later.
  The minimum `libclang` requirement for this particular function can be found here:
  https://docs.rs/clang-sys/latest/clang_sys/clang_getTranslationUnitTargetInfo/index.html

  Instructions for installing `libclang` can be found here:
  https://rust-lang.github.io/rust-bindgen/requirements.html

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  found clang_disposeTranslationUnit in "/usr/lib/llvm-3.8/lib/libclang-3.8.0.so"
  found clang_disposeIndex in "/usr/lib/llvm-3.8/lib/libclang-3.8.0.so"

And in fact:

$ nm -D /usr/lib/llvm-3.8/lib/libclang-3.8.0.so | grep clang_getTranslationUnitTargetInfo
$

That Ubuntu 16.04.7 LTS would seem to have a funky libclang?

ydirson commented 7 months ago

Note that Debian 9 (2017) also has 3.8 and shows the same error message.

KyleMayes commented 6 months ago

The error message is correct:

The remainder of the error message links to the documentation for the function which should have a comment indicating the minimum version of Clang required for that function.

All that being said, I can see how the presence of This crate only supports libclang 3.5 and later. in the error message could be a bit misleading, I will look into improving the error message further.