From 214449dae8d5b57e98b1e012ea9f60498f359e2c Mon Sep 17 00:00:00 2001 From: c8ef Date: Tue, 26 May 2026 21:41:10 +0800 Subject: [PATCH 01/10] bazel build Signed-off-by: c8ef --- .bazelrc | 13 +++++ .bazelversion | 1 + .github/workflows/bazel.yml | 60 ++++++++++++++++++++ BUILD.bazel | 52 +++++++++++++++++ MODULE.bazel | 29 ++++++++++ PI/BUILD.bazel | 19 +++++++ services/BUILD.bazel | 23 ++++++++ src/BMI/BUILD.bazel | 17 ++++++ src/bm_sim/BUILD.bazel | 38 +++++++++++++ targets/simple_switch/BUILD.bazel | 23 ++++++++ targets/simple_switch_grpc/BUILD.bazel | 31 ++++++++++ targets/simple_switch_grpc/tests/BUILD.bazel | 52 +++++++++++++++++ targets/simple_switch_grpc/tests/base_test.h | 2 +- targets/simple_switch_grpc/tests/utils.h | 2 +- third_party/BUILD.bazel | 12 ++++ 15 files changed, 372 insertions(+), 2 deletions(-) create mode 100644 .bazelrc create mode 100644 .bazelversion create mode 100644 .github/workflows/bazel.yml create mode 100644 BUILD.bazel create mode 100644 MODULE.bazel create mode 100644 PI/BUILD.bazel create mode 100644 services/BUILD.bazel create mode 100644 src/BMI/BUILD.bazel create mode 100644 src/bm_sim/BUILD.bazel create mode 100644 targets/simple_switch/BUILD.bazel create mode 100644 targets/simple_switch_grpc/BUILD.bazel create mode 100644 targets/simple_switch_grpc/tests/BUILD.bazel create mode 100644 third_party/BUILD.bazel diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 000000000..c388cac1b --- /dev/null +++ b/.bazelrc @@ -0,0 +1,13 @@ +# 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 new file mode 100644 index 000000000..f7ee06693 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +9.0.0 diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml new file mode 100644 index 000000000..4d65b2de9 --- /dev/null +++ b/.github/workflows/bazel.yml @@ -0,0 +1,60 @@ +name: "Test Bazel Build" + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + 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- + + - 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 + run: bazel build //targets/simple_switch_grpc:simple_switch_grpc + + - name: Test + run: bazel test //targets/simple_switch_grpc/tests/... diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 000000000..41ecb651e --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,52 @@ +load("@bazel_skylib//rules:expand_template.bzl", "expand_template") +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +exports_files(["VERSION"]) + +expand_template( + name = "config_h", + out = "include/bm/config.h", + substitutions = { + # disabled + "#cmakedefine BM_DEBUG_ON @BM_DEBUG_ON@": "/* #undef BM_DEBUG_ON */", + "#cmakedefine BM_ELOG_ON @BM_ELOG_ON@": "/* #undef BM_ELOG_ON */", + # enabled + "#cmakedefine BM_ENABLE_MODULES @BM_ENABLE_MODULES@": "#define BM_ENABLE_MODULES 1", + "#cmakedefine BM_HAVE_ALGORITHM @BM_HAVE_ALGORITHM@": "#define BM_HAVE_ALGORITHM 1", + "#cmakedefine BM_HAVE_ARRAY @BM_HAVE_ARRAY@": "#define BM_HAVE_ARRAY 1", + "#cmakedefine BM_HAVE_CASSERT @BM_HAVE_CASSERT@": "#define BM_HAVE_CASSERT 1", + "#cmakedefine BM_HAVE_CMATH @BM_HAVE_CMATH@": "#define BM_HAVE_CMATH 1", + "#cmakedefine BM_HAVE_CSTDIO @BM_HAVE_CSTDIO@": "#define BM_HAVE_CSTDIO 1", + "#cmakedefine BM_HAVE_CTIME @BM_HAVE_CTIME@": "#define BM_HAVE_CTIME 1", + "#cmakedefine BM_HAVE_DLFCN_H @BM_HAVE_DLFCN_H@": "#define BM_HAVE_DLFCN_H 1", + "#cmakedefine BM_HAVE_DLOPEN @BM_HAVE_DLOPEN@": "#define BM_HAVE_DLOPEN 1", + "#cmakedefine BM_HAVE_QUEUE @BM_HAVE_QUEUE@": "#define BM_HAVE_QUEUE 1", + "#cmakedefine BM_HAVE_STRING @BM_HAVE_STRING@": "#define BM_HAVE_STRING 1", + "#cmakedefine BM_HAVE_SYS_STAT_H @BM_HAVE_SYS_STAT_H@": "#define BM_HAVE_SYS_STAT_H 1", + "#cmakedefine BM_HAVE_SYS_TYPES_H @BM_HAVE_SYS_TYPES_H@": "#define BM_HAVE_SYS_TYPES_H 1", + # disabled + "#cmakedefine BM_HAVE_THRIFT_STDCXX_H @BM_HAVE_THRIFT_STDCXX_H@": "/* #undef BM_HAVE_THRIFT_STDCXX_H */", + # enabled + "#cmakedefine BM_HAVE_TUPLE @BM_HAVE_TUPLE@": "#define BM_HAVE_TUPLE 1", + "#cmakedefine BM_HAVE_UNISTD_H @BM_HAVE_UNISTD_H@": "#define BM_HAVE_UNISTD_H 1", + "#cmakedefine BM_HAVE_UNORDERED_MAP @BM_HAVE_UNORDERED_MAP@": "#define BM_HAVE_UNORDERED_MAP 1", + "#cmakedefine BM_HAVE_UTILITY @BM_HAVE_UTILITY@": "#define BM_HAVE_UTILITY 1", + "#cmakedefine BM_HAVE_VECTOR @BM_HAVE_VECTOR@": "#define BM_HAVE_VECTOR 1", + "#cmakedefine BM_LOG_DEBUG_ON @BM_LOG_DEBUG_ON@": "#define BM_LOG_DEBUG_ON 1", + "#cmakedefine BM_LOG_TRACE_ON @BM_LOG_TRACE_ON@": "#define BM_LOG_TRACE_ON 1", + # disabled + "#cmakedefine BM_NANOMSG_ON @BM_NANOMSG_ON@": "/* #undef BM_NANOMSG_ON */", + "#cmakedefine BM_THRIFT_ON @BM_THRIFT_ON@": "/* #undef BM_THRIFT_ON */", + "#cmakedefine BM_THRIFT_VERSION @BM_THRIFT_VERSION@": "/* #undef BM_THRIFT_VERSION */", + # enabled + "#cmakedefine BM_WP4_16_STACKS @BM_WP4_16_STACKS@": "#define BM_WP4_16_STACKS 1", + }, + template = "include/bm/config.h.in", +) + +cc_library( + name = "bm_headers", + hdrs = glob(["include/bm/**/*.h"]) + [":config_h"], + includes = ["include"], + visibility = ["//visibility:public"], +) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 000000000..98950eca6 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,29 @@ +module( + name = "behavioral-model", + version = "1.15.2", + bazel_compatibility = [">=7.0.0"], +) + +bazel_dep(name = "bazel_skylib", version = "1.9.0") +bazel_dep(name = "boost.filesystem", version = "1.90.0.bcr.1") +bazel_dep(name = "boost.program_options", version = "1.90.0.bcr.1") +bazel_dep(name = "boringssl", version = "0.20260508.0") +bazel_dep(name = "com_github_p4lang_pi", version = "head") +bazel_dep(name = "gmp", version = "6.3.0.bcr.1") +bazel_dep(name = "googleapis", version = "0.0.0-20260130-c0fcb356", repo_name = "com_google_googleapis") +bazel_dep(name = "grpc", version = "1.76.0", repo_name = "com_github_grpc_grpc") +bazel_dep(name = "jsoncpp", version = "1.9.6.bcr.2") +bazel_dep(name = "libpcap", version = "1.10.5.bcr.3") +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") +bazel_dep(name = "xxhash", version = "0.8.3.bcr.1") + +bazel_dep(name = "googletest", version = "1.17.0.bcr.2", dev_dependency = True) + +git_override( + module_name = "com_github_p4lang_pi", + commit = "0aa6c69140045b8a74575dbb7818664dd1066504", + init_submodules = True, + remote = "https://github.com/p4lang/PI.git", +) diff --git a/PI/BUILD.bazel b/PI/BUILD.bazel new file mode 100644 index 000000000..e0b5a4fc6 --- /dev/null +++ b/PI/BUILD.bazel @@ -0,0 +1,19 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +cc_library( + name = "bmpi", + srcs = glob([ + "src/*.cpp", + "src/*.h", + ]), + hdrs = ["bm/PI/pi.h"], + includes = ["."], + local_defines = ["WITH_SIMPLE_SWITCH"], + visibility = ["//visibility:public"], + deps = [ + "//:bm_headers", + "//targets/simple_switch:simpleswitch", + "@com_github_p4lang_pi//:pi", + ], + alwayslink = True, +) diff --git a/services/BUILD.bazel b/services/BUILD.bazel new file mode 100644 index 000000000..9d89ec3db --- /dev/null +++ b/services/BUILD.bazel @@ -0,0 +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") + +proto_library( + name = "dataplane_interface_proto", + srcs = ["p4/bm/dataplane_interface.proto"], + strip_import_prefix = "", +) + +cc_proto_library( + name = "dataplane_interface_cc_proto", + visibility = ["//visibility:public"], + deps = [":dataplane_interface_proto"], +) + +cc_grpc_library( + name = "bm_grpc_dataplane", + srcs = [":dataplane_interface_proto"], + grpc_only = True, + visibility = ["//visibility:public"], + deps = [":dataplane_interface_cc_proto"], +) diff --git a/src/BMI/BUILD.bazel b/src/BMI/BUILD.bazel new file mode 100644 index 000000000..22fb155db --- /dev/null +++ b/src/BMI/BUILD.bazel @@ -0,0 +1,17 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +cc_library( + name = "bmi", + srcs = [ + "bmi_interface.c", + "bmi_port.c", + ], + hdrs = [ + "BMI/bmi_port.h", + "bmi_interface.h", + ], + includes = ["."], + local_defines = ["WITH_PCAP_FIX"], + visibility = ["//visibility:public"], + deps = ["@libpcap"], +) diff --git a/src/bm_sim/BUILD.bazel b/src/bm_sim/BUILD.bazel new file mode 100644 index 000000000..2e963e0ea --- /dev/null +++ b/src/bm_sim/BUILD.bazel @@ -0,0 +1,38 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +genrule( + name = "version_cpp", + srcs = [ + "version.cpp.in", + "//:VERSION", + ], + outs = ["version.cpp"], + cmd = "sed \"s/@BM_VERSION@/$$(cat $(rootpath //:VERSION))/\" $(location version.cpp.in) > $@", +) + +cc_library( + name = "bmsim", + srcs = glob( + [ + "*.cpp", + "*.c", + "*.h", + "core/*.cpp", + ], + exclude = ["md5.c"], + ) + [":version_cpp"], + copts = ["-Isrc/bm_sim"], + defines = ["HAVE_OPENSSL"], + linkopts = ["-ldl"], + visibility = ["//visibility:public"], + deps = [ + "//:bm_headers", + "//src/BMI:bmi", + "//third_party:spdlog", + "@boringssl//:crypto", + "@gmp", + "@jsoncpp", + "@libpcap", + "@xxhash", + ], +) diff --git a/targets/simple_switch/BUILD.bazel b/targets/simple_switch/BUILD.bazel new file mode 100644 index 000000000..c1040b1cc --- /dev/null +++ b/targets/simple_switch/BUILD.bazel @@ -0,0 +1,23 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +cc_library( + name = "simpleswitch", + srcs = [ + "primitives.cpp", + "simple_switch.cpp", + ], + hdrs = [ + "register_access.h", + "simple_switch.h", + ], + includes = ["."], + visibility = ["//visibility:public"], + deps = [ + "//:bm_headers", + "//src/BMI:bmi", + "//src/bm_sim:bmsim", + "@boost.filesystem", + "@boost.program_options", + "@jsoncpp", + ], +) diff --git a/targets/simple_switch_grpc/BUILD.bazel b/targets/simple_switch_grpc/BUILD.bazel new file mode 100644 index 000000000..8401c643c --- /dev/null +++ b/targets/simple_switch_grpc/BUILD.bazel @@ -0,0 +1,31 @@ +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +cc_library( + name = "simpleswitchgrpc", + srcs = ["switch_runner.cpp"], + hdrs = ["switch_runner.h"], + includes = ["."], + visibility = ["//visibility:public"], + deps = [ + "//:bm_headers", + "//PI:bmpi", + "//services:bm_grpc_dataplane", + "//services:dataplane_interface_cc_proto", + "//targets/simple_switch:simpleswitch", + "@com_github_grpc_grpc//:grpc++", + "@com_github_p4lang_pi//:pi", + "@com_github_p4lang_pi//:pip4info", + "@com_github_p4lang_pi//proto/frontend:pifeproto", + "@com_github_p4lang_pi//proto/server:piserver", + ], +) + +cc_binary( + name = "simple_switch_grpc", + srcs = ["main.cpp"], + deps = [ + ":simpleswitchgrpc", + "//:bm_headers", + ], +) diff --git a/targets/simple_switch_grpc/tests/BUILD.bazel b/targets/simple_switch_grpc/tests/BUILD.bazel new file mode 100644 index 000000000..2fda2bd32 --- /dev/null +++ b/targets/simple_switch_grpc/tests/BUILD.bazel @@ -0,0 +1,52 @@ +load("@rules_cc//cc:cc_test.bzl", "cc_test") + +_COMMON_SRCS = [ + "base_test.cpp", + "base_test.h", + "main.cpp", + "utils.cpp", + "utils.h", +] + +_COMMON_DEPS = [ + "//targets/simple_switch_grpc:simpleswitchgrpc", + "//targets/simple_switch:simpleswitch", + "//services:bm_grpc_dataplane", + "//services:dataplane_interface_cc_proto", + "@googletest//:gtest", + "@com_github_grpc_grpc//:grpc++", + "@com_github_p4lang_pi//:pi", + "@com_github_p4lang_pi//:pip4info", + "@com_github_p4lang_pi//proto/frontend:pifeproto", + "@com_github_p4lang_pi//proto/server:piserver", + "@com_google_protobuf//:protobuf", + "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_grpc", + "@com_github_p4lang_p4runtime//proto/p4/config/v1:p4info_cc_proto", + "@com_google_googleapis//google/rpc:code_cc_proto", +] + +_TESTS = [ + "test_basic", + "test_grpc_dp", + "test_packet_io", + "test_counter", + "test_meter", + "test_ternary", + "test_pre", + "test_digest", + "test_idle_timeout", + "test_action_profile", + "test_optional", +] + +[ + cc_test( + name = test, + srcs = _COMMON_SRCS + [test + ".cpp"], + data = glob(["testdata/**"]), + defines = ["TESTDATADIR=\\\"" + package_name() + "/testdata\\\""], + tags = ["exclusive"], # tests share a gRPC port; must not run in parallel + deps = _COMMON_DEPS, + ) + for test in _TESTS +] diff --git a/targets/simple_switch_grpc/tests/base_test.h b/targets/simple_switch_grpc/tests/base_test.h index 577dbb0af..f9c8ca3db 100644 --- a/targets/simple_switch_grpc/tests/base_test.h +++ b/targets/simple_switch_grpc/tests/base_test.h @@ -13,7 +13,7 @@ #ifndef SIMPLE_SWITCH_GRPC_TESTS_BASE_TEST_H_ #define SIMPLE_SWITCH_GRPC_TESTS_BASE_TEST_H_ -#include +#include #include #include diff --git a/targets/simple_switch_grpc/tests/utils.h b/targets/simple_switch_grpc/tests/utils.h index c62c9a2d8..5cfbba847 100644 --- a/targets/simple_switch_grpc/tests/utils.h +++ b/targets/simple_switch_grpc/tests/utils.h @@ -13,7 +13,7 @@ #ifndef SIMPLE_SWITCH_GRPC_TESTS_UTILS_H_ #define SIMPLE_SWITCH_GRPC_TESTS_UTILS_H_ -#include +#include #include #include diff --git a/third_party/BUILD.bazel b/third_party/BUILD.bazel new file mode 100644 index 000000000..4b1b323db --- /dev/null +++ b/third_party/BUILD.bazel @@ -0,0 +1,12 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +cc_library( + name = "spdlog", + hdrs = glob([ + "spdlog/bm/spdlog/*.h", + "spdlog/bm/spdlog/**/*.h", + "spdlog/bm/spdlog/**/*.cc", + ]), + includes = ["spdlog"], + visibility = ["//visibility:public"], +) From 345de0ca2f6e0bf3e907a303389e1f209f640fd8 Mon Sep 17 00:00:00 2001 From: c8ef Date: Tue, 26 May 2026 21:57:47 +0800 Subject: [PATCH 02/10] refresh license Signed-off-by: c8ef --- .bazelrc | 4 ++++ .bazelversion.license | 3 +++ .github/workflows/bazel.yml | 4 ++++ BUILD.bazel | 4 ++++ MODULE.bazel | 5 ++++- PI/BUILD.bazel | 4 ++++ services/BUILD.bazel | 4 ++++ src/BMI/BUILD.bazel | 4 ++++ src/bm_sim/BUILD.bazel | 5 +++++ targets/simple_switch/BUILD.bazel | 6 ++++-- targets/simple_switch_grpc/BUILD.bazel | 4 ++++ targets/simple_switch_grpc/tests/BUILD.bazel | 4 ++++ third_party/BUILD.bazel | 4 ++++ 13 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 .bazelversion.license diff --git a/.bazelrc b/.bazelrc index c388cac1b..81ee5fa94 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + # Use Bzlmod (`MODULE.bazel`) instead of `WORKSPACE.bazel`. common --enable_bzlmod common --noenable_workspace diff --git a/.bazelversion.license b/.bazelversion.license new file mode 100644 index 000000000..8949742c5 --- /dev/null +++ b/.bazelversion.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2026 Yuao Ma + +SPDX-License-Identifier: Apache-2.0 diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 4d65b2de9..79508432d 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + name: "Test Bazel Build" on: diff --git a/BUILD.bazel b/BUILD.bazel index 41ecb651e..d9b9f7d37 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + load("@bazel_skylib//rules:expand_template.bzl", "expand_template") load("@rules_cc//cc:cc_library.bzl", "cc_library") diff --git a/MODULE.bazel b/MODULE.bazel index 98950eca6..aa5b9a734 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + module( name = "behavioral-model", version = "1.15.2", @@ -5,7 +9,6 @@ module( ) bazel_dep(name = "bazel_skylib", version = "1.9.0") -bazel_dep(name = "boost.filesystem", version = "1.90.0.bcr.1") bazel_dep(name = "boost.program_options", version = "1.90.0.bcr.1") bazel_dep(name = "boringssl", version = "0.20260508.0") bazel_dep(name = "com_github_p4lang_pi", version = "head") diff --git a/PI/BUILD.bazel b/PI/BUILD.bazel index e0b5a4fc6..5deaa4892 100644 --- a/PI/BUILD.bazel +++ b/PI/BUILD.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + load("@rules_cc//cc:cc_library.bzl", "cc_library") cc_library( diff --git a/services/BUILD.bazel b/services/BUILD.bazel index 9d89ec3db..9c4f9d5e2 100644 --- a/services/BUILD.bazel +++ b/services/BUILD.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + 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") diff --git a/src/BMI/BUILD.bazel b/src/BMI/BUILD.bazel index 22fb155db..fa24f9072 100644 --- a/src/BMI/BUILD.bazel +++ b/src/BMI/BUILD.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + load("@rules_cc//cc:cc_library.bzl", "cc_library") cc_library( diff --git a/src/bm_sim/BUILD.bazel b/src/bm_sim/BUILD.bazel index 2e963e0ea..b3f3f4237 100644 --- a/src/bm_sim/BUILD.bazel +++ b/src/bm_sim/BUILD.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + load("@rules_cc//cc:cc_library.bzl", "cc_library") genrule( @@ -29,6 +33,7 @@ cc_library( "//:bm_headers", "//src/BMI:bmi", "//third_party:spdlog", + "@boost.program_options", "@boringssl//:crypto", "@gmp", "@jsoncpp", diff --git a/targets/simple_switch/BUILD.bazel b/targets/simple_switch/BUILD.bazel index c1040b1cc..17a3dd469 100644 --- a/targets/simple_switch/BUILD.bazel +++ b/targets/simple_switch/BUILD.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + load("@rules_cc//cc:cc_library.bzl", "cc_library") cc_library( @@ -16,8 +20,6 @@ cc_library( "//:bm_headers", "//src/BMI:bmi", "//src/bm_sim:bmsim", - "@boost.filesystem", - "@boost.program_options", "@jsoncpp", ], ) diff --git a/targets/simple_switch_grpc/BUILD.bazel b/targets/simple_switch_grpc/BUILD.bazel index 8401c643c..abb928105 100644 --- a/targets/simple_switch_grpc/BUILD.bazel +++ b/targets/simple_switch_grpc/BUILD.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") diff --git a/targets/simple_switch_grpc/tests/BUILD.bazel b/targets/simple_switch_grpc/tests/BUILD.bazel index 2fda2bd32..f192d5657 100644 --- a/targets/simple_switch_grpc/tests/BUILD.bazel +++ b/targets/simple_switch_grpc/tests/BUILD.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + load("@rules_cc//cc:cc_test.bzl", "cc_test") _COMMON_SRCS = [ diff --git a/third_party/BUILD.bazel b/third_party/BUILD.bazel index 4b1b323db..a255850fa 100644 --- a/third_party/BUILD.bazel +++ b/third_party/BUILD.bazel @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Yuao Ma +# +# SPDX-License-Identifier: Apache-2.0 + load("@rules_cc//cc:cc_library.bzl", "cc_library") cc_library( From 06bc3c59efbcdda31b72316b87b5b8be8751e084 Mon Sep 17 00:00:00 2001 From: c8ef Date: Tue, 26 May 2026 22:09:25 +0800 Subject: [PATCH 03/10] more boost Signed-off-by: c8ef --- MODULE.bazel | 4 ++++ src/bm_sim/BUILD.bazel | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/MODULE.bazel b/MODULE.bazel index aa5b9a734..4709b9ca6 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -9,7 +9,11 @@ module( ) bazel_dep(name = "bazel_skylib", version = "1.9.0") +bazel_dep(name = "boost.container", version = "1.90.0.bcr.1") +bazel_dep(name = "boost.container_hash", version = "1.90.0.bcr.1") +bazel_dep(name = "boost.multiprecision", version = "1.90.0.bcr.1") bazel_dep(name = "boost.program_options", version = "1.90.0.bcr.1") +bazel_dep(name = "boost.thread", version = "1.90.0.bcr.1") bazel_dep(name = "boringssl", version = "0.20260508.0") bazel_dep(name = "com_github_p4lang_pi", version = "head") bazel_dep(name = "gmp", version = "6.3.0.bcr.1") diff --git a/src/bm_sim/BUILD.bazel b/src/bm_sim/BUILD.bazel index b3f3f4237..4f6105b47 100644 --- a/src/bm_sim/BUILD.bazel +++ b/src/bm_sim/BUILD.bazel @@ -33,7 +33,11 @@ cc_library( "//:bm_headers", "//src/BMI:bmi", "//third_party:spdlog", + "@boost.container", + "@boost.container_hash", + "@boost.multiprecision", "@boost.program_options", + "@boost.thread", "@boringssl//:crypto", "@gmp", "@jsoncpp", From 809c1e7c45428a832ea9869b8fa2d6ad79e7e6da Mon Sep 17 00:00:00 2001 From: c8ef Date: Tue, 26 May 2026 22:10:47 +0800 Subject: [PATCH 04/10] format bazel Signed-off-by: c8ef --- MODULE.bazel | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 4709b9ca6..708ac2913 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -9,11 +9,11 @@ module( ) bazel_dep(name = "bazel_skylib", version = "1.9.0") -bazel_dep(name = "boost.container", version = "1.90.0.bcr.1") -bazel_dep(name = "boost.container_hash", version = "1.90.0.bcr.1") -bazel_dep(name = "boost.multiprecision", version = "1.90.0.bcr.1") +bazel_dep(name = "boost.container", version = "1.90.0.bcr.1") +bazel_dep(name = "boost.container_hash", version = "1.90.0.bcr.1") +bazel_dep(name = "boost.multiprecision", version = "1.90.0.bcr.1") bazel_dep(name = "boost.program_options", version = "1.90.0.bcr.1") -bazel_dep(name = "boost.thread", version = "1.90.0.bcr.1") +bazel_dep(name = "boost.thread", version = "1.90.0.bcr.1") bazel_dep(name = "boringssl", version = "0.20260508.0") bazel_dep(name = "com_github_p4lang_pi", version = "head") bazel_dep(name = "gmp", version = "6.3.0.bcr.1") From f4bc3c7caa86fd2e9b9f1d524bde60589f0f118b Mon Sep 17 00:00:00 2001 From: c8ef Date: Wed, 3 Jun 2026 01:26:55 +0800 Subject: [PATCH 05/10] try removing includes Signed-off-by: c8ef --- BUILD.bazel | 2 +- PI/BUILD.bazel | 2 +- src/BMI/BUILD.bazel | 2 +- targets/simple_switch/BUILD.bazel | 2 +- targets/simple_switch_grpc/BUILD.bazel | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index d9b9f7d37..737f227af 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -51,6 +51,6 @@ expand_template( cc_library( name = "bm_headers", hdrs = glob(["include/bm/**/*.h"]) + [":config_h"], - includes = ["include"], + strip_include_prefix = "include", visibility = ["//visibility:public"], ) diff --git a/PI/BUILD.bazel b/PI/BUILD.bazel index 5deaa4892..39137fb5a 100644 --- a/PI/BUILD.bazel +++ b/PI/BUILD.bazel @@ -11,8 +11,8 @@ cc_library( "src/*.h", ]), hdrs = ["bm/PI/pi.h"], - includes = ["."], local_defines = ["WITH_SIMPLE_SWITCH"], + strip_include_prefix = "", visibility = ["//visibility:public"], deps = [ "//:bm_headers", diff --git a/src/BMI/BUILD.bazel b/src/BMI/BUILD.bazel index fa24f9072..331ad018e 100644 --- a/src/BMI/BUILD.bazel +++ b/src/BMI/BUILD.bazel @@ -14,8 +14,8 @@ cc_library( "BMI/bmi_port.h", "bmi_interface.h", ], - includes = ["."], local_defines = ["WITH_PCAP_FIX"], + strip_include_prefix = "", visibility = ["//visibility:public"], deps = ["@libpcap"], ) diff --git a/targets/simple_switch/BUILD.bazel b/targets/simple_switch/BUILD.bazel index 17a3dd469..c3851d9d5 100644 --- a/targets/simple_switch/BUILD.bazel +++ b/targets/simple_switch/BUILD.bazel @@ -14,7 +14,7 @@ cc_library( "register_access.h", "simple_switch.h", ], - includes = ["."], + strip_include_prefix = "", visibility = ["//visibility:public"], deps = [ "//:bm_headers", diff --git a/targets/simple_switch_grpc/BUILD.bazel b/targets/simple_switch_grpc/BUILD.bazel index abb928105..1d2caa5d5 100644 --- a/targets/simple_switch_grpc/BUILD.bazel +++ b/targets/simple_switch_grpc/BUILD.bazel @@ -9,7 +9,7 @@ cc_library( name = "simpleswitchgrpc", srcs = ["switch_runner.cpp"], hdrs = ["switch_runner.h"], - includes = ["."], + strip_include_prefix = "", visibility = ["//visibility:public"], deps = [ "//:bm_headers", From 5b678454b04e6b6cc0ce94d33a6956509484fd1a Mon Sep 17 00:00:00 2001 From: c8ef Date: Wed, 3 Jun 2026 01:32:42 +0800 Subject: [PATCH 06/10] Revert "try removing includes" This reverts commit f4bc3c7caa86fd2e9b9f1d524bde60589f0f118b. Signed-off-by: c8ef --- BUILD.bazel | 2 +- PI/BUILD.bazel | 2 +- src/BMI/BUILD.bazel | 2 +- targets/simple_switch/BUILD.bazel | 2 +- targets/simple_switch_grpc/BUILD.bazel | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 737f227af..d9b9f7d37 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -51,6 +51,6 @@ expand_template( cc_library( name = "bm_headers", hdrs = glob(["include/bm/**/*.h"]) + [":config_h"], - strip_include_prefix = "include", + includes = ["include"], visibility = ["//visibility:public"], ) diff --git a/PI/BUILD.bazel b/PI/BUILD.bazel index 39137fb5a..5deaa4892 100644 --- a/PI/BUILD.bazel +++ b/PI/BUILD.bazel @@ -11,8 +11,8 @@ cc_library( "src/*.h", ]), hdrs = ["bm/PI/pi.h"], + includes = ["."], local_defines = ["WITH_SIMPLE_SWITCH"], - strip_include_prefix = "", visibility = ["//visibility:public"], deps = [ "//:bm_headers", diff --git a/src/BMI/BUILD.bazel b/src/BMI/BUILD.bazel index 331ad018e..fa24f9072 100644 --- a/src/BMI/BUILD.bazel +++ b/src/BMI/BUILD.bazel @@ -14,8 +14,8 @@ cc_library( "BMI/bmi_port.h", "bmi_interface.h", ], + includes = ["."], local_defines = ["WITH_PCAP_FIX"], - strip_include_prefix = "", visibility = ["//visibility:public"], deps = ["@libpcap"], ) diff --git a/targets/simple_switch/BUILD.bazel b/targets/simple_switch/BUILD.bazel index c3851d9d5..17a3dd469 100644 --- a/targets/simple_switch/BUILD.bazel +++ b/targets/simple_switch/BUILD.bazel @@ -14,7 +14,7 @@ cc_library( "register_access.h", "simple_switch.h", ], - strip_include_prefix = "", + includes = ["."], visibility = ["//visibility:public"], deps = [ "//:bm_headers", diff --git a/targets/simple_switch_grpc/BUILD.bazel b/targets/simple_switch_grpc/BUILD.bazel index 1d2caa5d5..abb928105 100644 --- a/targets/simple_switch_grpc/BUILD.bazel +++ b/targets/simple_switch_grpc/BUILD.bazel @@ -9,7 +9,7 @@ cc_library( name = "simpleswitchgrpc", srcs = ["switch_runner.cpp"], hdrs = ["switch_runner.h"], - strip_include_prefix = "", + includes = ["."], visibility = ["//visibility:public"], deps = [ "//:bm_headers", From 5ec129667752ca73685b9168a53b9e15d70c6035 Mon Sep 17 00:00:00 2001 From: c8ef Date: Wed, 3 Jun 2026 20:44:47 +0800 Subject: [PATCH 07/10] add license Signed-off-by: c8ef --- BUILD.bazel | 12 +++++++++++- MODULE.bazel | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index d9b9f7d37..8fedfb5aa 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -3,9 +3,19 @@ # SPDX-License-Identifier: Apache-2.0 load("@bazel_skylib//rules:expand_template.bzl", "expand_template") +load("@package_metadata//licenses:defs.bzl", "license") load("@rules_cc//cc:cc_library.bzl", "cc_library") -exports_files(["VERSION"]) +exports_files([ + "LICENSE", + "VERSION", +]) + +license( + name = "license", + kind = "@package_metadata//licenses/spdx:Apache-2.0", + text = "LICENSE", +) expand_template( name = "config_h", diff --git a/MODULE.bazel b/MODULE.bazel index 708ac2913..e48b56069 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,7 +4,7 @@ module( name = "behavioral-model", - version = "1.15.2", + version = "1.15.3", bazel_compatibility = [">=7.0.0"], ) @@ -22,6 +22,7 @@ bazel_dep(name = "grpc", version = "1.76.0", repo_name = "com_github_grpc_grpc") bazel_dep(name = "jsoncpp", version = "1.9.6.bcr.2") bazel_dep(name = "libpcap", version = "1.10.5.bcr.3") bazel_dep(name = "p4runtime", version = "1.5.0.bcr.1", repo_name = "com_github_p4lang_p4runtime") +bazel_dep(name = "package_metadata", version = "0.0.10") bazel_dep(name = "protobuf", version = "33.5", repo_name = "com_google_protobuf") bazel_dep(name = "rules_cc", version = "0.2.17") bazel_dep(name = "xxhash", version = "0.8.3.bcr.1") From 68601de02fd7623dbd39d0e3450c0aca7f1b78df Mon Sep 17 00:00:00 2001 From: c8ef Date: Thu, 4 Jun 2026 20:43:37 +0800 Subject: [PATCH 08/10] address review comments Signed-off-by: c8ef --- BUILD.bazel | 14 +++++++++----- MODULE.bazel | 2 +- PI/BUILD.bazel | 6 +++++- services/BUILD.bazel | 7 +++++-- src/BMI/BUILD.bazel | 6 +++++- src/bm_sim/BUILD.bazel | 6 +++++- targets/simple_switch/BUILD.bazel | 6 +++++- targets/simple_switch_grpc/BUILD.bazel | 6 +++++- third_party/BUILD.bazel | 6 +++++- 9 files changed, 45 insertions(+), 14 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 8fedfb5aa..2ff1ee800 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -6,10 +6,10 @@ load("@bazel_skylib//rules:expand_template.bzl", "expand_template") load("@package_metadata//licenses:defs.bzl", "license") load("@rules_cc//cc:cc_library.bzl", "cc_library") -exports_files([ - "LICENSE", - "VERSION", -]) +package( + default_applicable_licenses = ["//:license"], + default_visibility = ["//visibility:public"], +) license( name = "license", @@ -17,6 +17,11 @@ license( text = "LICENSE", ) +exports_files([ + "LICENSE", + "VERSION", +]) + expand_template( name = "config_h", out = "include/bm/config.h", @@ -62,5 +67,4 @@ cc_library( name = "bm_headers", hdrs = glob(["include/bm/**/*.h"]) + [":config_h"], includes = ["include"], - visibility = ["//visibility:public"], ) diff --git a/MODULE.bazel b/MODULE.bazel index e48b56069..2c86ba411 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 module( - name = "behavioral-model", + name = "behavioral_model", version = "1.15.3", bazel_compatibility = [">=7.0.0"], ) diff --git a/PI/BUILD.bazel b/PI/BUILD.bazel index 5deaa4892..ed103de68 100644 --- a/PI/BUILD.bazel +++ b/PI/BUILD.bazel @@ -4,6 +4,11 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + cc_library( name = "bmpi", srcs = glob([ @@ -13,7 +18,6 @@ cc_library( hdrs = ["bm/PI/pi.h"], includes = ["."], local_defines = ["WITH_SIMPLE_SWITCH"], - visibility = ["//visibility:public"], deps = [ "//:bm_headers", "//targets/simple_switch:simpleswitch", diff --git a/services/BUILD.bazel b/services/BUILD.bazel index 9c4f9d5e2..9b58ac5c6 100644 --- a/services/BUILD.bazel +++ b/services/BUILD.bazel @@ -6,6 +6,11 @@ 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") +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + proto_library( name = "dataplane_interface_proto", srcs = ["p4/bm/dataplane_interface.proto"], @@ -14,7 +19,6 @@ proto_library( cc_proto_library( name = "dataplane_interface_cc_proto", - visibility = ["//visibility:public"], deps = [":dataplane_interface_proto"], ) @@ -22,6 +26,5 @@ cc_grpc_library( name = "bm_grpc_dataplane", srcs = [":dataplane_interface_proto"], grpc_only = True, - visibility = ["//visibility:public"], deps = [":dataplane_interface_cc_proto"], ) diff --git a/src/BMI/BUILD.bazel b/src/BMI/BUILD.bazel index fa24f9072..9c0a6c7a0 100644 --- a/src/BMI/BUILD.bazel +++ b/src/BMI/BUILD.bazel @@ -4,6 +4,11 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + cc_library( name = "bmi", srcs = [ @@ -16,6 +21,5 @@ cc_library( ], includes = ["."], local_defines = ["WITH_PCAP_FIX"], - visibility = ["//visibility:public"], deps = ["@libpcap"], ) diff --git a/src/bm_sim/BUILD.bazel b/src/bm_sim/BUILD.bazel index 4f6105b47..a412ef63b 100644 --- a/src/bm_sim/BUILD.bazel +++ b/src/bm_sim/BUILD.bazel @@ -4,6 +4,11 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + genrule( name = "version_cpp", srcs = [ @@ -28,7 +33,6 @@ cc_library( copts = ["-Isrc/bm_sim"], defines = ["HAVE_OPENSSL"], linkopts = ["-ldl"], - visibility = ["//visibility:public"], deps = [ "//:bm_headers", "//src/BMI:bmi", diff --git a/targets/simple_switch/BUILD.bazel b/targets/simple_switch/BUILD.bazel index 17a3dd469..aecfa436e 100644 --- a/targets/simple_switch/BUILD.bazel +++ b/targets/simple_switch/BUILD.bazel @@ -4,6 +4,11 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + cc_library( name = "simpleswitch", srcs = [ @@ -15,7 +20,6 @@ cc_library( "simple_switch.h", ], includes = ["."], - visibility = ["//visibility:public"], deps = [ "//:bm_headers", "//src/BMI:bmi", diff --git a/targets/simple_switch_grpc/BUILD.bazel b/targets/simple_switch_grpc/BUILD.bazel index abb928105..0b8b03a85 100644 --- a/targets/simple_switch_grpc/BUILD.bazel +++ b/targets/simple_switch_grpc/BUILD.bazel @@ -5,12 +5,16 @@ load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + cc_library( name = "simpleswitchgrpc", srcs = ["switch_runner.cpp"], hdrs = ["switch_runner.h"], includes = ["."], - visibility = ["//visibility:public"], deps = [ "//:bm_headers", "//PI:bmpi", diff --git a/third_party/BUILD.bazel b/third_party/BUILD.bazel index a255850fa..cce73b9bd 100644 --- a/third_party/BUILD.bazel +++ b/third_party/BUILD.bazel @@ -4,6 +4,11 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + cc_library( name = "spdlog", hdrs = glob([ @@ -12,5 +17,4 @@ cc_library( "spdlog/bm/spdlog/**/*.cc", ]), includes = ["spdlog"], - visibility = ["//visibility:public"], ) From cd51291e479ac629ba4c7ec04970f38fdbf68283 Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 6 Jun 2026 16:37:02 +0800 Subject: [PATCH 09/10] reorg test Signed-off-by: c8ef --- targets/simple_switch_grpc/tests/BUILD.bazel | 71 +++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/targets/simple_switch_grpc/tests/BUILD.bazel b/targets/simple_switch_grpc/tests/BUILD.bazel index f192d5657..573ab26d0 100644 --- a/targets/simple_switch_grpc/tests/BUILD.bazel +++ b/targets/simple_switch_grpc/tests/BUILD.bazel @@ -2,55 +2,60 @@ # # SPDX-License-Identifier: Apache-2.0 +load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_cc//cc:cc_test.bzl", "cc_test") -_COMMON_SRCS = [ - "base_test.cpp", - "base_test.h", - "main.cpp", - "utils.cpp", - "utils.h", -] - -_COMMON_DEPS = [ - "//targets/simple_switch_grpc:simpleswitchgrpc", - "//targets/simple_switch:simpleswitch", - "//services:bm_grpc_dataplane", - "//services:dataplane_interface_cc_proto", - "@googletest//:gtest", - "@com_github_grpc_grpc//:grpc++", - "@com_github_p4lang_pi//:pi", - "@com_github_p4lang_pi//:pip4info", - "@com_github_p4lang_pi//proto/frontend:pifeproto", - "@com_github_p4lang_pi//proto/server:piserver", - "@com_google_protobuf//:protobuf", - "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_grpc", - "@com_github_p4lang_p4runtime//proto/p4/config/v1:p4info_cc_proto", - "@com_google_googleapis//google/rpc:code_cc_proto", -] +cc_library( + name = "test_common", + srcs = [ + "base_test.cpp", + "main.cpp", + "utils.cpp", + ], + hdrs = [ + "base_test.h", + "utils.h", + ], + defines = ["TESTDATADIR=\\\"" + package_name() + "/testdata\\\""], + deps = [ + "//services:bm_grpc_dataplane", + "//services:dataplane_interface_cc_proto", + "//targets/simple_switch:simpleswitch", + "//targets/simple_switch_grpc:simpleswitchgrpc", + "@com_github_grpc_grpc//:grpc++", + "@com_github_p4lang_p4runtime//proto/p4/config/v1:p4info_cc_proto", + "@com_github_p4lang_p4runtime//proto/p4/v1:p4runtime_cc_grpc", + "@com_github_p4lang_pi//:pi", + "@com_github_p4lang_pi//:pip4info", + "@com_github_p4lang_pi//proto/frontend:pifeproto", + "@com_github_p4lang_pi//proto/server:piserver", + "@com_google_googleapis//google/rpc:code_cc_proto", + "@com_google_protobuf//:protobuf", + "@googletest//:gtest", + ], +) _TESTS = [ + "test_action_profile", "test_basic", - "test_grpc_dp", - "test_packet_io", "test_counter", - "test_meter", - "test_ternary", - "test_pre", "test_digest", + "test_grpc_dp", "test_idle_timeout", - "test_action_profile", + "test_meter", "test_optional", + "test_packet_io", + "test_pre", + "test_ternary", ] [ cc_test( name = test, - srcs = _COMMON_SRCS + [test + ".cpp"], + srcs = [test + ".cpp"], data = glob(["testdata/**"]), - defines = ["TESTDATADIR=\\\"" + package_name() + "/testdata\\\""], tags = ["exclusive"], # tests share a gRPC port; must not run in parallel - deps = _COMMON_DEPS, + deps = [":test_common"], ) for test in _TESTS ] From f9c4d01ffc21867ee3c5cfa4b3ebbea5485584b1 Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 6 Jun 2026 19:19:22 +0800 Subject: [PATCH 10/10] missing package Signed-off-by: c8ef --- targets/simple_switch_grpc/tests/BUILD.bazel | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/targets/simple_switch_grpc/tests/BUILD.bazel b/targets/simple_switch_grpc/tests/BUILD.bazel index 573ab26d0..d5ebdf7a2 100644 --- a/targets/simple_switch_grpc/tests/BUILD.bazel +++ b/targets/simple_switch_grpc/tests/BUILD.bazel @@ -5,6 +5,11 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_cc//cc:cc_test.bzl", "cc_test") +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + cc_library( name = "test_common", srcs = [