Skip to content

Commit b927c90

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 b927c90

File tree

11 files changed

+51
-33
lines changed

11 files changed

+51
-33
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: 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: 6 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, 9.x]
2625
# Don't abort other runs when one of them fails, to ease debugging.
2726
fail-fast: false
2827

@@ -62,10 +61,13 @@ 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//...
70+
bazel build //...
6971
7072
- name: Save end time
7173
# 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 = "rules_cc", version = "0.2.17")
17+
bazel_dep(name = "rules_go", version = "0.60.0")
18+
bazel_dep(name = "re2", version = "2025-11-05.bcr.1")
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: 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

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.

docs/v1/P4Runtime-Spec.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ practical to have a hybrid use-case as described in subsequent sections.
431431

432432
.Use-Case: Single Remote Controller
433433
[#fig-single-remote-controller]
434-
image::single-remote-controller.png[width=400,align="center"]
434+
image::single-embedded-controller.png[width=400,align="center"]
435435

436436

437437
=== Embedded + Single Remote Controller
@@ -475,7 +475,7 @@ role-based client arbitration scheme supports it.
475475

476476
.Use-Case: Embedded Plus Two Remote High-Availability Controllers
477477
[#fig-embedded-plus-two-remote-ha-controllers]
478-
image::embedded-plus-two-remote-ha-controllers.png[width=400,align="center"]
478+
image::embedded-plus-two-remote-controllers.png[width=400,align="center"]
479479

480480
[#sec-client-arbitration-and-controller-replication]
481481
== Client Arbitration and Controller Replication

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)