Skip to content
Merged
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
14 changes: 13 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
build --conlyopt='-std=gnu11' --cxxopt='-std=gnu++17'
# Use Bzlmod (`MODULE.bazel`) instead of `WORKSPACE.bazel`.
common --enable_bzlmod
common --noenable_workspace

# In Bazel 9, native C++ rules are no longer injected into the global namespace
# by default. 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)
# Restore the autoload until grpc 1.76.0.bcr.2 lands. No-op on Bazel 7/8.
build --incompatible_autoload_externally=+cc_library,+cc_binary

build --conlyopt='-std=gnu11' --cxxopt='-std=c++17'
build --host_cxxopt='-std=c++17'
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.4.0
9.0.0
68 changes: 44 additions & 24 deletions .github/workflows/bazel-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,58 @@ name: "Test Bazel Build"

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
schedule:
- cron: "0 0 * * *"

jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
env:
BAZEL: bazelisk-linux-amd64
BUILDIFIER: buildifier-linux-amd64
steps:
- uses: actions/checkout@v6
with:
submodules: recursive

- name: Mount bazel cache
uses: actions/cache@v5
with:
# See https://docs.bazel.build/versions/master/output_directories.html
path: "~/.cache/bazel"
# Create a new cache entry whenever Bazel files change.
# See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
key: bazel-${{ runner.os }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }}
restore-keys: |
bazel-${{ runner.os }}-build-
- uses: actions/checkout@v6
with:
submodules: recursive

- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.15.0/$BAZEL"
chmod +x $BAZEL
sudo mv $BAZEL /usr/local/bin/bazel
- name: Mount bazel cache
uses: actions/cache@v5
with:
# See https://docs.bazel.build/versions/master/output_directories.html
path: "~/.cache/bazel"
# Create a new cache entry whenever Bazel files change.
# See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
key: bazel-${{ runner.os }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }}
restore-keys: |
bazel-${{ runner.os }}-build-

- name: Build and run tests
run: bazel test //proto/tests:pi_proto_tests //proto/tests:pi_proto_server_tests
- name: Install Buildifier
run: |
curl -LO "https://github.com/bazelbuild/buildtools/releases/download/v8.5.1/$BUILDIFIER"
chmod +x $BUILDIFIER
sudo mv $BUILDIFIER /usr/local/bin/buildifier

- name: Run Buildifier
run: |
BZL_FILES=$(git ls-files | grep -E 'BUILD.*|\.bzl$|\.bazel$')
if ! buildifier --mode=check $BZL_FILES; then
echo "::error::Buildifier formatting issues found."
echo "::group::Buildifier Diff"
buildifier --mode=diff $BZL_FILES
echo "::endgroup::"
exit 1
else
echo "All files are formatted correctly."
fi

- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.29.0/$BAZEL"
chmod +x $BAZEL
sudo mv $BAZEL /usr/local/bin/bazel

- name: Build and run tests
run: bazel test //proto/tests:pi_proto_tests //proto/tests:pi_proto_server_tests
67 changes: 48 additions & 19 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

package(
default_visibility = ["//visibility:public"],
)
Expand All @@ -12,38 +14,65 @@ cc_library(
name = "piutils",
srcs = glob(["src/utils/*.c"]) + ["//:pihdrs"],
hdrs = glob(["src/utils/*.h"]),
includes = ["src/utils", "include"],
deps = [],
includes = [
"include",
"src/utils",
],
visibility = ["//:__subpackages__"],
)


cc_library(
name = "pip4info",
srcs = ["src/p4info_int.h", ":pihdrs"]
+ glob(["src/p4info/*.c", "src/p4info/*.h"])
+ glob(["src/config_readers/*.c", "src/config_readers/*.h"]),
srcs = [
"src/p4info_int.h",
":pihdrs",
] + glob([
"src/p4info/*.c",
"src/p4info/*.h",
]) + glob([
"src/config_readers/*.c",
"src/config_readers/*.h",
]),
hdrs = glob(["include/PI/p4info/*.h"]),
includes = ["include", "src"],
copts = ["-DPI_LOG_ON"],
deps = ["//third_party/cJSON:picjson",
"//third_party:piuthash",
"//lib:pitoolkit",
":piutils"],
includes = [
"include",
"src",
],
deps = [
":piutils",
"//lib:pitoolkit",
"//third_party:piuthash",
"//third_party/cJSON:picjson",
],
)

# using glob looks a bit nasty because of the files we have to exclude, but in
# the absence of a CI for the Bazel build, it is less error-prone that listing
# all files manually.
cc_library(
name = "pi",
srcs = [":pihdrs"]
+ glob(["src/*.c"], exclude=[
"src/pi_notifications_pub.c", "src/pi_rpc_server.c"])
+ glob(["src/*.h"], exclude=[
"src/p4info_int.h", "src/pi_notifications_pub.h"]),
hdrs = glob(["include/PI/*.h", "include/PI/target/*.h"])
+ ["include/PI/int/pi_int.h", "include/PI/int/serialize.h"],
srcs = [":pihdrs"] +
glob(
["src/*.c"],
exclude = [
"src/pi_notifications_pub.c",
"src/pi_rpc_server.c",
],
) + glob(
["src/*.h"],
exclude = [
"src/p4info_int.h",
"src/pi_notifications_pub.h",
],
),
hdrs = glob([
"include/PI/*.h",
"include/PI/target/*.h",
]) + [
"include/PI/int/pi_int.h",
"include/PI/int/serialize.h",
],
includes = ["include"],
deps = [":pip4info"],
)
Expand All @@ -52,7 +81,7 @@ cc_library(
name = "pifegeneric",
srcs = ["src/frontends/generic/pi.c"],
hdrs = ["include/PI/frontends/generic/pi.h"],
includes = ["include"],
copts = ["-DPI_LOG_ON"],
includes = ["include"],
deps = [":pi"],
)
21 changes: 21 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module(
name = "com_github_p4lang_pi",
# 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.9.0")
bazel_dep(name = "boost.container_hash", version = "1.90.0.bcr.1")
bazel_dep(name = "googleapis", version = "0.0.0-20260130-c0fcb356", repo_name = "com_google_googleapis")
bazel_dep(name = "googletest", version = "1.17.0.bcr.2", repo_name = "com_google_googletest")
bazel_dep(name = "grpc", version = "1.76.0", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "p4runtime", version = "1.5.0.bcr.1", repo_name = "com_github_p4lang_p4runtime")
bazel_dep(name = "protobuf", version = "33.5", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_cc", version = "0.2.17")

# 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.5.1.2", dev_dependency = True)
53 changes: 5 additions & 48 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,48 +1,5 @@
workspace(name = "com_github_p4lang_PI")

load("//bazel:deps.bzl", "PI_deps")
PI_deps()

load("@com_github_p4lang_p4runtime//:p4runtime_deps.bzl", "p4runtime_deps")
p4runtime_deps()

# -- Transitive dependencies of P4Runtime dependencies -------------------------

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()

load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
switched_rules_by_language(
name = "com_google_googleapis_imports",
grpc = True,
cc = True,
python = True,
)

load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
grpc_deps()
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
grpc_extra_deps()
load("@com_github_grpc_grpc//bazel:grpc_python_deps.bzl", "grpc_python_deps")
grpc_python_deps()

load("@rules_python//python:pip.bzl", "pip_parse")
pip_parse(
name = "grpc_python_dependencies",
requirements_lock = "@com_github_grpc_grpc//:requirements.bazel.txt",
)

load("@grpc_python_dependencies//:requirements.bzl", "install_deps")
install_deps()

# -- Boost dependencies -------------------------

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()
# https://bazel.build/external/migration#workspace.bzlmod
#
# This file is intentionally empty. When bzlmod is enabled and this
# file exists, the contents of WORKSPACE.bazel is ignored. This prevents
# bzlmod builds from unintentionally depending on the WORKSPACE.bazel file.
72 changes: 0 additions & 72 deletions bazel/deps.bzl

This file was deleted.

37 changes: 0 additions & 37 deletions bazel/external/gnmi.BUILD

This file was deleted.

Loading