Skip to content

0.72.1: generated pointer size is wrong on RISC V target #3294

@finalyards

Description

@finalyards

Output of ’bindgen-cli’ changes between 0.72.0 and 0.72.1 releases.

On ESP32-C6 (target riscv32imac-unknown-none-elf), bind-gen 0.72.0 creates 4-byte pointers (correct).

On same, 0.72.1 creates 8-byte pointers (incorrect).

C structure to bind:

typedef struct
{
	/* Platform, filled by customer into the 'platform.h' file */
	VL53L8CX_Platform	platform;
	/* Results streamcount, value auto-incremented at each range */
	uint8_t		        streamcount;
	/* Size of data read though I2C */
	uint32_t	        data_read_size;
	/* Address of default configuration buffer */
	uint8_t		        *default_configuration;
	/* Address of default Xtalk buffer */
	uint8_t		        *default_xtalk;
	/* Offset buffer */
	uint8_t		        offset_data[VL53L8CX_OFFSET_BUFFER_SIZE];
	/* Xtalk buffer */
	uint8_t		        xtalk_data[VL53L8CX_XTALK_BUFFER_SIZE];
	/* Temporary buffer used for internal driver processing */
	uint8_t		        temp_buffer[VL53L8CX_TEMPORARY_BUFFER_SIZE];
	/* Auto-stop flag for stopping the sensor */
	uint8_t				is_auto_stop_enabled;
} VL53L8CX_Configuration;

Binding (0.72.0):

#[doc = " @brief Structure VL_Configuration contains the sensor configuration.\n User MUST not manually change these fields."]
#[repr(C)]
#[derive(Debug)]
pub struct VL_Configuration {
    pub platform: VL_Platform,
    pub streamcount: u8,
    pub data_read_size: u32,
    pub default_configuration: *mut u8,
    pub default_xtalk: *mut u8,
    pub offset_data: [u8; 488usize],
    pub xtalk_data: [u8; 776usize],
    pub temp_buffer: [u8; 1024usize],
    pub is_auto_stop_enabled: u8,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of VL_Configuration"][::core::mem::size_of::<VL_Configuration>() - 2360usize];
    ["Alignment of VL_Configuration"][::core::mem::align_of::<VL_Configuration>() - 8usize];
    ["Offset of field: VL_Configuration::platform"]
        [::core::mem::offset_of!(VL_Configuration, platform) - 0usize];
    ["Offset of field: VL_Configuration::streamcount"]
        [::core::mem::offset_of!(VL_Configuration, streamcount) - 48usize];
    ["Offset of field: VL_Configuration::data_read_size"]
        [::core::mem::offset_of!(VL_Configuration, data_read_size) - 52usize];
    ["Offset of field: VL_Configuration::default_configuration"]
        [::core::mem::offset_of!(VL_Configuration, default_configuration) - 56usize];
    ["Offset of field: VL_Configuration::default_xtalk"]
        [::core::mem::offset_of!(VL_Configuration, default_xtalk) - 60usize];   // <— correct: +4
    ["Offset of field: VL_Configuration::offset_data"]
        [::core::mem::offset_of!(VL_Configuration, offset_data) - 64usize];   // <— correct: +4
    ["Offset of field: VL_Configuration::xtalk_data"]
        [::core::mem::offset_of!(VL_Configuration, xtalk_data) - 552usize];
    ["Offset of field: VL_Configuration::temp_buffer"]
        [::core::mem::offset_of!(VL_Configuration, temp_buffer) - 1328usize];
    ["Offset of field: VL_Configuration::is_auto_stop_enabled"]
        [::core::mem::offset_of!(VL_Configuration, is_auto_stop_enabled) - 2352usize];
};

Binding on 0.72.1:

#[doc = " @brief Structure VL_Configuration contains the sensor configuration.\n User MUST not manually change these fields."]
#[repr(C)]
#[derive(Debug)]
pub struct VL_Configuration {
    pub platform: VL_Platform,
    pub streamcount: u8,
    pub data_read_size: u32,
    pub default_configuration: *mut u8,
    pub default_xtalk: *mut u8,
    pub offset_data: [u8; 488usize],
    pub xtalk_data: [u8; 776usize],
    pub temp_buffer: [u8; 1024usize],
    pub is_auto_stop_enabled: u8,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of VL_Configuration"][::core::mem::size_of::<VL_Configuration>() - 2368usize];
    ["Alignment of VL_Configuration"][::core::mem::align_of::<VL_Configuration>() - 8usize];
    ["Offset of field: VL_Configuration::platform"]
        [::core::mem::offset_of!(VL_Configuration, platform) - 0usize];
    ["Offset of field: VL_Configuration::streamcount"]
        [::core::mem::offset_of!(VL_Configuration, streamcount) - 48usize];
    ["Offset of field: VL_Configuration::data_read_size"]
        [::core::mem::offset_of!(VL_Configuration, data_read_size) - 52usize];
    ["Offset of field: VL_Configuration::default_configuration"]
        [::core::mem::offset_of!(VL_Configuration, default_configuration) - 56usize];
    ["Offset of field: VL_Configuration::default_xtalk"]
        [::core::mem::offset_of!(VL_Configuration, default_xtalk) - 64usize];   // <— wrong: +8
    ["Offset of field: VL_Configuration::offset_data"]
        [::core::mem::offset_of!(VL_Configuration, offset_data) - 72usize];   // <— wrong: +8
    ["Offset of field: VL_Configuration::xtalk_data"]
        [::core::mem::offset_of!(VL_Configuration, xtalk_data) - 560usize];
    ["Offset of field: VL_Configuration::temp_buffer"]
        [::core::mem::offset_of!(VL_Configuration, temp_buffer) - 1336usize];
    ["Offset of field: VL_Configuration::is_auto_stop_enabled"]
        [::core::mem::offset_of!(VL_Configuration, is_auto_stop_enabled) - 2360usize];
};

Notice how the sizes of the two uint_8 * fields - and thus the size of the overall structure - has changed.

The outcome is that the binding does not compile, since the sizes of the bound C struct and the generated Rust struct differ.

I'll look at the changes since 0.72.0. In the mean time, downgraded by cargo install --locked --version 0.72.0 bindgen-cli.

$ cargo --version
cargo 1.89.0 (c24e10642 2025-06-23)
$ rustc --version
rustc 1.89.0 (29483883e 2025-08-04)

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