Skip to content

Commit a580e32

Browse files
smolkajclaude
andcommitted
Support Bazel 9
Bazel 9 removed native C++ rules from the global namespace by default (native.cc_binary, native.cc_library). Two gRPC 1.76.0 bundled files still use these: - bazel/cython_library.bzl uses native.cc_binary - third_party/address_sorting/address_sorting.bzl uses native.cc_library Use --incompatible_autoload_externally=+cc_library,+cc_binary to restore the autoload for those rules. This flag is a no-op in Bazel 7/8 where the rules remain native. Also: - Bump re2 to 2025-11-05.bcr.1 (BCR grpc 1.76.0 pulls in re2 2024-07-02.bcr.1 whose BUILD uses cc_test without load(), which is another Bazel 9 error; the 2025-11-05 release fixes that). - Remove the <9.0.0 upper bound from bazel_compatibility. - Update .bazelversion to 9.0.0. - Add 9.x to the CI matrix and remove the "once we support Bazel 9" TODO. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1833d12 commit a580e32

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

.bazelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@ common --noenable_workspace
55
# Use C++17 (required for recent gRPC versions).
66
build --cxxopt=-std=c++17
77
build --host_cxxopt=-std=c++17
8+
9+
# In Bazel 9, native C++ rules (cc_library, cc_binary, …) are no longer
10+
# injected into the global namespace by default. Some gRPC bundled sources
11+
# (third_party/address_sorting/address_sorting.bzl) still use
12+
# `native.cc_library`, so we restore the autoload until that is fixed
13+
# upstream. The flag is a no-op in Bazel 7/8 where these rules remain
14+
# native.
15+
build --incompatible_autoload_externally=+cc_library,+cc_binary
16+
17+
# Extra flags needed to build on macOS.
18+
build --repo_env=CC=/usr/bin/clang
19+
build --macos_minimum_os=10.13

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.5.1
1+
9.0.0

.github/workflows/bazel-build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ jobs:
2121
# We trust that things also work for versions in the middle.
2222
os: [ubuntu-22.04, ubuntu-latest]
2323
# See Bazelisk README for legal values.
24-
# TODO(#582): Add back "latest" once we support Bazel 9.
25-
bazel_version: [7.x, 8.x]
24+
bazel_version: [7.x, 8.x, 9.x]
2625
# Don't abort other runs when one of them fails, to ease debugging.
2726
fail-fast: false
2827

MODULE.bazel

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ module(
22
name = "p4runtime",
33
# Fill in concrete versions only on release branches/in the BCR.
44
version = "head",
5-
# TODO(#582): Remove upper bound once we support Bazel 9.x.
6-
bazel_compatibility = [
7-
">=7.0.0",
8-
"<9.0.0",
9-
],
5+
bazel_compatibility = [">=7.0.0"],
106
)
117

128
bazel_dep(name = "bazel_skylib", version = "1.9.0")
@@ -19,6 +15,7 @@ bazel_dep(name = "grpc", version = "1.76.0")
1915
bazel_dep(name = "protobuf", version = "33.5")
2016
bazel_dep(name = "rules_cc", version = "0.2.17")
2117
bazel_dep(name = "rules_go", version = "0.60.0")
18+
bazel_dep(name = "re2", version = "2025-11-05.bcr.1")
2219
bazel_dep(name = "rules_license", version = "1.0.0")
2320

2421
# Including this allows us to auto-format all Bazel files by running

bazel/example/using-bzlmod/.bazelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
common --enable_bzlmod
33
common --noenable_workspace
44

5+
# In Bazel 9, native C++ rules are no longer injected globally by default.
6+
# Some gRPC bundled sources still use `native.cc_library`/`native.cc_binary`,
7+
# so we restore the autoload until that is fixed upstream. No-op on Bazel 7/8.
8+
build --incompatible_autoload_externally=+cc_library,+cc_binary
9+
510
# Use C++17 (required for recent gRPC versions).
611
build --cxxopt=-std=c++17
712
build --host_cxxopt=-std=c++17

0 commit comments

Comments
 (0)