rust-lang / rust-lang/rust-bindgen

`header_contents` requires providing a header file extension in `name` argument

Open
#2,975 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

The below code fails because the name provided to the header_contents method doesn't have a valid c header file extension:

fn main() {
    bindgen::builder()
        .header_contents("input", "") // empty header
        .generate()
        .expect("Unable to generate bindings");
}

The docs don't mention this requirement and the error it creates doesn't actually say that this is the problem:

thread 'main' panicked at D:\.tools\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bindgen-0.69.4\ir\context.rs:556:15:
  libclang error; possible causes include:
  - Invalid flag syntax
  - Unrecognized flags
  - Invalid flag arguments
  - File I/O errors
  - Host vs. target architecture mismatch
  If you encounter an error missing from this list, please file an issue or a PR!
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I assumed that since the argument was name and since the docs didn't mention anything, that it would automatically append an appropriate file extension. I think the error should probably be updated and the docs too maybe.

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

Start with the Builder::header_contents documentation and the failure reported at ir/context.rs:556. Reproduce the example using an empty header and the name "input" to confirm the behavior and message. Done means the extension requirement is documented and the resulting error clearly identifies this problem.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.