Skip to content

Commit 4bc9311

Browse files
PINS Working Groupbocon13
PINS Working Group
authored andcommitted
Add Bazel support for external projects
Bazel build support allows swss-common to used in Bazel projects; this doesn’t change/impact the make-based build system Additionally, - Add Bazel test to CI - Update .gitignore Co-authored-by: Robert J. Halstead [email protected] Co-authored-by: Runming Wu [email protected]
1 parent 1dfe06f commit 4bc9311

File tree

6 files changed

+98
-0
lines changed

6 files changed

+98
-0
lines changed

.bazelversion

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.0.0

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ stamp-h1
6161
###############
6262
common/swssloglevel
6363
tests/tests
64+
65+
# Bazel Build System #
66+
/bazel-*

BUILD

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
exports_files(["LICENSE"])
4+
5+
cc_library(
6+
name = "common",
7+
srcs = glob(["common/*.cpp"], exclude=["common/loglevel.cpp"]),
8+
hdrs = glob([
9+
"common/*.h",
10+
"common/*.hpp",
11+
]),
12+
copts = [
13+
"-I/usr/include/libnl3", # Expected location in the SONiC build container"
14+
],
15+
includes = [
16+
"common",
17+
],
18+
linkopts = ["-lpthread -lhiredis -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3"],
19+
visibility = ["//visibility:public"],
20+
)
21+
22+
cc_library(
23+
name = "libswsscommon",
24+
hdrs = glob([
25+
"common/*.h",
26+
"common/*.hpp",
27+
]),
28+
include_prefix = "swss",
29+
strip_include_prefix = "common",
30+
deps = [":common"],
31+
)

WORKSPACE

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
workspace(name = "sonic_swss_common")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "com_google_absl",
7+
sha256 = "b3744a4f7a249d5eaf2309daad597631ce77ea62e0fc6abffbab4b4c3dc0fc08",
8+
strip_prefix = "abseil-cpp-20200923",
9+
url = "https://github.com/abseil/abseil-cpp/archive/20200923.tar.gz",
10+
)
11+
12+
http_archive(
13+
name = "com_google_googletest",
14+
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
15+
strip_prefix = "googletest-release-1.10.0",
16+
urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"],
17+
)
18+
19+
http_archive(
20+
name = "com_github_google_glog",
21+
sha256 = "f28359aeba12f30d73d9e4711ef356dc842886968112162bc73002645139c39c",
22+
strip_prefix = "glog-0.4.0",
23+
url = "https://github.com/google/glog/archive/v0.4.0.tar.gz",
24+
)
25+
26+
http_archive(
27+
name = "com_github_gflags_gflags",
28+
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
29+
strip_prefix = "gflags-2.2.2",
30+
url = "https://github.com/gflags/gflags/archive/v2.2.2.tar.gz",
31+
)

azure-pipelines.yml

+9
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,20 @@ stages:
4141
sudo apt-get install -y python
4242
sudo apt-get install cmake libgtest-dev libgmock-dev
4343
cd /usr/src/gtest && sudo cmake . && sudo make
44+
ARCH=$(dpkg --print-architecture)
45+
set -x
46+
sudo curl -fsSL -o /usr/local/bin/bazel \
47+
https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-${ARCH}
48+
sudo chmod 755 /usr/local/bin/bazel
4449
displayName: "Install dependencies"
4550
- script: |
4651
./autogen.sh
4752
dpkg-buildpackage -rfakeroot -us -uc -b -j$(nproc) && cp ../*.deb .
4853
displayName: "Compile sonic swss common"
54+
- script: |
55+
bazel build //...
56+
bazel test //...
57+
displayName: "Compile and test all Bazel targets"
4958
- publish: $(System.DefaultWorkingDirectory)/
5059
artifact: sonic-swss-common.amd64.ubuntu20_04
5160
displayName: "Archive swss common debian packages"

tests/BUILD

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
cc_test(
4+
name = "status_code_util_test",
5+
srcs = ["status_code_util_test.cpp"],
6+
deps = [
7+
"//:libswsscommon",
8+
"@com_github_google_glog//:glog",
9+
"@com_google_googletest//:gtest",
10+
"@com_google_googletest//:gtest_main",
11+
],
12+
)
13+
14+
cc_test(
15+
name = "saiaclschema_ut",
16+
srcs = ["saiaclschema_ut.cpp"],
17+
deps = [
18+
"//:libswsscommon",
19+
"@com_github_google_glog//:glog",
20+
"@com_google_googletest//:gtest",
21+
"@com_google_googletest//:gtest_main",
22+
],
23+
)

0 commit comments

Comments
 (0)