rust-lang / rust-lang/rust-bindgen

std dependencies when `use_core` is used: new approach

Open
#1,583 18 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Bindgen Invocation
$ bindgen /usr/include/stdint.h --use-core | rg 'std'
Actual Results
pub type __u_char = ::std::os::raw::c_uchar;
pub type __u_short = ::std::os::raw::c_ushort;
pub type __u_int = ::std::os::raw::c_uint;
pub type __u_long = ::std::os::raw::c_ulong;
pub type __int8_t = ::std::os::raw::c_schar;
pub type __uint8_t = ::std::os::raw::c_uchar;
pub type __int16_t = ::std::os::raw::c_short;
pub type __uint16_t = ::std::os::raw::c_ushort;
pub type __int32_t = ::std::os::raw::c_int;
pub type __uint32_t = ::std::os::raw::c_uint;
[...]
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 as c_schar instead of i8?), 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 are u8 or u16 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:

  1. The type isn't used at all the and the compiler won't notice anything
  2. The type is used and rust will throw an error, that the type hasn't been found.

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 :|).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the bindgen invocation shown with /usr/include/stdint.h and --use-core, then review the related discussions in issues #1015, #448, #628, and #1439. Define and implement a resolved approach so generated bindings do not require std for no_std use, including the behavior for unused or unsupported types.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.