rust-lang / rust-lang/rust-bindgen

panicked with `test.h`, but ok with `__binding.i`

Open
#1,471 8 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

Input C/C++ Header
#include <stdint.h>
const uint32_t test = 123;
Bindgen Invocation
$ bindgen test.h
Actual Results
test.h:5:7: error: unknown type name 'uint32_t'
test.h:5:7: error: unknown type name 'uint32_t', err: true
thread 'main' panicked at 'Unable to generate bindings: ()', libcore/result.rs:1009:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Expected Results

generating __binding.i file instead it works:

First generate __binding.i file using -dump-preprocessed-input

$ bindgen --dump-preprocessed-input test.h
test.h:2:7: error: unknown type name 'uint32_t'
test.h:2:7: error: unknown type name 'uint32_t', err: true
thread 'main' panicked at 'Unable to generate bindings: ()', libcore/result.rs:1009:5

and than:

$ bindgen __bindgen.i
warning: argument unused during compilation: '-isystem /usr/local/include' [-Wunused-command-line-argument], err: false
warning: argument unused during compilation: '-isystem /usr/local/Cellar/llvm@3.7/3.7.1/lib/llvm-3.7/bin/../lib/clang/3.7.1/include' [-Wunused-command-line-argument], err: false
warning: argument unused during compilation: '-isystem /System/Library/Frameworks' [-Wunused-command-line-argument], err: false
warning: argument unused during compilation: '-isystem /Library/Frameworks' [-Wunused-command-line-argument], err: false
/* automatically generated by rust-bindgen */

pub type int_least64_t = i64;
pub type uint_least64_t = u64;
pub type int_fast64_t = i64;
pub type uint_fast64_t = u64;
pub type int_least32_t = i32;
pub type uint_least32_t = u32;
pub type int_fast32_t = i32;
pub type uint_fast32_t = u32;
pub type int_least16_t = i16;
pub type uint_least16_t = u16;
pub type int_fast16_t = i16;
pub type uint_fast16_t = u16;
pub type int_least8_t = i8;
pub type uint_least8_t = u8;
pub type int_fast8_t = i8;
pub type uint_fast8_t = u8;
pub type intmax_t = ::std::os::raw::c_long;
pub type uintmax_t = ::std::os::raw::c_ulong;
pub const test: u32 = 123;

thanks

$ bindgen --version
bindgen 0.45.0
$ uname -a
Darwin MacBook-Pro.local 18.2.0 Darwin Kernel Version 18.2.0: Fri Oct  5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64

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 report with test.h and bindgen 0.45.0, then compare direct processing with the --dump-preprocessed-input flow. Trace how uint32_t from <stdint.h> is handled before the panic; done means bindgen processes test.h without unknown-type errors or a panic and generates the expected u32 constant.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp, rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.