rust-lang / rust-lang/rust-bindgen

bindgen panics with "header not found" message if Clang version is too old

Open
#3,171 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

bindgen crate doesn't clearly states Clang version is too old. Build fails with <header> not found error. See iai-callgrind issue.

Steps to reproduce:

  1. On Ubuntu 18.04 install libclang-6.0-dev, remove all other libclang versions if any
  2. Follow tutorial to create a sample project
  3. Build project using cargo build

Expected result: error message about too old Clang version

Actual result: 'stddef.h' file not found error:

# cargo build
   Compiling t v0.1.0 (/root/t)
error: failed to run custom build command for `t v0.1.0 (/root/t)`

Caused by:
  process didn't exit successfully: `/root/t/target/debug/build/t-fc2313a9f8a632f7/build-script-build` (exit status: 101)
  --- stdout
  cargo:rustc-link-search=/path/to/lib
  cargo:rustc-link-lib=bz2
  cargo:rerun-if-env-changed=TARGET
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
  cargo:rerun-if-changed=wrapper.h

  --- stderr
  /usr/include/stdio.h:33:10: fatal error: 'stddef.h' file not found

  thread 'main' panicked at build.rs:25:10:
  Unable to generate bindings: ClangDiagnostic("/usr/include/stdio.h:33:10: fatal error: 'stddef.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Upgrading Clang to version 9 solves the issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with Ubuntu 18.04 and libclang-6.0-dev, following the tutorial and using the reported wrapper.h and build.rs:25 context. Inspect how the build currently reports Clang diagnostics; done when an unsupported old Clang installation produces a clear version-related error instead of only reporting that stddef.h is missing.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.