rust-lang / rust-lang/rust-bindgen

#define + sizeof(...) fails to emit constant

Open
#666 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Not sure if I'm missing a feature that's not supported yet but I hit issue and narrowed it down when trying to generate bindings for Lua.

Input C/C++ Header
#define SIZEOF_INT sizeof(int)
Bindgen Invokation
    bindgen::Builder::default()
        .header("test.h")
        .generate().unwrap()
        .write_to_file("src/out.rs").unwrap();
Actual Results
/* automatically generated by rust-bindgen */



Expected Results
RUST_LOG=bindgen Output
No logging emitted when I set env var

Full repro repo also exists here for easier debugging: https://github.com/vvanders/bindgen_repro

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 issue from the test.h header using the bindgen::Builder invocation shown, then inspect the generated src/out.rs. Compare the empty output with the expected SIZEOF_INT constant and use the RUST_LOG=bindgen result as a debugging check. Done means the sizeof macro is emitted as a constant in the generated bindings.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.