Skip to content

Cargo build of rs_bindings_from_cc (using Bazel C++ dependencies). - #1876

Draft
anforowicz wants to merge 1 commit into
google:mainfrom
anforowicz:cargo-bazel-take2
Draft

Cargo build of rs_bindings_from_cc (using Bazel C++ dependencies).#1876
anforowicz wants to merge 1 commit into
google:mainfrom
anforowicz:cargo-bazel-take2

Conversation

@anforowicz

Copy link
Copy Markdown
Collaborator

No description provided.

This commit enables building the `rs_bindings_from_cc` binary using
Cargo by reusing Bazel-built static libraries and generated headers
for Abseil, LLVM/Clang, and Protobuf.

Changes:
1. **Environment Setup & Protobuf Scripts**:
   - Adds `cargo/build/generate_proto_headers.py` to pre-generate
     C++ Protobuf headers into a shared directory upfront, avoiding
     race conditions during concurrent Cargo builds across environments
     (Crubit OSS, Chromium, Android).
   - `cargo/build/setup_bazel_env.py`: Queries Bazel for prebuilt C++
     dependencies, merges static archives using `llvm-ar`, pre-generates
     Protobuf headers, detects the hermetic Clang toolchain, and emits
     `target/bazel_outputs/bazel-env.sh`.

2. **C++ Header Discovery & Robustness (`cargo/build/`)**:
   - Adds `paths::collect_static_libs` and `paths::get_env_paths` to
     validate environment variables, directory existence, and
     non-empty library archives with clean diagnostics.
   - Adds `-DLLVM_ON_UNIX` to C++ compilation flags in `flags.rs`.

3. **Protobuf Compatibility (`rust/BUILD`)**:
   - Adds placeholder `//rust:use_upb_kernel` config_setting in
     `rust/BUILD` to work around a known Bzlmod `rules_rust` bug in
     Protobuf where relative labels resolve against the root workspace.

4. **Documentation & CI Integration**:
   - Documents the Cargo build workflow and environment variable
     specification in `docs/overview/cargo_build.md`.
   - Adds CI steps in `.github/workflows/rust.yml` to verify
     `cargo build` of `rs_bindings_from_cc` in GitHub Actions.
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

Successfully merging this pull request may close these issues.

1 participant