rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Duplicate definitions with forward declared pointer types

Open 7Hazard opened this issue 5 years ago • 1 comments

Input C/C++ Header

CAPI void alt_RotationLayout_CAPI_Free_Forward(struct alt_RotationLayout* ptr);
typedef struct alt_RotationLayout {
    float roll;
    float pitch;
    float yaw;
} alt_RotationLayout;
CAPI void alt_RotationLayout_CAPI_Free(struct alt_RotationLayout* ptr);

Bindgen Invocation

let bindings = bindgen::Builder::default()
        .rustfmt_bindings(true)
        .layout_tests(false)
        .header(format!("./altv-capi-{}-static-{}/include/altv-capi-{}.h", kind, platform, kind))
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .generate()
        .expect("Unable to generate bindings");

    bindings
        .write_to_file(format!("src/altv_{}.rs", kind))
        .expect("Couldn't write bindings!");

Actual Results

/* automatically generated by rust-bindgen 0.54.1 */

pub const true_: u32 = 1;
pub const false_: u32 = 0;
pub const __bool_true_false_are_defined: u32 = 1;
pub type nullptr_t = *mut ::std::os::raw::c_void;
extern "C" {
  pub fn alt_RotationLayout_CAPI_Free_Forward(ptr: *mut alt_RotationLayout);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct alt_RotationLayout {
  pub roll: f32,
  pub pitch: f32,
  pub yaw: f32,
}
extern "C" {
  pub fn alt_RotationLayout_CAPI_Free(ptr: *mut alt_RotationLayout);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct alt_RotationLayout {
  pub _address: u8,
}

Expected Results

No duplicate definitions (when using forward declared pointers).

/* automatically generated by rust-bindgen 0.54.1 */

pub const true_: u32 = 1;
pub const false_: u32 = 0;
pub const __bool_true_false_are_defined: u32 = 1;
pub type nullptr_t = *mut ::std::os::raw::c_void;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
extern "C" {
  pub fn alt_RotationLayout_CAPI_Free_Forward(ptr: *mut alt_RotationLayout);
}
pub struct alt_RotationLayout {
  pub roll: f32,
  pub pitch: f32,
  pub yaw: f32,
}
extern "C" {
  pub fn alt_RotationLayout_CAPI_Free(ptr: *mut alt_RotationLayout);
}

7Hazard avatar Aug 09 '20 00:08 7Hazard

Isn't this somewhat related to https://github.com/rust-lang/rust-bindgen/issues/2227 ?

pvdrz avatar Sep 21 '22 20:09 pvdrz