Skip to content

Generated core bindings use types beyond MSRV #2324

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

Closed
declanvk opened this issue Oct 24, 2022 · 5 comments
Closed

Generated core bindings use types beyond MSRV #2324

declanvk opened this issue Oct 24, 2022 · 5 comments

Comments

@declanvk
Copy link

Input C/C++ Header

In /tmp/bindgen-msrv/vendor/header.h:

typedef unsigned char  mp_sign;

Bindgen Invocation

bindgen::Builder::default()
    .header("/tmp/bindgen-msrv/vendor/header.h")
    .use_core()
    .generate()
    .unwrap()

Actual Results

In /tmp/bindgen-msrv/target/debug/build/bindgen-msrv-76670de3f461768b/out/bindings.rs:

/* automatically generated by rust-bindgen 0.61.0 */

pub type mp_sign = ::core::ffi::c_uchar;

and while running cargo +1.57.0 build:

error[E0412]: cannot find type `c_uchar` in module `core::ffi`
 --> /private/tmp/bindgen-msrv/target/debug/build/bindgen-msrv-7c473a0810493086/out/bindings.rs:3:33
  |
3 | pub type mp_sign = ::core::ffi::c_uchar;
  |                                 ^^^^^^^ not found in `core::ffi`
  |
help: consider importing this type alias
  |
3 | use std::os::raw::c_uchar;
  |

core::ffi::c_uchar was introduced in Rust version 1.64.0.

Expected Results

Should compile without errors.

@declanvk declanvk changed the title Generated core bindings use types from beyond MSRV Generated core bindings use types beyond MSRV Oct 24, 2022
@declanvk
Copy link
Author

I'm not actually sure if the MSRV is supposed to be 1) the minimum version of Rust that can build bindgen OR 2) the minimum version of Rust that can build the generated bindings.

@declanvk
Copy link
Author

Seems related to #2277

@declanvk
Copy link
Author

Ah I see the Builder::rust_target controls which version of rust the bindings support, I should just enable that.

This is probably not an issue then? Maybe just improving the MSRV statement to include some references to rust_target or mentioning that MSRV only covers building bindgen, not the generated bindings.

declanvk pushed a commit to declanvk/reckoner that referenced this issue Oct 24, 2022
**Description**
 - Increase MSRV to `1.64.0` and add README line stating MSRV.
 - Using the `bindgen::Builder::rust_target` function, set the rustc version
   required to `1.64.0` to access FFI types from `core`.

**Motivation**
Previous MSRV bump to `1.57.0` failed because `bindgen` generated bindings
which required `1.64.0`. See issue
rust-lang/rust-bindgen#2324 for slightly more
context.

**Testing Done**
 - `cargo +1.57.0 build` fails
 - `cargo +1.64.0 build` succeeds
@pvdrz
Copy link
Contributor

pvdrz commented Oct 24, 2022

If you set the rust target to anything below 1.64.0, bindgen will use std::os::raw instead as expected.

The MSRV is the minimum version that can be used to compile bindgen. However, bindgen itself can produce code for targets below the current MSRV. Maybe we should clarify this in the readme.

@pvdrz
Copy link
Contributor

pvdrz commented Oct 24, 2022

Fixed via: d86db07

Thanks for the report and please feel free to reopen if you think this is not an adequate solution

@pvdrz pvdrz closed this as completed Oct 24, 2022
declanvk pushed a commit to declanvk/reckoner that referenced this issue Oct 24, 2022
**Description**
 - Increase MSRV to `1.64.0` and add README line stating MSRV.
 - Using the `bindgen::Builder::rust_target` function, set the rustc version
   required to `1.64.0` to access FFI types from `core`.

**Motivation**
Previous MSRV bump to `1.57.0` failed because `bindgen` generated bindings
which required `1.64.0`. See issue
rust-lang/rust-bindgen#2324 for slightly more
context.

**Testing Done**
 - `cargo +1.57.0 build` fails
 - `cargo +1.64.0 build` succeeds
declanvk added a commit to declanvk/reckoner that referenced this issue May 17, 2023
**Description**
 - Increase MSRV to `1.64.0` and add README line stating MSRV.
 - Using the `bindgen::Builder::rust_target` function, set the rustc version
   required to `1.64.0` to access FFI types from `core`.

**Motivation**
Previous MSRV bump to `1.57.0` failed because `bindgen` generated bindings
which required `1.64.0`. See issue
rust-lang/rust-bindgen#2324 for slightly more
context.

**Testing Done**
 - `cargo +1.57.0 build` fails
 - `cargo +1.64.0 build` succeeds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants