Skip to content
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

bindgen 0.70 uses offset_of on Rust 1.76 #2960

Open
juntyr opened this issue Oct 20, 2024 · 9 comments
Open

bindgen 0.70 uses offset_of on Rust 1.76 #2960

juntyr opened this issue Oct 20, 2024 · 9 comments

Comments

@juntyr
Copy link

juntyr commented Oct 20, 2024

My weekly CI on my MSRV 1.76 started failing because a dependency bumped bindgen to 1.70, which now includes offset_of! in the bindings despite being still unstable. It looks like #2787 introduced the extra checks, though at a quick glance that PR looks fine.

juntyr added a commit to juntyr/numcodecs-rs that referenced this issue Oct 20, 2024
@kulp
Copy link
Member

kulp commented Oct 23, 2024

@juntyr,

(I think you mean bindgen 0.70 and not 1.70.)

In the PR you linked, I think #2787 (comment) might be helpful:

The MSRV of the generated code is configurable with Builder::rust_target. If using Bindgen 0.70 and Rust < 1.77.0 then the relevant target will need to be set.

@juntyr juntyr changed the title bindgen 1.70 uses offset_of on Rust 1.76 bindgen 0.70 uses offset_of on Rust 1.76 Oct 23, 2024
@juntyr
Copy link
Author

juntyr commented Oct 23, 2024

(I think you mean bindgen 0.70 and not 1.70.)

Whoops :)

The MSRV of the generated code is configurable with Builder::rust_target. If using Bindgen 0.70 and Rust < 1.77.0 then the relevant target will need to be set.

How do I set the target when bindgen runs in the build script of a dependency I don’t control?

@pvdrz
Copy link
Contributor

pvdrz commented Oct 24, 2024

that's on your dependency's yard. If they want to produce bindings for a lower msrv then they have to do it themselves.

@juntyr
Copy link
Author

juntyr commented Oct 24, 2024

I think at least the CHANGELOG should be updated to mention that 0.70 contains an on-by-default MSRV bump for generated code.

I know that in the end it was my dependency’s fault for bumping bindgen in a minor release so that a simple cargo update suddenly broke my build. But it still feels like a call-out in the CHANGELOG might have prevented this.

@pvdrz
Copy link
Contributor

pvdrz commented Oct 24, 2024

@juntyr I understand your point, definitely we could include such comments in the future. However, they might be rather confusing as there are 3 different MSRVs: One to compile bindgen, one to compile bindgen-cli and one for the generated code.

That being said, if someone maintains a library with an MSRV guarantee and you're bumping dependencies without checking if your MSRV guarantees hold, it is as you said, their fault. Specially since you can use

builder.rust_target(RustTarget::Stable_1_73)

to be sure that if there's a MSRV guarantee breakage is actually a bug in bindgen.

@barakugav
Copy link

The rust-version field in bindgen Cargo.toml should be 1.77

@pvdrz
Copy link
Contributor

pvdrz commented Nov 1, 2024

The rust-version field in bindgen Cargo.toml should be 1.77

no:

$ cargo +1.70.0 build -p bindgen
   Compiling proc-macro2 v1.0.60
   Compiling glob v0.3.1
   Compiling memchr v2.5.0
   Compiling quote v1.0.28
   Compiling unicode-ident v1.0.6
   Compiling prettyplease v0.2.7
   Compiling libc v0.2.159
   Compiling cfg-if v1.0.0
   Compiling log v0.4.17
   Compiling minimal-lexical v0.2.1
   Compiling either v1.8.1
   Compiling regex-syntax v0.6.28
   Compiling libloading v0.7.4
   Compiling bindgen v0.70.1 (/home/christian/Workspace/bindgen/bindgen)
   Compiling itertools v0.13.0
   Compiling bitflags v2.2.1
   Compiling shlex v1.3.0
   Compiling rustc-hash v1.1.0
   Compiling clang-sys v1.4.0
   Compiling nom v7.1.3
   Compiling regex v1.7.1
   Compiling syn v2.0.18
   Compiling cexpr v0.6.0
    Finished dev [unoptimized + debuginfo] target(s) in 6.47s

@barakugav
Copy link

@pvdrz You dont get the error when compiling, but the generated code of bindgen uses the offset_of! macro, which was added in rust 1.77 https://doc.rust-lang.org/nightly/core/mem/macro.offset_of.html

@pvdrz
Copy link
Contributor

pvdrz commented Nov 1, 2024

Please @barakugav read the thread carefully before writing comments like these

the generated code of bindgen uses the offset_of! macro, which was added in rust 1.77

yes, this is true. This doesn't mean that bindgen requires Rust 1.77 to compile. If you want to control the target Rust version of the generated bindings you must use the rust_target method to guarantee that your bindings compile for the right Rust version.

You can use bindgen with Rust 1.70 and generate bindings that should be guaranteed to work on any Rust version from 1.33 to the latest stable and nightly,

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

4 participants