Skip to content

Fix BCR build issues and add Bazel 9 support#590

Open
smolkaj wants to merge 1 commit intomainfrom
update-bazel-deps
Open

Fix BCR build issues and add Bazel 9 support#590
smolkaj wants to merge 1 commit intomainfrom
update-bazel-deps

Conversation

@smolkaj
Copy link
Member

@smolkaj smolkaj commented Feb 19, 2026

This PR does three things:

  1. Fix build issues discovered when adding P4Runtime to the Bazel Central Registry (Add p4runtime 1.5.0 (initial release to BCR) bazelbuild/bazel-central-registry#7594)
  2. Fix the gap in our CI scripts that allowed these build issues to slip through
  3. Add Bazel 9 support

Fix BCR build issues (details on 1)

TL;DR: update various dependencies to newer versions. See the commit message for details.

Fix CI gap (details on 2)

  • In Bazel, it is possible that a project builds from its own workspace but fails when depended on from another workspace.
  • We have an example project in bazel/example/using-bzlmod that we build in CI to cover this case, but it was only exercising some @p4runtime targets transitively.
  • Fix: run bazel build @p4runtime//... from the example workspace to close the gap.

Bazel 9 support (details on 3)

  • Remove the <9.0.0 upper bound from bazel_compatibility and bump .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 them. It is a no-op on Bazel 7/8. Two files in grpc 1.76.0 still use native.cc_*:
    • bazel/cython_library.bzl (native.cc_binary)
    • third_party/address_sorting/address_sorting.bzl (native.cc_library)
  • Pin re2 to 2025-11-05.bcr.1: grpc 1.76.0 pulls in re2 2024-07-02, whose BUILD uses cc_test without a load() — a Bazel 9 hard error.
  • Update CI to test on Bazel 7.x and 9.x.

The workarounds above can be dropped once grpc 1.76.0.bcr.2 lands in BCR (bazelbuild/bazel-central-registry#7749), which fixes both native.cc_* usages and the re2 issue.

This also supersedes #597.

@smolkaj smolkaj changed the title Update Bazel dependencies and migrate off googleapis switched_rules Fix issues when building P4runtime from another Bazel workspace Feb 20, 2026
@smolkaj smolkaj force-pushed the update-bazel-deps branch 3 times, most recently from 6640339 to 1833d12 Compare February 20, 2026 03:46
@smolkaj smolkaj changed the title Fix issues when building P4runtime from another Bazel workspace Fix BCR build issues and add Bazel 9 support Mar 1, 2026
@smolkaj smolkaj mentioned this pull request Mar 1, 2026
3 tasks
@smolkaj smolkaj force-pushed the update-bazel-deps branch 8 times, most recently from 0f84e6a to 6ca8c34 Compare March 1, 2026 04:28
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>
@smolkaj smolkaj force-pushed the update-bazel-deps branch from 6ca8c34 to 77269af Compare March 1, 2026 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant