Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing class methods bindings when target is i686-pc-windows-gnu #1739

Open
katyo opened this issue Mar 2, 2020 · 3 comments
Open

Missing class methods bindings when target is i686-pc-windows-gnu #1739

katyo opened this issue Mar 2, 2020 · 3 comments

Comments

@katyo
Copy link

katyo commented Mar 2, 2020

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.

@katyo
Copy link
Author

katyo commented Mar 2, 2020

Hmm,
The log looks strange:

...
[2020-03-02T08:31:33Z DEBUG bindgen::codegen] <Item as CodeGenerator>::codegen: self = Item { id: ItemId(11), local_id: LazyCell { inner: UnsafeCell }, next_child_local_id: Cell { value: 1 }, canonical_name: LazyCell { inner: UnsafeCell }, path_for_whitelisting: LazyCell { inner: UnsafeCell }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false, derives: [] }, parent_id: ItemId(1), kind: Function(Function { name: "reset", mangled_name: Some("__ZN4Vec25resetEv"), signature: TypeId(ItemId(6)), comment: None, kind: Method(Normal), linkage: External }) }
[2020-03-02T08:31:33Z DEBUG bindgen::codegen] <Function as CodeGenerator>::codegen: item = Item { id: ItemId(11), local_id: LazyCell { inner: UnsafeCell }, next_child_local_id: Cell { value: 1 }, canonical_name: LazyCell { inner: UnsafeCell }, path_for_whitelisting: LazyCell { inner: UnsafeCell }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false, derives: [] }, parent_id: ItemId(1), kind: Function(Function { name: "reset", mangled_name: Some("__ZN4Vec25resetEv"), signature: TypeId(ItemId(6)), comment: None, kind: Method(Normal), linkage: External }) }
[2020-03-02T08:31:33Z WARN  bindgen::codegen] Skipping function with thiscall ABI that isn't supported by the configured Rust target
...

Which means "isn't supported by the configured Rust target"?

UPD:
It seems "thiscall" still unstable rust feature...

@katyo
Copy link
Author

katyo commented Mar 2, 2020

As wiki says "for the GCC compiler, thiscall is almost identical to cdecl". Are that means this is unexpected behavior?

@emilio
Copy link
Contributor

emilio commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants