rust-lang / rust-bindgen

Automatically generates Rust FFI bindings to C (and some C++) libraries.
https://rust-lang.github.io/rust-bindgen/
BSD 3-Clause "New" or "Revised" License
4.39k stars 691 forks source link

Workaround for atomic types #2777

Open lenianiva opened 7 months ago

lenianiva commented 7 months ago

Input C/C++ Header

typedef struct {
    int      m_rc;
    unsigned m_cs_sz:16;
    unsigned m_other:8;
    unsigned m_tag:8;
} lean_object;

static inline _Atomic(int) * lean_get_rc_mt_addr(lean_object* o) {
    return (_Atomic(int)*)(&(o->m_rc));
}

This case is narrowed down from lean.h

Bindgen Invocation

$ bindgen input.h --experimental --wrap-static-fns

Actual Results

When executing the above

panicked at main.rs:52:36:
Unable to generate bindings: Codegen(Serialize { msg: "Cannot serialize type kind Opaque", loc: "builtin definitions" })

Expected Results

The resulting type of lean_get_rc_mt_addr should be a rust atomic.

I've seen https://github.com/rust-lang/rust-bindgen/issues/2151, but is there a workaround of this other than blocklisting the above functions?