Skip to content

[PINS] Add Bazel support for external projects #557

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 1 commit into from
Nov 19, 2021
Merged
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
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ stamp-h1
###############
common/swssloglevel
tests/tests

# Bazel Build System #
/bazel-*
31 changes: 31 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package(default_visibility = ["//visibility:public"])

exports_files(["LICENSE"])

cc_library(
name = "common",
srcs = glob(["common/*.cpp"], exclude=["common/loglevel.cpp"]),
hdrs = glob([
"common/*.h",
"common/*.hpp",
]),
copts = [
"-I/usr/include/libnl3", # Expected location in the SONiC build container"
],
includes = [
"common",
],
linkopts = ["-lpthread -lhiredis -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3"],
visibility = ["//visibility:public"],
)

cc_library(
name = "libswsscommon",
hdrs = glob([
"common/*.h",
"common/*.hpp",
]),
include_prefix = "swss",
strip_include_prefix = "common",
deps = [":common"],
)
31 changes: 31 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
workspace(name = "sonic_swss_common")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "com_google_absl",
sha256 = "b3744a4f7a249d5eaf2309daad597631ce77ea62e0fc6abffbab4b4c3dc0fc08",
strip_prefix = "abseil-cpp-20200923",
url = "https://github.com/abseil/abseil-cpp/archive/20200923.tar.gz",
)

http_archive(
name = "com_google_googletest",
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
strip_prefix = "googletest-release-1.10.0",
urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"],
)

http_archive(
name = "com_github_google_glog",
sha256 = "f28359aeba12f30d73d9e4711ef356dc842886968112162bc73002645139c39c",
strip_prefix = "glog-0.4.0",
url = "https://github.com/google/glog/archive/v0.4.0.tar.gz",
)

http_archive(
name = "com_github_gflags_gflags",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
strip_prefix = "gflags-2.2.2",
url = "https://github.com/gflags/gflags/archive/v2.2.2.tar.gz",
)
9 changes: 9 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,20 @@ stages:
sudo apt-get install -y python
sudo apt-get install cmake libgtest-dev libgmock-dev
cd /usr/src/gtest && sudo cmake . && sudo make
ARCH=$(dpkg --print-architecture)
set -x
sudo curl -fsSL -o /usr/local/bin/bazel \
https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-${ARCH}
sudo chmod 755 /usr/local/bin/bazel
displayName: "Install dependencies"
- script: |
./autogen.sh
dpkg-buildpackage -rfakeroot -us -uc -b -j$(nproc) && cp ../*.deb .
displayName: "Compile sonic swss common"
- script: |
bazel build //...
bazel test //...
displayName: "Compile and test all Bazel targets"
- publish: $(System.DefaultWorkingDirectory)/
artifact: sonic-swss-common.amd64.ubuntu20_04
displayName: "Archive swss common debian packages"
Expand Down
23 changes: 23 additions & 0 deletions tests/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package(default_visibility = ["//visibility:public"])

cc_test(
name = "status_code_util_test",
srcs = ["status_code_util_test.cpp"],
deps = [
"//:libswsscommon",
"@com_github_google_glog//:glog",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "saiaclschema_ut",
srcs = ["saiaclschema_ut.cpp"],
deps = [
"//:libswsscommon",
"@com_github_google_glog//:glog",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)