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

Take advantage of `feature(core_ffi_c)` (and possibly `feature(c_size_t)`)

Open ojeda opened this issue 3 years ago • 2 comments

feature(core_ffi_c) was stabilized (and possibly feature(c_size_t) in the future), so we may want to extend --use-core to use them (gated on --rust-target or some other flag).

In fact, it could potentially be made the default, since it would work for all projects (i.e. both std and no_std).

Currently, a workaround is to manually specify the prefix via --ctypes-prefix core::ffi.

Input C/C++ Header

void f(int);

Bindgen Invocation

$ bindgen input.h --use-core

Or in the future:

$ bindgen input.h

Actual Results

extern "C" {
    pub fn f(arg1: ::std::os::raw::c_int);
}

Expected Results

extern "C" {
    pub fn f(arg1: ::core::ffi::c_int);
}

ojeda avatar Jun 30 '22 19:06 ojeda

Yes, making this the default based on the rust target seems like a great path forward. It seems core_ffi_c got stabilized already? A patch for this should be easy-ish to write / review :)

emilio avatar Jul 25 '22 09:07 emilio

Yeah, I have piled up a few things for bindgen that I want to take a look at and submit -- I should have some time in a week or so :)

ojeda avatar Jul 25 '22 09:07 ojeda