Skip to content

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

@agausmann

Description

@agausmann

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;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions