rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

Bindgen rules are not supported on all platforms

Open UebelAndre opened this issue 3 years ago • 4 comments

The //bindgen rules are currently not working on Windows and in RBE environments. This should be fixed

UebelAndre avatar Aug 29 '21 17:08 UebelAndre

Yeah, they are only defined for Mac and Linux:

https://github.com/bazelbuild/rules_rust/blob/bb38e76dc148b2460e326f7f2181c40d13b97fc9/bindgen/BUILD.bazel#L14

sayrer avatar Aug 29 '21 17:08 sayrer

Yeah, makes sense. This is more of a tracking issue for comments being added in https://github.com/bazelbuild/rules_rust/pull/918

Ideally we should support all platforms but for the time being, my hope is that users see this issue instead of needing to dig through the code.

UebelAndre avatar Aug 29 '21 17:08 UebelAndre

rust_bindgen fails with the following error in remote build environments (remote execution):

(15:08:59) ERROR: /workdir/examples/bindgen/BUILD.bazel:10:21: Generating bindings for bindgen/simple.h.. failed: (Exit 101): cargo_bin_bindgen failed: error executing command
  (cd /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/90e2e9b2d72fa9b00c19ff0535bb31ae/execroot/examples && \
  exec env - \
    CLANG_PATH=bazel-out/k8-opt-exec-60723E07/bin/external/bindgen_clang_linux/clang \
    LIBCLANG_PATH=bazel-out/k8-opt-exec-60723E07/bin/_solib_k8/_U@bindgen_Uclang_Ulinux_S_S_Clibclang___Ulib \
    RUST_BACKTRACE=1 \
  bazel-out/k8-opt-exec-60723E07/bin/external/rules_rust_bindgen__bindgen__0_58_1/cargo_bin_bindgen --no-rustfmt-bindings '--allowlist-var=SIMPLE_.*' bindgen/simple.h --output bazel-out/k8-fastbuild/bin/bindgen/simple_bindgen__bindgen.rs.unformatted -- -iquote . -iquote bazel-out/k8-fastbuild/bin)
# Configuration: 2098c73efc81d9b6effdf6ab8b32d3798f8ca72c71a5005bd40c6a1e8a36ddb5
# Execution platform: @buildkite_config//config:platform
thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared library at bazel-out/k8-opt-exec-60723E07/bin/_solib_k8/_U@bindgen_Uclang_Ulinux_S_S_Clibclang___Ulib/libclang.so could not be opened: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by bazel-out/k8-opt-exec-60723E07/bin/_solib_k8/_U@bindgen_Uclang_Ulinux_S_S_Clibclang___Ulib/libclang.so)"', external/rules_rust_bindgen__bindgen__0_58_1/src/lib.rs:2057:31
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/panicking.rs:142:14
   2: core::result::unwrap_failed
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/result.rs:1785:5
   3: std::sync::once::Once::call_once::{{closure}}
   4: std::sync::once::Once::call_inner
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sync/once.rs:434:21
   5: bindgen::clang_version
   6: cargo_bin_bindgen::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

UebelAndre avatar Jul 14 '22 15:07 UebelAndre

A result of this is that bindgen doesn't work when building for the newer Mac models that run on arm64, which is blocking our use of the bindgen rules.

Has any thought been given to how to address this? The quick fix for Mac arm64 would be to reference the arm64 pre-built llvm binaries, but bindgen is currently using a pretty old llvm version (10, current is 15.x) which doesn't provide mac arm64 pre-builts.

For a short term solution would it be feasible to update the version of llvm used so we can make use of the recent pre-built binaries that include mac arm64? Or would we want a more holistic approach that can work for more platforms?

@keith

snowp avatar Sep 21 '22 13:09 snowp

Any update on this? I have experienced this causing some issues considering how common darwin-arm64 dev machines are and the limited documentation for your own toolchain as a workaround.

BadBastion avatar Dec 27 '22 23:12 BadBastion