From 21a814f66048a3e596938b88e635d1d711dbad13 Mon Sep 17 00:00:00 2001 From: Albert Wu Date: Thu, 28 May 2026 21:24:10 -0700 Subject: [PATCH] build(proto): use prebuilt protoc toolchain instead of compiling from source Registers toolchains_protoc and enables proto toolchain resolution so the proto rules resolve a downloaded protoc binary instead of building @protobuf//:protoc (and its abseil/upb C++ deps) from source on every cold build. Why the noise existed (and why it's gone): the proto rules compiled protoc + abseil from source using the host's Clang, which is newer than the pinned abseil and flagged a deprecated builtin ~800x as build-action stderr; with a prebuilt protoc binary no C++ is compiled, so those warnings are never produced. Cold `make test` (after `bazel clean`): | Metric | Before | After | |-------------------------------------|---------|-------| | make test output | 30,868 | 69 | | abseil deprecation warnings | 802 | 0 | | protobuf/abseil `[for tool]` compiles | ~250+ | 0 | | `external/` lines | 9,741 | 1 | | tests passing | 35 | 35 | | cold wall time | ~84s | ~11s | Changes: - MODULE.bazel: add toolchains_protoc (listed first to win toolchain resolution over the transitive protobuf module) and register its toolchain - .bazelrc: --incompatible_enable_proto_toolchain_resolution No generated *.pb.go changes; rules_go needs no BUILD changes. Validated with bazel clean + make test (35/35 pass), bazel build //..., bazel mod tidy, gazelle. Co-authored-by: Cursor --- .bazelrc | 4 ++++ MODULE.bazel | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/.bazelrc b/.bazelrc index d5c30b39..55b803eb 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,2 +1,6 @@ common --disk_cache=~/.cache/bazel-disk-cache common --repository_cache=~/.cache/bazel-repo-cache + +# Resolve protoc from a registered toolchain (toolchains_protoc provides a +# prebuilt binary) instead of compiling protoc from source. Introduced in Bazel 7. +common --incompatible_enable_proto_toolchain_resolution diff --git a/MODULE.bazel b/MODULE.bazel index d8e387f5..d44b8457 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,7 +1,18 @@ +# Listed first so its protoc toolchain wins resolution over the protobuf module's, +# which is pulled in transitively by rules_go/rules_proto. +bazel_dep(name = "toolchains_protoc", version = "0.6.1") bazel_dep(name = "rules_go", version = "0.57.0") bazel_dep(name = "gazelle", version = "0.45.0") bazel_dep(name = "rules_proto", version = "7.1.0") +# Use a prebuilt protoc binary instead of compiling protoc (and its abseil/upb +# dependencies) from source on every cold build. Requires +# --incompatible_enable_proto_toolchain_resolution (set in .bazelrc). +protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") +use_repo(protoc, "toolchains_protoc_hub") + +register_toolchains("@toolchains_protoc_hub//:all") + GO_VERSION = "1.24.5" go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")