Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Exclude bazel sub-projects so `bazel build //...` works.
bazel/example

# Exclude Bazel output symlinks to avoid gnarly errors.
bazel-bin
bazel-out
bazel-testlogs
bazel-p4runtime
12 changes: 12 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ common --noenable_workspace
# Use C++17 (required for recent gRPC versions).
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17

# In Bazel 9, native C++ rules (cc_library, cc_binary, …) are no longer
# injected into the global namespace by default. Some gRPC bundled sources
# (third_party/address_sorting/address_sorting.bzl) still use
# `native.cc_library`, so we restore the autoload until that is fixed
# upstream. The flag is a no-op in Bazel 7/8 where these rules remain
# native.
build --incompatible_autoload_externally=+cc_library,+cc_binary

# Extra flags needed to build on macOS.
build --repo_env=CC=/usr/bin/clang
build --macos_minimum_os=10.13
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.5.1
9.0.0
10 changes: 6 additions & 4 deletions .github/workflows/bazel-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
# We trust that things also work for versions in the middle.
os: [ubuntu-22.04, ubuntu-latest]
# See Bazelisk README for legal values.
# TODO(#582): Add back "latest" once we support Bazel 9.
bazel_version: [7.x, 8.x]
bazel_version: [7.x, 9.x]
# Don't abort other runs when one of them fails, to ease debugging.
fail-fast: false

Expand Down Expand Up @@ -62,10 +61,13 @@ jobs:
format: X

- name: Build proto/
run: cd proto && bazel build //... && bazel test //...
run: bazel build //... && bazel test //...

- name: Build bazel/example/using-bzlmod/
run: cd bazel/example/using-bzlmod && bazel build //...
run: |
cd bazel/example/using-bzlmod
bazel build @p4runtime//...
bazel build //...

- name: Save end time
# Always save the end time so we can calculate the build duration.
Expand Down
33 changes: 13 additions & 20 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
module(
name = "p4runtime",
# TODO(#582): Remove upper bound once we support Bazel 9.x.
bazel_compatibility = [">=7.0.0", "<9.0.0"],
# Fill in concrete versions only on release branches/in the BCR.
version = "head",
bazel_compatibility = [">=7.0.0"],
)

bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_cc", version = "0.2.16")
bazel_dep(name = "googleapis", version = "0.0.0-20240819-fe8ba054a")
bazel_dep(name = "grpc", version = "1.68.0")
bazel_dep(name = "protobuf", version = "29.1")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "googleapis", version = "0.0.0-20260130-c0fcb356")
bazel_dep(name = "googleapis-cc", version = "1.0.0")
bazel_dep(name = "googleapis-go", version = "1.0.0")
bazel_dep(name = "googleapis-python", version = "1.0.0")
bazel_dep(name = "googleapis-grpc-cc", version = "1.0.0")
bazel_dep(name = "grpc", version = "1.76.0")
bazel_dep(name = "protobuf", version = "33.5")
bazel_dep(name = "rules_cc", version = "0.2.17")
bazel_dep(name = "rules_go", version = "0.60.0")
bazel_dep(name = "re2", version = "2025-11-05.bcr.1")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.0.2")
bazel_dep(name = "rules_go", version = "0.59.0")
bazel_dep(name = "gazelle", version = "0.45.0")

switched_rules = use_extension("@googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(
cc = True,
go = True,
grpc = True,
python = True,
)
use_repo(switched_rules, googleapis_imports = "com_google_googleapis_imports")

# Including this allows us to auto-format all Bazel files by running
# ```
# bazel run -- @buildifier_prebuilt//:buildifier -lint=fix -r $(bazel info workspace)
# ```
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1.2", dev_dependency = True)
5 changes: 5 additions & 0 deletions bazel/example/using-bzlmod/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
common --enable_bzlmod
common --noenable_workspace

# In Bazel 9, native C++ rules are no longer injected globally by default.
# Some gRPC bundled sources still use `native.cc_library`/`native.cc_binary`,
# so we restore the autoload until that is fixed upstream. No-op on Bazel 7/8.
build --incompatible_autoload_externally=+cc_library,+cc_binary

# Use C++17 (required for recent gRPC versions).
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17
4 changes: 2 additions & 2 deletions bazel/example/using-bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bazel_dep(name = "p4runtime")
bazel_dep(name = "protobuf", version = "29.1")
bazel_dep(name = "rules_cc", version = "0.2.16")
bazel_dep(name = "protobuf", version = "33.5")
bazel_dep(name = "rules_cc", version = "0.2.17")

# In your own project, you will likely want to use `git_override` instead
# of `local_repository` to load p4runtime.
Expand Down
2 changes: 1 addition & 1 deletion proto/p4/config/v1/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@grpc//bazel:python_rules.bzl", "py_proto_library")
load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_go//proto:def.bzl", "go_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")

package(
default_visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion proto/p4/v1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load("@grpc//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library")
load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_go//proto:def.bzl", "go_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")

package(
default_visibility = ["//visibility:public"],
Expand Down