Bazel: Don't build protobuf from the source
Gerrit is pure java project. Given that it depends on Google protobuf,
and given that Bazel was using @com_google_protobuf toolchain that was
built from source, this project ended up bulding the Google protobuf
from source.
Compiling protoc from source requires a functional C++ toolchain,
which is a burden for projects that have no C++ code. Also, Bazel
does not ship with a hermetic toolchain, so that it is possible
that for many Gerrit developers and contributors the Bazel build
is inherently broken.
In addition, building protobuf from source made OS upgrades difficult
because of the incompatibilities between the source code and the latest XCode versions.
That changed in Bazel 7.x release, with the new and shiny option:
--incompatible_enable_proto_toolchain_resolution, that allow to register
prebuilt protoc toolchains.
In addition rules_proto have added support for prebuilt toolchains in
context of this tracking issue: [1].
In this change we use toolchains_protoc project to consume predefined
protobuf toolchains: [2].
As the side effect of this change we have to consume protobuf-java
ourself and not transitively through standard @com_google_protobuf
toolchain. Given that Google protobuf is internal Google project and
all released versions already available within Google, we add the new
dependency to tools/nongoogle.bzl to exempt the updates for it from the
Library-Compliance label.
Now, that we stop building protobuf from source, we can remove C++
options in .bazelrc as well.
[1] https://github.com/bazelbuild/rules_proto/issues/179
[2] https://github.com/aspect-build/toolchains_protoc
Release-Notes: Use prebuilt protobuf toolchain to avoid building protoc from source
Change-Id: I27975879819c4b632682990474ce88737f722d9a
diff --git a/.bazelrc b/.bazelrc
index 480bea7..74427f3 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -1,6 +1,7 @@
# TODO(davido): Migrate all dependencies from WORKSPACE to MODULE.bazel
# https://issues.gerritcodereview.com/issues/303819949
common --noenable_bzlmod
+common --incompatible_enable_proto_toolchain_resolution
build --workspace_status_command="python3 ./tools/workspace_status.py"
build --repository_cache=~/.gerritcodereview/bazel-cache/repository
@@ -51,10 +52,6 @@
build:remote21_bb --config=config_bb
build:remote21_bb --config=build_java21_shared
-# Enable modern C++ features
-build --cxxopt=-std=c++17
-build --host_cxxopt=-std=c++17
-
# Enable strict_action_env flag to. For more information on this feature see
# https://groups.google.com/forum/#!topic/bazel-discuss/_VmRfMyyHBk.
# This will be the new default behavior at some point (and the flag was flipped