-
Notifications
You must be signed in to change notification settings - Fork 698
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
std dependencies when use_core
is used: new approach
#1583
Comments
Maybe one could also provide meta variables, which is then an alias for e.g. pub type r_c_int = std::os::raw::c_int;
[...]
pub type __int32_t = r_c_int;
pub type __mode_t = r_c_int;
[...] and then I only have to specify the types |
The expected way to use So You can perfectly do something like: And define something like: pub mod myctypes {
pub type c_int = i64; // yolo
} It's not clear to me how that is different from your proposed solution, or am I missing something? |
|
As said, libc is not feasible here :/
But I do not know the types, but my compiler does (I honestly don't care if an I'm not really sure how to handle this, but IMHO the |
Ah, I see. So what you want is a way to generate bindings for whatever target clang bindgen invoked against, is that right? That means that the bindings will no longer be portable, but maybe that's ok as long as you opt into that. |
I just want to add I'm in the same predicament. Bare metal embedded, no libc. I don't care about portability of the bindings I'm generating for a specific hardware target, what I want is for bindgen to generate |
Ok, so I'll assume #1583 (comment) is the right understanding of the issue. If so, this should be pretty easy to implement. Just add a new switch and then in this match here: rust-bindgen/src/codegen/mod.rs Line 3047 in 9fe3e90
We need to do something similar to what we do for Doing the same for the other integer types under a flag should be pretty straight-forward. |
Has there been any further work towards this issue? It feels a bit odd to require users to specify their definition of |
I've also run into this, I'm trying to generate bindings for GRUB. Is there anything I can do, or do I need to figure out what types the c types correspond to and map them by hand? |
https://github.com/rust-lang/libc seems to suggest it might be possible to use libc with no_std? Is it possible to use libc's types without needing to actually link / whatever the binary to the final result? Edit: after grepping a bit, if I did it right, it seems like I really only need to map 12 or so simple basic types, so maybe it's not so bad. |
Yeah. Alternatively as a reply to the comments above no, there hasn't been any work towards this feature, but #1583 (comment) should still be an accurate description of what needs to get done. I don't plan to work on this myself but I'll happily review a patch or mentor someone interested in doing so. |
I found the hints in https://docs.rust-embedded.org/book/interoperability/c-with-rust.html#automatically-generating-the-interface useful: [dependencies]
cty = "0.2.1" let bindings = bindgen::Builder::default()
.use_core()
.ctypes_prefix("cty"); |
Since let bindings = bindgen::Builder::default()
.use_core()
.ctypes_prefix("::core::ffi"); Although a couple of types are still missing at the time of writing; among them are:
|
This might be relevant: #1663 (comment) |
@pvdrz Why use clang/llvm to figure this out if it is natively supported by |
I could see these working on a nightly rust target. Implementing this change wouldn't be that hard.
If you're not interested in portability and you cannot use rust 1.64 for whatever reason you'd be better using the sized integer types that rust provides instead. |
@pvdrz I see a lot of "if"s there. But I'd argue "if" you are generating the ffis statically (meaning, once and commit them to git instead of at compile time), the |
yes |
Bindgen Invocation
Actual Results
Expected Results
This is mostly a dupe/expansion of #1015, #448, #628, #1439.
I'm afraid that you don't like the discussion anymore, but in my eyes this isn't closed. If I want to build a
!#[no_std]
crate which relies on "no std" c libraries, it isn't possible in the current form.I know, that some of types can't be expressed in core(, but e.g. why is
int8_t
defined asc_schar
instead ofi8
?), but currently my workaround is to opaque all the types. This isn't feasible. The workaround with libc is also not possible for me, because I don't have a libc running on bare metal.Bindgen should be able to deduce the types, because it knows the target and therefore knows what
c_uchar
,c_ushort
, ... are, e.g. if they areu8
oru16
or anything else. They can be mapped directly to the corresponding types.What I would like to see is either an option to skip all
std
dependent types (e.g. by using--skip-std-types
). I see two possibilities here:One could also print a message to stdout, that a specific type (e.g.
clock_t
) has been skipped, because of that option above.Is that something one could provide? What alternatives are (expect for blacklisting all the types :|).
The text was updated successfully, but these errors were encountered: