diff --git a/.bazelrc b/.bazelrc index c0462c2c..c388cac1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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' diff --git a/.bazelversion b/.bazelversion index 8a30e8f9..f7ee0669 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.4.0 +9.0.0 diff --git a/.github/workflows/bazel-build.yml b/.github/workflows/bazel-build.yml index 7ed8d2c7..26e9765a 100644 --- a/.github/workflows/bazel-build.yml +++ b/.github/workflows/bazel-build.yml @@ -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 diff --git a/BUILD b/BUILD index da7b7f10..a85b439d 100644 --- a/BUILD +++ b/BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + package( default_visibility = ["//visibility:public"], ) @@ -12,24 +14,37 @@ 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 @@ -37,13 +52,27 @@ cc_library( # 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"], ) @@ -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"], ) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..3291258b --- /dev/null +++ b/MODULE.bazel @@ -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) diff --git a/WORKSPACE b/WORKSPACE index af39dddb..203f54c6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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. diff --git a/bazel/deps.bzl b/bazel/deps.bzl deleted file mode 100644 index e50907a9..00000000 --- a/bazel/deps.bzl +++ /dev/null @@ -1,72 +0,0 @@ -"""Load dependencies needed to compile PI as a 3rd-party consumer.""" - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("//bazel:workspace_rule.bzl", "remote_workspace") - -GNMI_COMMIT="39cb2fffed5c9a84970bde47b3d39c8c716dc17a"; -GNMI_SHA="3701005f28044065608322c179625c8898beadb80c89096b3d8aae1fbac15108"; - -# P4RUNTIME_TAG = "1.3.0" -# We cannot use the latest release (v1.3.0) as we need to include a recent fix -# to support Bazel 5.0. More precisely, this fix updates the Bazel build -# dependencies to more recent versions compatible with Bazel 5.0. -P4RUNTIME_COMMIT="ec4eb5ef70dbcbcbf2f8357a4b2b8c2f218845a5" -P4RUNTIME_SHA="ea8b7744c45afa7a78a90a1a4232b5fbb386b6714dc16c9b1ea643398889c92b" - -def PI_deps(): - """Loads dependencies needed to compile PI.""" - - if "com_github_p4lang_p4runtime" not in native.existing_rules(): - http_archive( - name = "com_github_p4lang_p4runtime", - # urls = ["https://github.com/p4lang/p4runtime/archive/v%s.zip" % P4RUNTIME_TAG], - urls = ["https://github.com/p4lang/p4runtime/archive/%s.zip" % P4RUNTIME_COMMIT], - sha256 = P4RUNTIME_SHA, - # strip_prefix = "p4runtime-%s/proto" % P4RUNTIME_TAG, - strip_prefix = "p4runtime-%s/proto" % P4RUNTIME_COMMIT, - ) - - if "com_google_absl" not in native.existing_rules(): - http_archive( - name = "com_google_absl", - sha256 = "4208129b49006089ba1d6710845a45e31c59b0ab6bff9e5788a87f55c5abd602", - strip_prefix = "abseil-cpp-20220623.0", - urls = [ - "https://storage.googleapis.com/grpc-bazel-mirror/github.com/abseil/abseil-cpp/archive/20220623.0.tar.gz", - "https://github.com/abseil/abseil-cpp/archive/20220623.0.tar.gz", - ], - ) - - if "com_github_openconfig_gnmi" not in native.existing_rules(): - http_archive( - name = "com_github_openconfig_gnmi", - url = "https://github.com/openconfig/gnmi/archive/%s.zip" % GNMI_COMMIT, - sha256 = GNMI_SHA, - strip_prefix = "gnmi-%s/proto" % GNMI_COMMIT, - build_file = "@//bazel:external/gnmi.BUILD", - patch_cmds = [ - "sed -i.bak 's#github.com/openconfig/gnmi/proto/##g' gnmi/gnmi.proto", - "rm gnmi/gnmi.proto.bak" - ], - ) - - if "com_google_googletest" not in native.existing_rules(): - remote_workspace( - name = "com_google_googletest", - remote = "https://github.com/google/googletest", - commit = "f5edb4f542e155c75bc4b516f227911d99ec167c", - ) - - if "com_google_googleapis" not in native.existing_rules(): - remote_workspace( - name = "com_google_googleapis", - remote = "https://github.com/googleapis/googleapis", - commit = "9fe00a1330817b5ce00919bf2861cd8a9cea1a00", - ) - - if "com_github_nelhage_rules_boost" not in native.existing_rules(): - remote_workspace( - name = "com_github_nelhage_rules_boost", - remote = "https://github.com/nelhage/rules_boost", - commit = "7523a494d35098dfd972399963b00b71064cbb11", - ) diff --git a/bazel/external/gnmi.BUILD b/bazel/external/gnmi.BUILD deleted file mode 100644 index 57bb1c2a..00000000 --- a/bazel/external/gnmi.BUILD +++ /dev/null @@ -1,37 +0,0 @@ -load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") - -package( - default_visibility = [ "//visibility:public" ], -) - -proto_library( - name = "gnmi_ext_proto", - srcs = ["gnmi_ext/gnmi_ext.proto"], -) - -proto_library( - name = "gnmi_proto", - srcs = ["gnmi/gnmi.proto"], - deps = [ - ":gnmi_ext_proto", - "@com_google_protobuf//:descriptor_proto", - "@com_google_protobuf//:any_proto", - ], -) - -cc_proto_library( - name = "gnmi_ext_cc_proto", - deps = [":gnmi_ext_proto"] -) - -cc_proto_library( - name = "gnmi_cc_proto", - deps = ["@com_github_openconfig_gnmi//:gnmi_proto"], -) - -cc_grpc_library( - name = "gnmi_cc_grpc", - srcs = [":gnmi_proto"], - deps = [":gnmi_cc_proto"], - grpc_only = True, -) \ No newline at end of file diff --git a/bazel/workspace_rule.bzl b/bazel/workspace_rule.bzl deleted file mode 100644 index 579490ed..00000000 --- a/bazel/workspace_rule.bzl +++ /dev/null @@ -1,130 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") -_strict = False - -def _build_http_archive( - name, - remote, - branch = None, - commit = None, - tag = None, - build_file = None, - patch_cmds = [], - ): - if not remote.startswith("https://github.com"): - # This is only currently support for github repos - return False - - # Fix remote suffix - if remote.endswith(".git"): - remote = remote[:-4] - elif remote.endswith("/"): - remote = remote[:-1] - - # Tranform repo URL to archive URL - repo_name = remote.split("/")[-1] - if tag: - urls = ["%s/archive/v%s.zip" % (remote, tag)] - prefix = repo_name + "-" + tag - if commit or branch: - ref = commit if commit else branch - urls = ["%s/archive/%s.zip" % (remote, ref)] - prefix = repo_name + "-" + ref - - # Generate http_archive rule - if build_file: - http_archive( - name = name, - urls = urls, - strip_prefix = prefix, - build_file = build_file, - patch_cmds = patch_cmds, - ) - else: - http_archive( - name = name, - urls = urls, - strip_prefix = prefix, - patch_cmds = patch_cmds, - ) - return True - -def _build_git_repository( - name, - remote, - branch = None, - commit = None, - tag = None, - build_file = None, - patch_cmds = [], - ): - - # Strip trailing / from remote - if remote.endswith("/"): - remote = remote[:-1] - - # Generate the git_repository rule - if build_file: - git_repository( - name = name, - remote = remote, - branch = branch, - commit = commit, - tag = tag, - build_file = build_file, - patch_cmds = patch_cmds, - ) - else: - git_repository( - name = name, - remote = remote, - branch = branch, - commit = commit, - tag = tag, - patch_cmds = patch_cmds, - ) - return True - -def remote_workspace( - name, - remote, - branch = None, - commit = None, - tag = None, - build_file = None, - use_git = False, - patch_cmds = [] - ): - ref_count = 0 - if branch: - ref_count += 1 - if commit: - ref_count += 1 - if tag: - ref_count += 1 - - if ref_count == 0: - fail("one of branch, commit or tag must be set for " + name) - elif ref_count > 1: - fail("only one of branch, commit, or tag can be set for " + name) - - if commit and len(commit) != 40: - fail("You must use the full commit hash for " + name) - use_git = True - print("using git for ", name, remote) - - if _strict and branch: - print("Warning: external workspace, %s, " % name + - "should refer to a specific tag or commit (currently: %s)" % branch) - - # Prefer http_archive - if not use_git and _build_http_archive( - name, remote, branch, commit, tag, build_file, patch_cmds): - return - - # Fall back to git_repository - if _build_git_repository( - name, remote, branch, commit, tag, build_file, patch_cmds): - return - - fail("could not generate remote workspace for " + name) diff --git a/frontends_extra/cpp/BUILD b/frontends_extra/cpp/BUILD index 18dee03b..deaae1cc 100644 --- a/frontends_extra/cpp/BUILD +++ b/frontends_extra/cpp/BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + package( default_visibility = ["//visibility:public"], ) diff --git a/lib/BUILD b/lib/BUILD index 53c388db..b7ef5a2f 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + package( default_visibility = ["//:__subpackages__"], ) @@ -7,5 +9,4 @@ cc_library( srcs = glob(["*.c"]), hdrs = glob(["*.h"]), includes = ["."], - deps = [], ) diff --git a/proto/BUILD b/proto/BUILD index 80d5834f..f3351774 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -1,20 +1,23 @@ +load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") +load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") +load("@rules_cc//cc:defs.bzl", "cc_library") + package( default_visibility = ["//visibility:public"], ) -load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") - cc_library( name = "piprotoutil", srcs = ["src/util.cpp"], hdrs = ["PI/proto/util.h"], includes = ["."], - deps = ["@com_github_p4lang_p4runtime//:p4info_cc_proto"], + deps = ["@com_github_p4lang_p4runtime//proto/p4/config/v1:p4info_cc_proto"], ) proto_library( name = "p4config_proto", - srcs = ["p4/tmp/p4config.proto"] + srcs = ["p4/tmp/p4config.proto"], ) cc_proto_library( @@ -27,13 +30,13 @@ cc_library( srcs = ["server_config/server_config.cpp"], hdrs = ["server_config/server_config.h"], includes = ["."], - deps = [":p4serverconfig_cc_proto"], visibility = ["//proto:__subpackages__"], + deps = [":p4serverconfig_cc_proto"], ) proto_library( name = "p4serverconfig_proto", - srcs = ["p4/server/v1/config.proto"] + srcs = ["p4/server/v1/config.proto"], ) cc_proto_library( @@ -44,6 +47,28 @@ cc_proto_library( cc_grpc_library( name = "p4serverconfig_cc_grpc", srcs = [":p4serverconfig_proto"], + grpc_only = True, deps = [":p4serverconfig_cc_proto"], +) + +proto_library( + name = "gnmi_proto", + srcs = ["openconfig/gnmi/proto/gnmi/gnmi.proto"], + strip_import_prefix = "openconfig/gnmi/proto", + deps = [ + "@com_google_protobuf//:any_proto", + "@com_google_protobuf//:descriptor_proto", + ], +) + +cc_proto_library( + name = "gnmi_cc_proto", + deps = [":gnmi_proto"], +) + +cc_grpc_library( + name = "gnmi_cc_grpc", + srcs = [":gnmi_proto"], grpc_only = True, + deps = [":gnmi_cc_proto"], ) diff --git a/proto/frontend/BUILD b/proto/frontend/BUILD index 24fb24d5..23702378 100644 --- a/proto/frontend/BUILD +++ b/proto/frontend/BUILD @@ -1,25 +1,32 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + package( default_visibility = ["//visibility:public"], ) cc_library( name = "pifeproto", - srcs = glob(["src/*.cpp", "src/*.h"]), - hdrs = ["PI/frontends/proto/device_mgr.h", - "PI/frontends/proto/logging.h"], + srcs = glob([ + "src/*.cpp", + "src/*.h", + ]), + hdrs = [ + "PI/frontends/proto/device_mgr.h", + "PI/frontends/proto/logging.h", + ], includes = ["."], - copts = ["-DUSE_ABSL=1"], - deps = ["@com_github_p4lang_p4runtime//:p4runtime_cc_grpc", - "@com_github_p4lang_p4runtime//:p4runtime_cc_proto", - "@com_google_googleapis//google/rpc:code_cc_proto", - "@com_google_protobuf//:protobuf", - "@com_github_grpc_grpc//:grpc++", - "//proto:p4serverconfig_cc_proto", - "//proto:piprotoutil", - "//proto:piprotoserverconfig", - "//proto/third_party:fmt", - "//proto:p4config_cc_proto", - "//frontends_extra/cpp:pifecpp", - "//proto/p4info:piconvertproto", - "@com_google_absl//absl/synchronization:synchronization"], + deps = [ + "//frontends_extra/cpp:pifecpp", + "//proto:p4config_cc_proto", + "//proto:p4serverconfig_cc_proto", + "//proto:piprotoserverconfig", + "//proto:piprotoutil", + "//proto/p4info:piconvertproto", + "//proto/third_party:fmt", + "@com_github_grpc_grpc//:grpc++", + "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_grpc", + "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_proto", + "@com_google_googleapis//google/rpc:code_cc_proto", + "@com_google_protobuf//:protobuf", + ], ) diff --git a/proto/p4info/BUILD b/proto/p4info/BUILD index 8a7eb9ae..97e2ab09 100644 --- a/proto/p4info/BUILD +++ b/proto/p4info/BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + package( default_visibility = ["//visibility:public"], ) @@ -7,8 +9,10 @@ cc_library( srcs = ["p4info_to_and_from_proto.cpp"], hdrs = ["PI/proto/p4info_to_and_from_proto.h"], includes = ["."], - deps = ["//:pip4info", - "@com_github_p4lang_p4runtime//:p4info_cc_proto"], + deps = [ + "//:pip4info", + "@com_github_p4lang_p4runtime//proto/p4/config/v1:p4info_cc_proto", + ], ) cc_binary( diff --git a/proto/server/BUILD b/proto/server/BUILD index 9b93239a..5f0fddb0 100644 --- a/proto/server/BUILD +++ b/proto/server/BUILD @@ -1,22 +1,30 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + package( default_visibility = ["//visibility:public"], ) cc_library( name = "piserver", - srcs = ["gnmi_dummy.cpp", - "log.h", - "pi_server.cpp", - "uint128.h", - "uint128.cpp"], - hdrs = ["PI/proto/pi_server.h", "pi_server_testing.h", "gnmi.h"], - copts = ["-DUSE_ABSL=1"], - deps = ["@com_github_p4lang_p4runtime//:p4runtime_cc_grpc", - "@com_google_googleapis//google/rpc:code_cc_proto", - "@com_google_protobuf//:protobuf", - "@com_github_grpc_grpc//:grpc++", - "@com_github_openconfig_gnmi//:gnmi_cc_grpc", - "//proto:p4serverconfig_cc_grpc", - "//proto/frontend:pifeproto", - "@com_google_absl//absl/synchronization:synchronization"], + srcs = [ + "gnmi_dummy.cpp", + "log.h", + "pi_server.cpp", + "uint128.cpp", + "uint128.h", + ], + hdrs = [ + "PI/proto/pi_server.h", + "gnmi.h", + "pi_server_testing.h", + ], + deps = [ + "//proto:gnmi_cc_grpc", + "//proto:p4serverconfig_cc_grpc", + "//proto/frontend:pifeproto", + "@com_github_grpc_grpc//:grpc++", + "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_grpc", + "@com_google_googleapis//google/rpc:code_cc_proto", + "@com_google_protobuf//:protobuf", + ], ) diff --git a/proto/tests/BUILD b/proto/tests/BUILD index ad011646..50311d57 100644 --- a/proto/tests/BUILD +++ b/proto/tests/BUILD @@ -1,49 +1,68 @@ +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + package( default_visibility = ["//visibility:private"], ) cc_library( name = "testutils", - srcs = ["main.cpp", - "matchers.cpp", - "mock_switch.cpp", - "stream_receiver.h"], - hdrs = ["matchers.h", "mock_switch.h"], - deps = ["@com_google_googletest//:gtest", - "@com_github_p4lang_p4runtime//:p4runtime_cc_proto", - "//proto/frontend:pifeproto", - "@boost//:optional", - "@boost//:functional"], testonly = True, + srcs = [ + "main.cpp", + "matchers.cpp", + "mock_switch.cpp", + "stream_receiver.h", + ], + hdrs = [ + "matchers.h", + "mock_switch.h", + ], + deps = [ + "//proto/frontend:pifeproto", + "@boost.container_hash//:boost.container_hash", + "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_proto", + "@com_google_googletest//:gtest", + ], ) cc_test( name = "pi_proto_tests", - srcs = ["test_p4info_convert.cpp", - "test_task_queue.cpp", - "test_proto_fe_base.h"] - + glob(["test_proto_fe*.cpp"]), - deps = ["@com_google_googletest//:gtest", - "@com_github_p4lang_p4runtime//:p4runtime_cc_proto", - "//proto/frontend:pifeproto", - ":testutils", - "@boost//:optional"], - data = ["//tests:exported_testdata"], + srcs = [ + "test_p4info_convert.cpp", + "test_proto_fe_base.h", + "test_task_queue.cpp", + ] + glob([ + "test_proto_fe*.cpp", + ]), copts = ['-DTESTDATADIR=\\"tests/testdata\\"'], + data = ["//tests:exported_testdata"], + deps = [ + ":testutils", + "//proto/frontend:pifeproto", + "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_proto", + "@com_google_googletest//:gtest", + ], ) cc_test( name = "pi_proto_server_tests", - srcs = glob(["server/*.cpp", "server/*.h"]), - deps = ["@com_google_googletest//:gtest", - "@com_github_p4lang_p4runtime//:p4runtime_cc_grpc", - "@com_github_p4lang_p4runtime//:p4runtime_cc_proto", - "//proto/server:piserver", - ":testutils", - "@boost//:optional", - "@com_github_grpc_grpc//:grpc++"], + srcs = glob([ + "server/*.cpp", + "server/*.h", + ]), + copts = [ + '-DTESTDATADIR=\\"tests/testdata\\"', + "-Iproto/server", + "-Iproto/tests", + "-I$(GENDIR)/proto/p4serverconfig_cc_grpc_pb/proto", + ], data = ["//tests:exported_testdata"], - copts = ['-DTESTDATADIR=\\"tests/testdata\\"', - "-Iproto/server", "-Iproto/tests", - "-I$(GENDIR)/proto/p4serverconfig_cc_grpc_pb/proto"], + deps = [ + ":testutils", + "//proto/server:piserver", + "@com_github_grpc_grpc//:grpc++", + "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_grpc", + "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_proto", + "@com_google_googletest//:gtest", + ], ) diff --git a/proto/third_party/BUILD b/proto/third_party/BUILD index f66562a8..0615cd2e 100644 --- a/proto/third_party/BUILD +++ b/proto/third_party/BUILD @@ -1,21 +1,25 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + package( default_visibility = ["//:__subpackages__"], ) cc_library( name = "fmt", - srcs = ["fmt/container.h", - "fmt/format.cc", - "fmt/ostream.cc", - "fmt/ostream.h", - "fmt/posix.cc", - "fmt/posix.h", - "fmt/printf.cc", - "fmt/printf.h", - "fmt/string.h", - "fmt/time.h", - "fmt/_assert.h", - "fmt/_assert.cc"], + srcs = [ + "fmt/_assert.cc", + "fmt/_assert.h", + "fmt/container.h", + "fmt/format.cc", + "fmt/ostream.cc", + "fmt/ostream.h", + "fmt/posix.cc", + "fmt/posix.h", + "fmt/printf.cc", + "fmt/printf.h", + "fmt/string.h", + "fmt/time.h", + ], hdrs = ["fmt/format.h"], includes = ["."], -) \ No newline at end of file +) diff --git a/tests/BUILD b/tests/BUILD index 1d6be519..e1b97ed7 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -1,5 +1,8 @@ filegroup( name = "exported_testdata", - srcs = glob(["testdata/*.txt", "testdata/*.json"]), + srcs = glob([ + "testdata/*.txt", + "testdata/*.json", + ]), visibility = ["//:__subpackages__"], -) \ No newline at end of file +) diff --git a/third_party/BUILD b/third_party/BUILD index 4a4d7dfe..0e54a18e 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + package( default_visibility = ["//:__subpackages__"], ) @@ -6,5 +8,4 @@ cc_library( name = "piuthash", hdrs = glob(["uthash/src/*.h"]), includes = ["uthash/src"], - deps = [], ) diff --git a/third_party/cJSON/BUILD b/third_party/cJSON/BUILD index 3b6ee214..c54d2fb4 100644 --- a/third_party/cJSON/BUILD +++ b/third_party/cJSON/BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + package( default_visibility = ["//:__subpackages__"], ) @@ -8,8 +10,10 @@ licenses( cc_library( name = "picjson", - srcs = glob(["src/cJSON.c"]), - hdrs = glob(["include/cJSON/cJSON.h"]), - includes = ["include", "include/cJSON"], - deps = [], + srcs = ["src/cJSON.c"], + hdrs = ["include/cJSON/cJSON.h"], + includes = [ + "include", + "include/cJSON", + ], )