Skip to content

I think there might be a bug with the version matching #3052

Description

@pvdrz

I think there might be a bug with the version matching:

error: extern block cannot be declared unsafe
    --> /home/christiaan/scate2-dev/rust/target/release/build/flexnet_client-sys-a77799b3d52b9432/out/bindings.rs:3363:1
     |
3363 | unsafe extern "C" {
     | ^^^^^^
     |
     = note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information

error: extern block cannot be declared unsafe
    --> /home/christiaan/scate2-dev/rust/target/release/build/flexnet_client-sys-a77799b3d52b9432/out/bindings.rs:3371:1
     |
3371 | unsafe extern "C" {
     | ^^^^^^
     |
     = note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information

error: could not compile `flexnet_client-sys` (lib) due to 243 previous errors
warning: build failed, waiting for other jobs to finish...
christiaan@CBHST34:~/scate2-dev/rust$ rustc --version
rustc 1.81.0 (eeb90cda1 2024-09-04)

This is with bindgen = { version = "0.71.1" }

Originally posted by @Kriskras99 in #3015 (comment)

Activity

  1. pvdrz commented on Dec 10, 2024

    @pvdrz
    ContributorAuthor

    This is because bindgen automatically targets the latest rust available as it has no way to detect the rust version of your project (yet). So you have to set the version using builder.rust_target("1.81.0".parse()?)

  2. Kriskras99 commented on Dec 10, 2024

    @Kriskras99
    Contributor

    Ah check, that's inconvenient.
    Thanks for the fix!

  3. pvdrz commented on Dec 10, 2024

    @pvdrz
    ContributorAuthor

    If you're using a rust-toolchain.toml file: #3049

  4. ydirson commented on Jan 6, 2025

    @ydirson

    This hardly looks like a fix. When you're building a project that use a crate that uses bindgen (quite common in fact), your project does not have any control over the bindgen run.
    Why would bindgen not be able to know what Rust version it targets, through the version of the cargo process launching it?

  5. ydirson commented on Jan 6, 2025

    @ydirson

    BTW, I'm curious what algorithm is used to select the target Rust version: when building inside docker.io/library/rust:1.77-buster, I would expect that bindgen would not see any toolchain more recent than 1.77... shouldn't the version check in #3015 indeed avoid the newer construct?

  6. ydirson commented on Jan 6, 2025

    @ydirson

    Why would bindgen not be able to know what Rust version it targets, through the version of the cargo process launching it?

    See #3049 (comment)

  7. pvdrz commented on Jan 8, 2025

    @pvdrz
    ContributorAuthor

    This hardly looks like a fix. When you're building a project that use a crate that uses bindgen (quite common in fact), your project does not have any control over the bindgen run.

    Using bindgen in a crate is an implementation detail. If the crate you're using asserts that they have a specific MSRV and they don't, that's a bug in the crate. If they don't have a MSRV, then they just don't.

    Why would bindgen not be able to know what Rust version it targets, through the version of the cargo process launching it?

    Well, basically because there is no canonical way to know this, you can maybe grab it from the rust-toolchain.toml, or from the cargo manifest, or from the cargo env vars, or get the rustc path from the cargo env vars and then run rustc --version. Each one of these options has the caveat where some user won't be able to use it: Either their project doesn't have a rust-toolchain.toml, or they don't set a version in the manifest, or they don't even use cargo.

    And that's for the users that actually use bindgen as a library, a lot of people just use the standalone CLI application.

  8. glandium commented on Jan 24, 2025

    @glandium
    Contributor

    a lot of people just use the standalone CLI application.

    How many really use it standalone, as opposed to driven by the library? The library, when it's not using the CLI, could just use the rustc version it's being compiled with, via rustc_version, rustversion or similar crate. The library, when it is using the CLI, could pass the rustc version it's being compiled with to the CLI as an argument. And for the people that do use the CLI entirely in standalone mode, bindgen could default to the most recent version, and those people could also use the version flag to give a specific rust version if they so want.

  9. glandium commented on Jan 24, 2025

    @glandium
    Contributor

    Erf, that CLI option already exists...

  10. glandium commented on Jan 24, 2025

    @glandium
    Contributor

    How about changing RustTarget::default to return the version of the rust compiler in use when the __cli feature is not enabled?

  11. decathorpe commented on May 8, 2025

    @decathorpe
    Contributor

    We hit this in Fedora Linux too now - with bindgen-cli 0.71.1 compiled for EPEL on RHEL 9, it still defaults to generating code for Rust 1.82, whereas both the version it was compiled and the current version of Rust are 1.79. Defaulting to a Rust version that is newer than the version the executable was compiled with seems ill-advised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions