Open
Description
Input C/C++ Header
struct Vec2 {
float x, y;
void reset();
};
Bindgen Invocation
$ bindgen test.hpp -- -target i686-pc-windows-gnu
Actual Results
/* automatically generated by rust-bindgen */
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Vec2 {
pub x: f32,
pub y: f32,
}
#[test]
fn bindgen_test_layout_Vec2() {
assert_eq!(
::std::mem::size_of::<Vec2>(),
8usize,
concat!("Size of: ", stringify!(Vec2))
);
assert_eq!(
::std::mem::align_of::<Vec2>(),
4usize,
concat!("Alignment of ", stringify!(Vec2))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Vec2>())).x as *const _ as usize },
0usize,
concat!("Offset of field: ", stringify!(Vec2), "::", stringify!(x))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Vec2>())).y as *const _ as usize },
4usize,
concat!("Offset of field: ", stringify!(Vec2), "::", stringify!(y))
);
}
Expected Results
However when target is x86_64 it works as expected:
$ bindgen test.hpp -- -target x86_64-pc-windows-gnu
The result is:
/* automatically generated by rust-bindgen */
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Vec2 {
pub x: f32,
pub y: f32,
}
#[test]
fn bindgen_test_layout_Vec2() {
assert_eq!(
::std::mem::size_of::<Vec2>(),
8usize,
concat!("Size of: ", stringify!(Vec2))
);
assert_eq!(
::std::mem::align_of::<Vec2>(),
4usize,
concat!("Alignment of ", stringify!(Vec2))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Vec2>())).x as *const _ as usize },
0usize,
concat!("Offset of field: ", stringify!(Vec2), "::", stringify!(x))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Vec2>())).y as *const _ as usize },
4usize,
concat!("Offset of field: ", stringify!(Vec2), "::", stringify!(y))
);
}
extern "C" {
#[link_name = "\u{1}_ZN4Vec25resetEv"]
pub fn Vec2_reset(this: *mut Vec2);
}
impl Vec2 {
#[inline]
pub unsafe fn reset(&mut self) {
Vec2_reset(self)
}
}
I assume the both results should looks similar but this isn't so.
This issue looks like a #751, but adding -fvisibility=default
doesn't help.
Also I tried to set appropriate sysroot to clang (using -isysroot) but It also doesn't help.
Activity
katyo commentedon Mar 2, 2020
Hmm,
The log looks strange:
Which means "isn't supported by the configured Rust target"?
UPD:
It seems "thiscall" still unstable rust feature...
katyo commentedon Mar 2, 2020
As wiki says "for the GCC compiler, thiscall is almost identical to cdecl". Are that means this is unexpected behavior?
emilio commentedon Mar 2, 2020
thiscall
is generated if rustc supports it. It is unstable still per rust-lang/rust#42202.You can generate it if you build with rust-target=nightly. That being said if the ABI is just cdecl in some targets we may want to make the checks here and in similar places more nuanced.