rust-lang / rust-lang/rust-bindgen
Bindings for headers using rust-style integer aliases are awkward
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the case from bindgen.h with the shown bindgen::builder invocation, using the u16 alias and meow declaration. Trace how the generated Rust alias and function signature are produced, then add coverage showing that this alias can yield the expected u16 parameter without the workaround; done means the generated binding uses the requested spelling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp, rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100