-
Notifications
You must be signed in to change notification settings - Fork 388
Add Bazel Build Support for simple_switch_grpc #1349
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
Open
Vineet1101
wants to merge
19
commits into
p4lang:main
Choose a base branch
from
Vineet1101:bazel-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e41b157
fixes issue 1288 Enable printing of full contents of packets sent out…
Vineet1101 231b685
basic bazel setup
Vineet1101 4a39c41
bazel: add top-level .bazelrc and root BUILD.bazel
Vineet1101 af32142
bazel: add third_party BUILD file
Vineet1101 024bd61
bazel: add src/BMI BUILD file
Vineet1101 75a97ae
bazel: add bm_sim and include BUILD files
Vineet1101 bb59ae3
bazel: add PI and simple_switch headers BUILD files
Vineet1101 dc59082
bazel: add services proto codegen BUILD file
Vineet1101 3df245f
bazel: full rebuild of target simple_switch BUILD file
Vineet1101 8a231e9
Phase 8: Add BUILD.bazel for targets/simple_switch_grpc
Vineet1101 d474428
Phase 9: Add BUILD.bazel for targets/simple_switch_grpc/tests
Vineet1101 0ef40f1
Fix PI static build linking errors by falling back to shared libs
Vineet1101 176d0d2
fixed cpplint style issues
Vineet1101 52018ae
Phase 10: Add GitHub Actions workflow for Bazel build and tests
Vineet1101 8485844
fixed GPG key error
Vineet1101 91714c7
fixed syntax error in the bazel.yml file
Vineet1101 479cee2
fixed failing config.h file error
Vineet1101 157522c
fixed linking errors
Vineet1101 efb7361
removed uncessary files
Vineet1101 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
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,16 @@ | ||
| # C++17 standard (required by BMv2) | ||
| build --cxxopt=-std=c++17 | ||
| build --host_cxxopt=-std=c++17 | ||
|
|
||
| # Position-independent code (required for shared libs) | ||
| build --copt=-fPIC | ||
|
|
||
| # Compiler warnings (match CMake config) | ||
| build --copt=-Wall | ||
| build --copt=-Wextra | ||
|
|
||
| # Feature flags (match CMake defaults) | ||
| build --copt=-DLOG_DEBUG_ON | ||
| build --copt=-DLOG_TRACE_ON | ||
| build --copt=-DWP4_16_STACKS | ||
| build --per_file_copt=external/.*@-Wno-error |
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 @@ | ||
| 8.5.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,42 @@ | ||
| name: Bazel | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| build-and-test: | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| submodules: recursive | ||
|
|
||
| - name: Fix expired p4lang GPG key | ||
| run: | | ||
| sudo sed -i "s|deb http://download.opensuse.org/repositories/home:/p4lang/xUbuntu_22.04/|deb [trusted=yes] http://download.opensuse.org/repositories/home:/p4lang/xUbuntu_22.04/|g" install_deps_ubuntu_22.04.sh | ||
| sudo sed -i '/curl -fsSL https:\/\/download.opensuse.org\/repositories\/home:\/p4lang/d' install_deps_ubuntu_22.04.sh | ||
| - name: Install dependencies | ||
| run: sudo ./install_deps_ubuntu_22.04.sh | ||
|
|
||
| - name: Cache Bazel | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: | | ||
| ~/.cache/bazel | ||
| key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'MODULE.bazel') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-bazel- | ||
|
|
||
| - name: Build simple_switch_grpc | ||
| run: | | ||
| bazel build //targets/simple_switch_grpc:simple_switch_grpc | ||
|
|
||
| - name: Run simple_switch_grpc tests | ||
| 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 |
|---|---|---|
|
|
@@ -104,3 +104,7 @@ VERSION-build | |
|
|
||
| core | ||
| vgcore* | ||
|
|
||
| # Bazel | ||
| bazel-* | ||
| *.lock | ||
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 @@ | ||
| exports_files(["VERSION"]) |
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,15 @@ | ||
| module( | ||
| name = "behavioral-model", | ||
| version = "1.0.0", | ||
| ) | ||
| # C++ rules for Bazel | ||
| bazel_dep(name = "rules_cc", version = "0.1.1") | ||
|
|
||
| # Google Test for running the unit tests | ||
| bazel_dep(name = "googletest", version = "1.17.0") | ||
|
|
||
| bazel_dep(name = "rules_proto", version = "7.1.0") | ||
|
|
||
| # gRPC and Protobuf for the simple_switch_grpc server | ||
| bazel_dep(name = "grpc", version = "1.78.0") | ||
| bazel_dep(name = "protobuf", version = "31.1") |
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,21 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
|
||
| cc_library( | ||
| name = "bmpi", | ||
| srcs = glob([ | ||
| "src/*.cpp", | ||
| ]), | ||
| hdrs = glob([ | ||
| "src/*.h", | ||
| "bm/PI/*.h", | ||
| ]), | ||
| includes = [".", "../targets/simple_switch"], | ||
| defines = ["WITH_SIMPLE_SWITCH"], | ||
| deps = [ | ||
| "//include:bm_headers", | ||
| "//src/bm_sim:bmsim", | ||
| "//targets/simple_switch:simpleswitch_headers", | ||
| ], | ||
| alwayslink = True, | ||
| visibility = ["//visibility:public"], | ||
| ) |
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,31 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_import") | ||
|
|
||
| cc_import( | ||
| name = "pi_lib", | ||
| static_library = "/usr/local/lib/libpi.a", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| cc_import( | ||
| name = "pip4info_lib", | ||
| static_library = "/usr/local/lib/libpip4info.a", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| cc_import( | ||
| name = "pifrontend_lib", | ||
| static_library = "/usr/local/lib/libpifrontend.a", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| cc_import( | ||
| name = "pifeproto_lib", | ||
| static_library = "/usr/local/lib/libpifeproto.a", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| cc_import( | ||
| name = "pigrpcserver_lib", | ||
| static_library = "/usr/local/lib/libpigrpcserver.a", | ||
| visibility = ["//visibility:public"], | ||
| ) |
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,15 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
|
||
| genrule( | ||
| name = "bm_config_h", | ||
| srcs = ["bm/config.h.in"], | ||
| outs = ["bm/config.h"], | ||
| cmd = "sed -e 's/#cmakedefine/#undef/g' $< > $@", | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "bm_headers", | ||
| hdrs = glob(["bm/**/*.h"]) + [":bm_config_h"], | ||
| includes = ["."], | ||
| visibility = ["//visibility:public"], | ||
| ) |
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
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,8 @@ | ||
| def get_grpc_linkopts(): | ||
| return [ | ||
| "-lgrpc++", "-lgrpc", "-lprotobuf", "-lgpr", | ||
| "-labsl_cord", "-labsl_strings", "-labsl_base", | ||
| "-labsl_synchronization", "-labsl_status", | ||
| "-labsl_statusor", "-labsl_time", | ||
| "-lre2", "-lcares", "-lupb" | ||
| ] |
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 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
| load("//:pkgconfig_grpc.bzl", "get_grpc_linkopts") | ||
|
|
||
| genrule( | ||
| name = "dataplane_interface_codegen", | ||
| srcs = ["p4/bm/dataplane_interface.proto"], | ||
| outs = [ | ||
| "p4/bm/dataplane_interface.pb.h", | ||
| "p4/bm/dataplane_interface.pb.cc", | ||
| "p4/bm/dataplane_interface.grpc.pb.h", | ||
| "p4/bm/dataplane_interface.grpc.pb.cc", | ||
| ], | ||
| cmd = "protoc -Iservices --cpp_out=$(RULEDIR) --grpc_out=$(RULEDIR) --plugin=protoc-gen-grpc=/usr/bin/grpc_cpp_plugin $(location p4/bm/dataplane_interface.proto)", | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "bm_grpc_dataplane", | ||
| srcs = [ | ||
| "p4/bm/dataplane_interface.pb.cc", | ||
| "p4/bm/dataplane_interface.grpc.pb.cc", | ||
| ], | ||
| hdrs = [ | ||
| "p4/bm/dataplane_interface.pb.h", | ||
| "p4/bm/dataplane_interface.grpc.pb.h", | ||
| ], | ||
| includes = ["."], | ||
| linkopts = get_grpc_linkopts(), | ||
| visibility = ["//visibility:public"], | ||
| ) |
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,13 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
|
||
| cc_library( | ||
| name = "bmi", | ||
| srcs = [ | ||
| "bmi_interface.c", | ||
| "bmi_port.c", | ||
| ], | ||
| hdrs = glob(["*.h", "BMI/*.h"]), | ||
| includes = ["."], | ||
| visibility = ["//visibility:public"], | ||
| linkopts = ["-lpcap"], | ||
| ) |
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,24 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
|
||
| # Generate version.cpp from template | ||
| genrule( | ||
| name = "version_cpp", | ||
| srcs = ["version.cpp.in", "//:VERSION"], | ||
| outs = ["version.cpp"], | ||
| cmd = "sed 's/@BM_VERSION@/1.13.0/g' $(location version.cpp.in) > $@", | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "bmsim", | ||
| srcs = glob(["*.cpp", "*.c", "core/*.cpp"]) + [":version_cpp"], | ||
| hdrs = glob(["*.h"]), | ||
| includes = ["."], | ||
| deps = [ | ||
| "//include:bm_headers", | ||
| "//third_party:jsoncpp", | ||
| "//third_party:spdlog", | ||
| "//src/BMI:bmi", | ||
| ], | ||
| linkopts = ["-lgmp", "-lpcap", "-lnanomsg", "-lpthread", "-ldl", "-lboost_program_options", "-lboost_system", "-lboost_filesystem", "-lboost_thread"], | ||
| visibility = ["//visibility:public"], | ||
| ) |
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,22 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
|
||
| cc_library( | ||
| name = "simpleswitch", | ||
| srcs = glob(["*.cpp"], exclude=["main.cpp"]), | ||
| hdrs = glob(["*.h", "bm/**/*.h"]), | ||
| includes = ["."], | ||
| deps = [ | ||
| "//include:bm_headers", | ||
| "//src/bm_sim:bmsim", | ||
| "//src/BMI:bmi", | ||
| ], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| # Also expose headers as a separate target for PI, or just let PI depend on simpleswitch. | ||
| # PI depends on simpleswitch_headers, so let's keep it or alias it. | ||
| alias( | ||
| name = "simpleswitch_headers", | ||
| actual = ":simpleswitch", | ||
| visibility = ["//visibility:public"], | ||
| ) |
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,43 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") | ||
| load("//:pkgconfig_grpc.bzl", "get_grpc_linkopts") | ||
|
|
||
| _PI_LINKOPTS = [ | ||
| "-L/usr/local/lib", | ||
| "-Wl,-rpath=/usr/local/lib", | ||
| "-lpigrpcserver", | ||
| "-lpifeproto", | ||
| "-lpiprotogrpc", | ||
| "-lpiprotobuf", | ||
| "-lpifecpp", | ||
| "-lpiconvertproto", | ||
| "-lpi", | ||
| "-lpip4info", | ||
| "-lpifegeneric", | ||
| ] + get_grpc_linkopts() + ["-lgrpc++_reflection"] | ||
|
|
||
| # Library for starting the gRPC server attached to the switch | ||
| cc_library( | ||
| name = "switch_runner", | ||
| srcs = ["switch_runner.cpp"], | ||
| hdrs = ["switch_runner.h"], | ||
| includes = ["."], | ||
| deps = [ | ||
| "//targets/simple_switch:simpleswitch", | ||
| "//PI:bmpi", | ||
| "//services:bm_grpc_dataplane", | ||
| ], | ||
| linkopts = _PI_LINKOPTS, | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| # The main executable target | ||
| cc_binary( | ||
| name = "simple_switch_grpc", | ||
| srcs = ["main.cpp"], | ||
| deps = [ | ||
| ":switch_runner", | ||
| "//targets/simple_switch:simpleswitch", | ||
| ], | ||
| linkopts = _PI_LINKOPTS, | ||
| visibility = ["//visibility:public"], | ||
| ) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now I have added this code to pass this test if its not required I will remove it