Skip to content

Bindgen build script panicking on "x86_64-unknown-linux-gnu" in debug #3274

@almanac-problem

Description

@almanac-problem

Hi there,

I ran into an error while compiling rust-rocksdb, which appears to potentially be a bindgen issue. I re-created this issue on my system using the same code provided in the bindgen tutorial, but using 0.72.0 instead of 0.71. The panic occurs here:

rust-bindgen/bindgen/lib.rs

Lines 914 to 920 in b03b222

if is_host_build {
debug_assert_eq!(
context.target_pointer_size(),
size_of::<*mut ()>(),
"{effective_target:?} {HOST_TARGET:?}"
);
}

In the debug profile builds, the output is:

...
Compiling bindgen_test v0.1.0 (~/projects/bindgen_test)
error: failed to run custom build command for `bindgen_test v0.1.0 ~/projects/bindgen_test)`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `~/projects/bindgen_test/target/debug/build/bindgen_test-b821d7dddd98ba9e/build-script-build` (exit status: 101)
  --- stdout
  cargo:rustc-link-search=/path/to/lib
  cargo:rustc-link-lib=bz2
  cargo:rerun-if-env-changed=TARGET
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
  cargo:rerun-if-changed=wrapper.h

  --- stderr

  thread 'main' panicked at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bindgen-0.72.0/lib.rs:917:13:
  assertion `left == right` failed: "x86_64-unknown-linux-gnu" "x86_64-unknown-linux-gnu"
    left: 4
   right: 8
  stack backtrace:
     0: __rustc::rust_begin_unwind
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library/std/src/panicking.rs:697:5
     1: core::panicking::panic_fmt
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library/core/src/panicking.rs:75:14
     2: core::panicking::assert_failed_inner
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library/core/src/panicking.rs:427:23
     3: core::panicking::assert_failed
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library/core/src/panicking.rs:387:5
     4: bindgen::Bindings::generate
     5: bindgen::Builder::generate
     6: build_script_build::main
     7: core::ops::function::FnOnce::call_once
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

As noted above, the problem seems to be that context.target_pointer_size() and size_of::<*mut ()>() are not equal even though the effective target and HOST_TARGET are the same. I would expect both to be 8. I followed the calls back to the creation of BindgenContext.translation_unit, but I know absolutely nothing about bindgen as I've yet to use it directly.

Interestingly, if I compile with --release, that debug_assert_eq is not hit and the compilation is successful. I was able to run application code which relied on rust-rocksdb --release immediately after hitting this panic with --debug.

Please let me know what additional diagnostics would be helpful. I'm running a distro derivative of Ubuntu 22.04:

[bindgen_test] uname -srv
Linux 6.5.0-45-generic #45~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC

[bindgen_test] rustc --print host-tuple 
x86_64-unknown-linux-gnu

Thanks!

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