Rust-bindgen: use_core option to imply nostd and deny any ::std::

Created on 11 Apr 2017  路  10Comments  路  Source: rust-lang/rust-bindgen

I need #![no_std] rust source. I suggest that use-core should help but now use-core produces lots of ::std:: code. If use-core isn't good for the goal maybe it's worth introducing another option?

Most helpful comment

Yes, I believe so, hardcoding types for a single platform isn't something that should happen on bindgen.

All 10 comments

There are two options: use-core and ctypes-prefix. I suspect that setting ctypes-prefix to libc should remove all the std code, otherwise it's a bug.

I'm processing a low-level library (CMSIS/STM32 HAL). And I get the output
full of ::std::os::raw::c_uint types. I suggest that they should be
replaced with libcore types. Possible?

Is core::os::raw a thing now? I was pretty sure that at the time this was implemented the only suitable solution for #![no_std] and ctypes was using libc.

FYI: the library is libc-independent. And I assume rs code should be alike.

Transforming ::std::os::raw::c_uint -> u32 is fine for me, but it seems
impossible with bindgen options, right?
But AFAIU uint isn't completely equal to u32 (arch-dependent), so the full
solution should take this into account too.

You can create a submodule in your crate as follows:

mod c_types {
    type c_uint = u32;
    // ...
}

And call bindgen with ctypes-prefix set to c_types.

I'm closing this because I'm not sure there's anything else I can do from bindgen.

Thanks for reporting!

Em, excuse me. But ::std::os::raw::c_uint -> u32could be done. Or am I
getting it wrong and you suggest it must be done with c_types
workaround/c_types crate?

Yes, I believe so, hardcoding types for a single platform isn't something that should happen on bindgen.

Was this page helpful?
0 / 5 - 0 ratings