rust-lang / rust-lang/rust-bindgen

Define macro type aliases / Custom macro parsing in special use cases

Open
#1,754 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

In working on emscripten-sys, I have a scenario where #define macros are being used as type aliases, which I would like to translate to Rust.

Since I don't think this is a very common pattern, if you don't wish to merge this upstream, I think it could be resolved by somehow allowing the callee to specify custom behavior via ParseCallbacks for macros that bindgen doesn't know how to handle.

Input C/C++ Header

types.h:

#define EMSCRIPTEN_RESULT int
Bindgen Invocation
fn main() {
    let builder = bindgen::builder()
        .header("types.h");

    builder
        .generate()
        .expect("failed to generate rust bindings")
        .write(Box::new(std::io::stdout()))
        .expect("failed to write to file");
}
Actual Results

No bindings are generated.

Expected Results
pub type EMSCRIPTEN_RESULT = c_int;

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 types.h example and the bindgen builder invocation, then read the macro handling and ParseCallbacks areas relevant to custom macro behavior. Done means the #define EMSCRIPTEN_RESULT int case generates a Rust type alias equivalent to pub type EMSCRIPTEN_RESULT = c_int, with coverage for the reported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.