-
Notifications
You must be signed in to change notification settings - Fork 392
Add bazel build system support for simple_switch_grpc #1401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
214449d
bazel build
c8ef 345de0c
refresh license
c8ef 06bc3c5
more boost
c8ef 809c1e7
format bazel
c8ef bc6ea00
Merge branch 'main' into bazel
c8ef f4bc3c7
try removing includes
c8ef 5b67845
Revert "try removing includes"
c8ef 48f33c1
Merge branch 'main' into bazel
c8ef 5ec1296
add license
c8ef 68601de
address review comments
c8ef cd51291
reorg test
c8ef f9c4d01
missing package
c8ef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # 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 | ||
|
|
||
| # 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 9.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| SPDX-FileCopyrightText: 2026 Yuao Ma | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # SPDX-FileCopyrightText: 2026 Yuao Ma | ||
|
c8ef marked this conversation as resolved.
|
||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| 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/... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # SPDX-FileCopyrightText: 2026 Yuao Ma | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
c8ef marked this conversation as resolved.
|
||
| 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") | ||
|
|
||
| package( | ||
| default_applicable_licenses = ["//:license"], | ||
| default_visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| license( | ||
| name = "license", | ||
| kind = "@package_metadata//licenses/spdx:Apache-2.0", | ||
| text = "LICENSE", | ||
| ) | ||
|
|
||
| exports_files([ | ||
| "LICENSE", | ||
| "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"], | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # SPDX-FileCopyrightText: 2026 Yuao Ma | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
c8ef marked this conversation as resolved.
|
||
| module( | ||
| name = "behavioral_model", | ||
| version = "1.15.3", | ||
| bazel_compatibility = [">=7.0.0"], | ||
| ) | ||
|
|
||
| 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") | ||
| 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 = "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") | ||
|
|
||
| bazel_dep(name = "googletest", version = "1.17.0.bcr.2", dev_dependency = True) | ||
|
c8ef marked this conversation as resolved.
|
||
|
|
||
| git_override( | ||
| module_name = "com_github_p4lang_pi", | ||
| commit = "0aa6c69140045b8a74575dbb7818664dd1066504", | ||
| init_submodules = True, | ||
| remote = "https://github.com/p4lang/PI.git", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # SPDX-FileCopyrightText: 2026 Yuao Ma | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| load("@rules_cc//cc:cc_library.bzl", "cc_library") | ||
|
|
||
| package( | ||
| default_visibility = ["//visibility:public"], | ||
| licenses = ["notice"], | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "bmpi", | ||
| srcs = glob([ | ||
| "src/*.cpp", | ||
| "src/*.h", | ||
| ]), | ||
| hdrs = ["bm/PI/pi.h"], | ||
| includes = ["."], | ||
| local_defines = ["WITH_SIMPLE_SWITCH"], | ||
| deps = [ | ||
| "//:bm_headers", | ||
| "//targets/simple_switch:simpleswitch", | ||
| "@com_github_p4lang_pi//:pi", | ||
| ], | ||
| alwayslink = True, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # 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") | ||
|
|
||
| package( | ||
| default_visibility = ["//visibility:public"], | ||
| licenses = ["notice"], | ||
| ) | ||
|
|
||
| proto_library( | ||
| name = "dataplane_interface_proto", | ||
| srcs = ["p4/bm/dataplane_interface.proto"], | ||
| strip_import_prefix = "", | ||
| ) | ||
|
|
||
| cc_proto_library( | ||
| name = "dataplane_interface_cc_proto", | ||
| deps = [":dataplane_interface_proto"], | ||
| ) | ||
|
|
||
| cc_grpc_library( | ||
| name = "bm_grpc_dataplane", | ||
| srcs = [":dataplane_interface_proto"], | ||
| grpc_only = True, | ||
| deps = [":dataplane_interface_cc_proto"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # SPDX-FileCopyrightText: 2026 Yuao Ma | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| load("@rules_cc//cc:cc_library.bzl", "cc_library") | ||
|
|
||
| package( | ||
| default_visibility = ["//visibility:public"], | ||
| licenses = ["notice"], | ||
| ) | ||
|
|
||
| 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"], | ||
| deps = ["@libpcap"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # SPDX-FileCopyrightText: 2026 Yuao Ma | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| load("@rules_cc//cc:cc_library.bzl", "cc_library") | ||
|
|
||
| package( | ||
| default_visibility = ["//visibility:public"], | ||
| licenses = ["notice"], | ||
| ) | ||
|
|
||
| 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"], | ||
| deps = [ | ||
| "//:bm_headers", | ||
| "//src/BMI:bmi", | ||
| "//third_party:spdlog", | ||
| "@boost.container", | ||
| "@boost.container_hash", | ||
| "@boost.multiprecision", | ||
| "@boost.program_options", | ||
| "@boost.thread", | ||
| "@boringssl//:crypto", | ||
| "@gmp", | ||
| "@jsoncpp", | ||
| "@libpcap", | ||
| "@xxhash", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # SPDX-FileCopyrightText: 2026 Yuao Ma | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| load("@rules_cc//cc:cc_library.bzl", "cc_library") | ||
|
|
||
| package( | ||
| default_visibility = ["//visibility:public"], | ||
| licenses = ["notice"], | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "simpleswitch", | ||
| srcs = [ | ||
| "primitives.cpp", | ||
| "simple_switch.cpp", | ||
| ], | ||
| hdrs = [ | ||
| "register_access.h", | ||
| "simple_switch.h", | ||
| ], | ||
| includes = ["."], | ||
| deps = [ | ||
| "//:bm_headers", | ||
| "//src/BMI:bmi", | ||
| "//src/bm_sim:bmsim", | ||
| "@jsoncpp", | ||
| ], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.