Rust bindgen "Unable to find libclang" in CI
A crate that runs bindgen at build time could not find libclang. bindgen uses libclang to parse C headers, and a minimal runner has no clang installed, so the build script panics.
What this error means
A -sys crate (or one with a build.rs calling bindgen) fails the custom build command with Unable to find libclang and a list of library names it tried. The pure-Rust crates compile; only the bindgen step fails.
error: failed to run custom build command for `rocksdb-sys v0.6.1`
--- stderr
thread 'main' panicked at 'Unable to find libclang: "couldn't find any
valid shared libraries matching: ['libclang.so', ...]"'Common causes
libclang not installed
bindgen needs the libclang shared library. A slim image without clang/libclang-dev has nothing for it to load.
libclang present but not discoverable
On some distros or macOS the library exists in a non-default path; bindgen cannot find it without LIBCLANG_PATH pointing at the directory.
How to fix it
Install clang and libclang
# Debian/Ubuntu
apt-get update && apt-get install -y clang libclang-dev
# Alpine
apk add --no-cache clang-dev llvm-dev
# RHEL/Fedora
dnf install -y clang clang-develPoint bindgen at libclang explicitly
Set LIBCLANG_PATH if the library lives in a non-standard directory.
export LIBCLANG_PATH="$(llvm-config --libdir)"
cargo build --lockedHow to prevent it
- Bake
clang/libclang-devinto images that build bindgen-based-syscrates. - Set
LIBCLANG_PATHwhen libclang is in a non-standard prefix. - Pin
-syscrate versions so bindgen behavior stays stable.