Skip to content

Bindings for headers using rust-style integer aliases are awkward #2256

Open
@LunarLambda

Description

@LunarLambda

Input C/C++ Header

#include <stdint.h>

typedef u16 uint16_t;

extern void meow(u16 a);

Bindgen Invocation

bindgen::builder()
        .header("bindgen.h")
        .generate()
        .unwrap()

Actual Results

/* snip */

pub type u16_ = u16;

extern "C" {
    pub fn meow(a: u16_);
}

Expected Results

There doesn't appear to be an easy way for this to simply become:

extern "C" {
    pub fn meow(a: u16);
}

As renaming via ParseCallbacks doesn't appear to work.

It'd be highly unfortunate to have to hack around it like this:

// Pretend we already included the header with the type aliases
#define _LIB_TYPES_H
#include <stdint.h>

// Do the alias in the preprocessor instead
#define u16 uint16_t

// Include the actual header
#include <lib.h>

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