Skip to content

Commit 6ca8c34

Browse files
committed
Fix BCR build issues and add Bazel 9 support
Motivation: These changes are required for P4Runtime to build successfully for downstream users who depend on it via the BCR. Issues were discovered while upstreaming P4Runtime v1.5.0 to the BCR (bazelbuild/bazel-central-registry#7594) and when adding Bazel 9 support. Dependency updates: - Upgrade googleapis and replace the switched_rules extension with the new per-language modules (googleapis-cc, googleapis-go, googleapis-python, googleapis-grpc-cc). The old switched_rules extension only processes use_languages() calls from the root module, which breaks BCR presubmit and downstream users who don't call it themselves. - Upgrade grpc 1.68.0 -> 1.76.0, protobuf 29.1 -> 33.5, bazel_skylib 1.7.1 -> 1.9.0, rules_go 0.59.0 -> 0.60.0, re2 -> 2025-11-05.bcr.1. - Remove rules_proto and gazelle deps (no longer needed). - Load proto_library from @protobuf//bazel:proto_library.bzl instead of the deprecated @rules_proto//proto:defs.bzl. CI coverage gap fix: - Our example project in bazel/example/using-bzlmod only exercised some @p4runtime targets transitively, allowing build issues to slip through. - Fix: run bazel build @p4runtime//... from the example workspace. Bazel 9 support: - Remove the <9.0.0 upper bound from bazel_compatibility. - Update .bazelversion to 9.0.0. - Add --incompatible_autoload_externally=+cc_library,+cc_binary to .bazelrc files. Bazel 9 removed native C++ rules from the global namespace; this flag restores the autoload. It is a no-op on Bazel 7/8. (Workaround for two gRPC 1.76.0 bundled files that still use native.cc_binary / native.cc_library; can be dropped once a fixed gRPC BCR release ships.) - Update CI to test on Bazel 7.x and 9.x. Signed-off-by: Steffen Smolka <steffen.smolka@gmail.com>
1 parent a8e62aa commit 6ca8c34

File tree

9 files changed

+47
-29
lines changed

9 files changed

+47
-29
lines changed

.bazelignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# Exclude bazel sub-projects so `bazel build //...` works.
22
bazel/example
3+
4+
# Exclude Bazel output symlinks to avoid gnarly errors.
5+
bazel-bin
6+
bazel-out
7+
bazel-testlogs
8+
bazel-p4runtime

.bazelrc

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

5+
# In Bazel 9, native C++ rules are no longer injected into the global namespace
6+
# by default. Two files in grpc 1.76.0 still use native.cc_*:
7+
# bazel/cython_library.bzl (native.cc_binary)
8+
# third_party/address_sorting/address_sorting.bzl (native.cc_library)
9+
# Restore the autoload until grpc 1.76.0.bcr.2 lands. No-op on Bazel 7/8.
10+
build --incompatible_autoload_externally=+cc_library,+cc_binary
11+
512
# Use C++17 (required for recent gRPC versions).
613
build --cxxopt=-std=c++17
714
build --host_cxxopt=-std=c++17
15+
16+
# Extra flags needed to build on macOS.
17+
build --repo_env=CC=/usr/bin/clang
18+
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: 5 additions & 4 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, latest]
2625
# Don't abort other runs when one of them fails, to ease debugging.
2726
fail-fast: false
2827

@@ -62,10 +61,12 @@ jobs:
6261
format: X
6362

6463
- name: Build proto/
65-
run: cd proto && bazel build //... && bazel test //...
64+
run: bazel build //... && bazel test //...
6665

6766
- name: Build bazel/example/using-bzlmod/
68-
run: cd bazel/example/using-bzlmod && bazel build //...
67+
run: |
68+
cd bazel/example/using-bzlmod
69+
bazel build @p4runtime//... //...
6970
7071
- name: Save end time
7172
# Always save the end time so we can calculate the build duration.

MODULE.bazel

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
module(
22
name = "p4runtime",
3-
# TODO(#582): Remove upper bound once we support Bazel 9.x.
4-
bazel_compatibility = [">=7.0.0", "<9.0.0"],
53
# Fill in concrete versions only on release branches/in the BCR.
64
version = "head",
5+
bazel_compatibility = [">=7.0.0"],
76
)
87

9-
bazel_dep(name = "bazel_skylib", version = "1.7.1")
10-
bazel_dep(name = "rules_cc", version = "0.2.16")
11-
bazel_dep(name = "googleapis", version = "0.0.0-20240819-fe8ba054a")
12-
bazel_dep(name = "grpc", version = "1.68.0")
13-
bazel_dep(name = "protobuf", version = "29.1")
8+
bazel_dep(name = "bazel_skylib", version = "1.9.0")
9+
bazel_dep(name = "googleapis", version = "0.0.0-20260130-c0fcb356")
10+
bazel_dep(name = "googleapis-cc", version = "1.0.0")
11+
bazel_dep(name = "googleapis-go", version = "1.0.0")
12+
bazel_dep(name = "googleapis-python", version = "1.0.0")
13+
bazel_dep(name = "googleapis-grpc-cc", version = "1.0.0")
14+
bazel_dep(name = "grpc", version = "1.76.0")
15+
bazel_dep(name = "protobuf", version = "33.5")
16+
bazel_dep(name = "re2", version = "2025-11-05.bcr.1")
17+
bazel_dep(name = "rules_cc", version = "0.2.17")
18+
bazel_dep(name = "rules_go", version = "0.60.0")
1419
bazel_dep(name = "rules_license", version = "1.0.0")
15-
bazel_dep(name = "rules_proto", version = "7.0.2")
16-
bazel_dep(name = "rules_go", version = "0.59.0")
17-
bazel_dep(name = "gazelle", version = "0.45.0")
18-
19-
switched_rules = use_extension("@googleapis//:extensions.bzl", "switched_rules")
20-
switched_rules.use_languages(
21-
cc = True,
22-
go = True,
23-
grpc = True,
24-
python = True,
25-
)
26-
use_repo(switched_rules, googleapis_imports = "com_google_googleapis_imports")
2720

2821
# Including this allows us to auto-format all Bazel files by running
2922
# ```
3023
# bazel run -- @buildifier_prebuilt//:buildifier -lint=fix -r $(bazel info workspace)
3124
# ```
32-
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1.1", dev_dependency = True)
25+
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1.2", dev_dependency = True)

bazel/example/using-bzlmod/.bazelrc

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

5+
# In Bazel 9, native C++ rules are no longer injected into the global namespace
6+
# by default. Two files in grpc 1.76.0 still use native.cc_*:
7+
# bazel/cython_library.bzl (native.cc_binary)
8+
# third_party/address_sorting/address_sorting.bzl (native.cc_library)
9+
# Restore the autoload until grpc 1.76.0.bcr.2 lands. No-op on Bazel 7/8.
10+
build --incompatible_autoload_externally=+cc_library,+cc_binary
11+
512
# Use C++17 (required for recent gRPC versions).
613
build --cxxopt=-std=c++17
714
build --host_cxxopt=-std=c++17

bazel/example/using-bzlmod/MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
bazel_dep(name = "p4runtime")
2-
bazel_dep(name = "protobuf", version = "29.1")
3-
bazel_dep(name = "rules_cc", version = "0.2.16")
2+
bazel_dep(name = "protobuf", version = "33.5")
3+
bazel_dep(name = "rules_cc", version = "0.2.17")
44

55
# In your own project, you will likely want to use `git_override` instead
66
# of `local_repository` to load p4runtime.

proto/p4/config/v1/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
load("@bazel_skylib//rules:build_test.bzl", "build_test")
22
load("@grpc//bazel:python_rules.bzl", "py_proto_library")
33
load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
4+
load("@protobuf//bazel:proto_library.bzl", "proto_library")
45
load("@rules_go//proto:def.bzl", "go_proto_library")
5-
load("@rules_proto//proto:defs.bzl", "proto_library")
66

77
package(
88
default_visibility = ["//visibility:public"],

proto/p4/v1/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ load("@bazel_skylib//rules:build_test.bzl", "build_test")
22
load("@grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
33
load("@grpc//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library")
44
load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
5+
load("@protobuf//bazel:proto_library.bzl", "proto_library")
56
load("@rules_go//proto:def.bzl", "go_proto_library")
6-
load("@rules_proto//proto:defs.bzl", "proto_library")
77

88
package(
99
default_visibility = ["//visibility:public"],

0 commit comments

Comments
 (0)