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

Generate `std::ffi::*` instead of the `std::os::raw::*` types

Open nyurik opened this issue 1 year ago • 4 comments

std::os::raw recommends to use core::ffi instead, but for std crates using core directly seem to trigger some warnings. The std::ffi::* offers the same types like c_char and c_int as core::ffi::*, plus it offers the newer types like CStr in there. Would it make sense to consistently use just the std::ffi::* for all C types in the generated code?

P.S. I am aware that this can be done with .ctypes_prefix("::std::ffi") param - but the question is if this should be done by default?

nyurik avatar Sep 06 '24 04:09 nyurik

I think core::ffi is used if the use_core option is enabled and the rust target is high enough. Isn't that the case?

pvdrz avatar Sep 06 '24 12:09 pvdrz

It would be helpful to default to core::ffi on editions/versions that support it, since that should work on both std and no-std environments and is one less setting to have to set.

GKFX avatar Dec 02 '24 22:12 GKFX

I think this is a sensible default. I don't see any immediate reason to not use core::ffi if available.

In general I don't see any reasons to not use core instead of std in general (unless it is something that std offers and core does not, of course).

pvdrz avatar Dec 03 '24 19:12 pvdrz

Yeah, seems nice to default this to std::ffi:: if --rust-target 1.64 or higher (and core:: if --use-core is specified, of course).

MarijnS95 avatar Feb 22 '25 20:02 MarijnS95