Bazel: Split protobuf Bazel module across language boundaries

Open
#30,754 2 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@esrauchg is already working on this.

Since Oct 20, 2026.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
15/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, java, rust
Domain
build-system

Research direction

The payload points to the Rust runtime BUILD file at rust/BUILD and the procedural macro BUILD file at rust/protobuf_macros/BUILD, which pull in paste, linkme, quote and syn. Reproduce the cost by running bazelisk mod deps --lockfile_mode=update on a Java-only consumer and checking which Rust tooling downloads. Done would mean a proposed module layout that keeps Rust and multilanguage consumers working, which needs maintainer agreement on the design first.

Written by the indexing model from the issue text.

Description

feature request

Request

Provide separate Bazel modules for Protobuf's language integrations, so
Java consumers can use Java support without provisioning Rust tooling.

For example, using proposed module names:

# Java applications
bazel_dep(name = "protobuf_java", version = "36.2")
# Rust applications
bazel_dep(name = "protobuf_rust", version = "36.2")

Each language module would depend on shared compiler/core infrastructure.
The shared module would not depend on every language integration.

Measured cost

Gerrit Code Review uses Protobuf's Java support. With Protobuf 36.2 and
Bazel 9.3.0 on macOS x86_64, running:

bazelisk mod deps --lockfile_mode=update

provisions Rust tooling and processes Protobuf's Cargo workspace.
A repeat with a fresh Bazel output directory and empty download cache
confirmed these downloads:

Download MB
cargo-bazel 0.69.0 15.87
rustc 1.93.1 77.40
Cargo 1.93.1 9.16
Clippy 1.93.1 3.21
LLVM tools 1.93.1 49.15
Rust standard library 1.93.1 28.51
Rustfmt nightly 1.73
Total 185.03

Bazel's profile records 194.61 seconds evaluating the Rust crate
extension. Separately, the extracted Rust host tools contain 1.05 GB
of files, excluding cargo-bazel and cached archives.

These measurements come from one cold-cache run. Repository-rule logs and
downloaded files establish the payload sizes; the total excludes metadata
and network overhead. Warm caches can avoid repeat downloads.

Why our workaround is limited

Our Gerrit patch
marks rules_rust and the crate extension as dev_dependency = True.
This works for Java-only usage, but removes dependencies required by
downstream Rust consumers.

The extension includes test tooling such as googletest, but also
production dependencies: paste and linkme in the
Rust runtime,
and quote and syn in its
procedural macros.
It cannot all be treated as test-only.

Expected behavior

  • Java builds and lockfile maintenance work without unused Rust tooling.
  • Rust and multilanguage consumers retain supported configurations.
  • Existing consumers have a documented migration path.
  • Required shared compiler dependencies remain available, including C++
    dependencies when building protoc from source.

A smaller fix that preserves downstream Rust support would also be
welcome; resolving the download bug need not wait for a module split.

Related discussion

Bazel considered optional module dependencies in
bazelbuild/bazel#25214,
now closed as not planned. It explicitly discusses splitting Protobuf
into core and language-specific modules. Its optional-dependency proposal
means activation when another dependency introduces the module, rather
than selection based on a build target's language.

This request concerns Protobuf's module design; it does not require a new
Bazel optional-dependency attribute.

Related: #30684 — Java-only consumers inherit Rust compiler downloads.

Dominant language
C++
Stars
72.2k
Forks
16.4k
Avg merge
1d 8h
Merged PRs (30d)
342

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from protocolbuffers/protobuf

All issues in protocolbuffers/protobuf

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.