bazelbuild / bazelbuild/rules_rust

Build scripts fail on *-sys packages where the native library already supports bazel

Open
#3,465 0 comments 0 reactions 0 assignees View on GitHub
needs-triage
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

When you would like to build a bindings library (`*-sys`) then if the native library already supports bazel the build script won't work.

It will fail with missing directory.

# Example

An example is [highs-sys](https://github.com/rust-or/highs-sys).

When your try to build it will give you an error that the directory was not found in the `_bs.cargo_runfiles`. (error below)

After some debugging I saw that the submodule (`HiGHS`) was never copied to the runfiles. The reason because that project supports bazel already.

In the generated build script rule we would glob everything from the dependency for `cargo_build_script`. However, globs are not going through package boundaries (presence of `BUILD.bazel` file in a directory). Therefore it skips the native repository.

```
Build script process failed with exit code 101
--stdout:
CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = None
CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = None
HOST_CMAKE_TOOLCHAIN_FILE = None
CMAKE_TOOLCHAIN_FILE = None
CMAKE_GENERATOR_x86_64-unknown-linux-gnu = None
CMAKE_GENERATOR_x86_64_unknown_linux_gnu = None
HOST_CMAKE_GENERATOR = None
CMAKE_GENERATOR = None
CMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = None
CMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = None
HOST_CMAKE_PREFIX_PATH = None
CMAKE_PREFIX_PATH = None
CMAKE_x86_64-unknown-linux-gnu = None
CMAKE_x86_64_unknown_linux_gnu = None
HOST_CMAKE = None
CMAKE = None
running: cd "/home/wincent/.cache/bazel/_bazel_wincent/6b97d6e3efd5c36d4cbad59f061097eb/sandbox/linux-sandbox/73/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_rust++crate+crates__highs-sys-1.6.4/_bs.out_dir/build" && CMAKE_PREFIX_PATH="" "cmake" "/home/wincent/.cache/bazel/_bazel_wincent/6b97d6e3efd5c36d4cbad59f061097eb/sandbox/linux-sandbox/73/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_rust++crate+crates__highs-sys-1.6.4/_bs.cargo_runfiles/rules_rust++crate+crates__highs-sys-1.6.4/HiGHS" "-DFAST_BUILD=ON" "-DBUILD_SHARED_LIBS=OFF" "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL" "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=FALSE" "-DCMAKE_INSTALL_PREFIX=/home/wincent/.cache/bazel/_bazel_wincent/6b97d6e3efd5c36d4cbad59f061097eb/sandbox/linux-sandbox/73/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_rust++crate+crates__highs-sys-1.6.4/_bs.out_dir" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 --target=x86_64-unknown-linux-gnu -U_FORTIFY_SOURCE -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -no-canonical-prefixes -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -fdebug-prefix-map=/usr/bin/=__bazel_toolchain_llvm_repo__/" "-DCMAKE_C_COMPILER=/usr/bin/clang" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 --target=x86_64-unknown-linux-gnu -U_FORTIFY_SOURCE -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -std=c++17 -stdlib=libstdc++ -no-canonical-prefixes -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -fdebug-prefix-map=/usr/bin/=__bazel_toolchain_llvm_repo__/" "-DCMAKE_CXX_COMPILER=/usr/bin/clang" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 --target=x86_64-unknown-linux-gnu -U_FORTIFY_SOURCE -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -no-canonical-prefixes -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -fdebug-prefix-map=/usr/bin/=__bazel_toolchain_llvm_repo__/" "-DCMAKE_ASM_COMPILER=/usr/bin/clang" "-DCMAKE_BUILD_TYPE=Release"

--stderr:
CMake Error: The source directory "/home/wincent/.cache/bazel/_bazel_wincent/6b97d6e3efd5c36d4cbad59f061097eb/sandbox/linux-sandbox/73/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_rust++crate+crates__highs-sys-1.6.4/_bs.cargo_runfiles/rules_rust++crate+crates__highs-sys-1.6.4/HiGHS" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.

thread 'main' panicked at external/rules_rust++crate+crates__cmake-0.1.50/src/lib.rs:1098:5:

command did not execute successfully, got: exit status: 1

ERROR: /home/wincent/.cache/bazel/_bazel_wincent/6b97d6e3efd5c36d4cbad59f061097eb/external/rules_rust++crate+crates__highs-sys-1.6.4/BUILD.bazel:27:13 Compiling Rust rlib highs_sys v1.6.4 (4 files) failed: (Exit 1): runner failed: error executing CargoBuildScriptRun command (from target @@rules_rust++crate+crates__highs-sys-1.6.4//:_bs) bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/rules_rust+/cargo/cargo_build_script_runner/runner '--script=bazel-out/k8-fastbuild/bin/external/rules_rust++crate+crates__highs-sys-1.6.4/_bs-' ... (remaining 9 arguments skipped)
```

# Workaround

Possible workaround to patch the dependency and remove all `BUILD` files.

# Correct way to fix

Not entirely sure what would be the correct way to fix this. Maybe when we download the dependencies we should remove bazel files from these projects or we should try to discover that this is a bazel project and use that to reference files?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.