Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17

build --copt=-fPIC

build --copt=-Wall
build --copt=-Wextra

build --per_file_copt=external/.*@-Wno-error

build --linkopt=-L/usr/local/lib
build --linkopt=-Wl,-rpath,/usr/local/lib

test --test_output=errors
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.5.0
42 changes: 42 additions & 0 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Bazel Build"

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build_and_test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install system dependencies
run: sudo bash install_deps_ubuntu_22.04.sh

- name: Setup Buildifier
run: |
sudo curl -L https://github.com/bazelbuild/buildtools/releases/download/v8.5.1/buildifier-linux-amd64 -o /usr/bin/buildifier --fail
sudo chmod +x /usr/bin/buildifier

- name: Run Buildifier
run: |
BZL_FILES=$(find . -name *BUILD* -o -name '*bzl' -o -name '*.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: Build
run: bazel build //targets/simple_switch_grpc:simple_switch_grpc

- name: Test
run: bazel test //targets/simple_switch_grpc/tests/...
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ VERSION-build

core
vgcore*

# Bazel build outputs
/bazel-*
MODULE.bazel.lock
50 changes: 50 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:cc_library.bzl", "cc_library")

expand_template(
name = "config_h",
out = "include/bm/config.h",
substitutions = {
# disabled
"#cmakedefine BM_DEBUG_ON @BM_DEBUG_ON@": "/* #undef BM_DEBUG_ON */",
# enabled
"#cmakedefine BM_ELOG_ON @BM_ELOG_ON@": "#define BM_ELOG_ON 1",
"#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",
"#cmakedefine BM_NANOMSG_ON @BM_NANOMSG_ON@": "#define BM_NANOMSG_ON 1",
# disabled
"#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"],
)
13 changes: 13 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module(
name = "behavioral-model",
version = "1.15.0",
bazel_compatibility = [">=7.2.1"],
)

bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_cc", version = "0.2.17")

bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True)

ubuntu2204 = use_extension("//bazel:ubuntu2204.bzl", "ubuntu2204")
use_repo(ubuntu2204, "ubuntu2204")
19 changes: 19 additions & 0 deletions PI/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
copts = ["-Wno-error=redundant-move"],
includes = ["."],
local_defines = ["WITH_SIMPLE_SWITCH"],
visibility = ["//visibility:public"],
deps = [
"//:bm_headers",
"//targets/simple_switch:simpleswitch",
],
alwayslink = True,
)
Empty file added bazel/BUILD.bazel
Empty file.
114 changes: 114 additions & 0 deletions bazel/ubuntu2204.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""
Module extension for system-installed libraries.
"""

def _ubuntu2204_impl(rctx):
rctx.file("BUILD.bazel", """
load("@rules_cc//cc:cc_library.bzl", "cc_library")

# p4lang/PI libraries (installed via apt: p4lang-pi)
cc_library(
name = "pi",
linkopts = ["-lpi"],
visibility = ["//visibility:public"],
)

cc_library(
name = "pifeproto",
linkopts = ["-lpifeproto"],
visibility = ["//visibility:public"],
)

cc_library(
name = "pigrpcserver",
linkopts = ["-lpigrpcserver"],
visibility = ["//visibility:public"],
)

cc_library(
name = "pip4info",
linkopts = ["-lpip4info"],
visibility = ["//visibility:public"],
)

cc_library(
name = "piprotogrpc",
linkopts = ["-lpiprotogrpc"],
visibility = ["//visibility:public"],
)

cc_library(
name = "piprotobuf",
linkopts = ["-lpiprotobuf"],
visibility = ["//visibility:public"],
)

# Boost libraries
cc_library(
name = "boost_program_options",
linkopts = ["-lboost_program_options"],
visibility = ["//visibility:public"],
)

cc_library(
name = "boost_filesystem",
linkopts = ["-lboost_filesystem"],
visibility = ["//visibility:public"],
)

cc_library(
name = "boost_thread",
linkopts = ["-lboost_thread"],
visibility = ["//visibility:public"],
)

cc_library(
name = "boost_system",
linkopts = ["-lboost_system"],
visibility = ["//visibility:public"],
)

# GMP (GNU Multiple Precision)
cc_library(
name = "gmp",
linkopts = ["-lgmp"],
visibility = ["//visibility:public"],
)

# PCAP
cc_library(
name = "pcap",
linkopts = ["-lpcap"],
visibility = ["//visibility:public"],
)

# nanomsg
cc_library(
name = "nanomsg",
linkopts = ["-lnanomsg"],
visibility = ["//visibility:public"],
)

# grpc
cc_library(
name = "grpc",
linkopts = [
"-lgrpc++",
"-lgrpc",
"-lprotobuf",
"-lgpr",
],
visibility = ["//visibility:public"],
)
""")

_ubuntu2204_repo = repository_rule(
implementation = _ubuntu2204_impl,
)

def _ubuntu2204_ext_impl(_):
_ubuntu2204_repo(name = "ubuntu2204")

ubuntu2204 = module_extension(
implementation = _ubuntu2204_ext_impl,
)
3 changes: 1 addition & 2 deletions install_deps_ubuntu_22.04.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ set -e

apt-get update
apt-get install -y curl gnupg
echo 'deb http://download.opensuse.org/repositories/home:/p4lang/xUbuntu_22.04/ /' | tee /etc/apt/sources.list.d/home:p4lang.list
curl -fsSL https://download.opensuse.org/repositories/home:p4lang/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_p4lang.gpg > /dev/null
echo 'deb [trusted=yes] http://download.opensuse.org/repositories/home:/p4lang/xUbuntu_22.04/ /' | tee /etc/apt/sources.list.d/home:p4lang.list

apt-get update

Expand Down
28 changes: 28 additions & 0 deletions services/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")

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=$$(which grpc_cpp_plugin) $(location p4/bm/dataplane_interface.proto)",
)

cc_library(
name = "bm_grpc_dataplane",
srcs = [
"p4/bm/dataplane_interface.grpc.pb.cc",
"p4/bm/dataplane_interface.pb.cc",
],
hdrs = [
"p4/bm/dataplane_interface.grpc.pb.h",
"p4/bm/dataplane_interface.pb.h",
],
includes = ["."],
visibility = ["//visibility:public"],
deps = ["@ubuntu2204//:grpc"],
)
17 changes: 17 additions & 0 deletions src/BMI/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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 = ["@ubuntu2204//:pcap"],
)
31 changes: 31 additions & 0 deletions src/bm_sim/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")

genrule(
name = "version_cpp",
srcs = ["version.cpp.in"],
outs = ["version.cpp"],
cmd = "sed 's/@BM_VERSION@/1.15.0/' $< > $@",
)

cc_library(
name = "bmsim",
srcs = glob([
"*.cpp",
"*.c",
"*.h",
"core/*.cpp",
]) + [":version_cpp"],
copts = ["-Isrc/bm_sim"],
linkopts = ["-ldl"],
visibility = ["//visibility:public"],
deps = [
"//:bm_headers",
"//src/BMI:bmi",
"//third_party:jsoncpp",
"//third_party:spdlog",
"@ubuntu2204//:boost_thread",
"@ubuntu2204//:gmp",
"@ubuntu2204//:nanomsg",
"@ubuntu2204//:pcap",
],
)
23 changes: 23 additions & 0 deletions targets/simple_switch/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
"//third_party:jsoncpp",
"@ubuntu2204//:boost_filesystem",
"@ubuntu2204//:boost_program_options",
],
)
Loading
Loading