Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fd1508e
upgrade to bazel 8 and bzlmod
thesayyn Sep 3, 2025
fb3c520
local changes
thesayyn Oct 2, 2025
9c8b2e2
tls
thesayyn Nov 27, 2025
676ae5b
all tests passing
thesayyn Dec 1, 2025
c773222
fix boost
thesayyn Dec 4, 2025
49a4a8b
latest
thesayyn Dec 12, 2025
fb068d7
fix swig
thesayyn Dec 16, 2025
e7f48e1
add expoerts for gnmi, add consolidated libswsscommon for CGO
Mivr Jan 7, 2026
5c4c07d
Merge pull request #1 from thesayyn/gnmi-image
thesayyn Feb 9, 2026
bd870b5
feat: Add build files for sonic-db-cli (#2)
blorente Feb 11, 2026
771d9b0
checkpoint: I can build swss
blorente Feb 13, 2026
4d7c6e5
checkpoint; Works with transition
blorente Feb 13, 2026
cef4bca
Merge pull request #3 from blorente/blorente/swss-again
thesayyn Feb 13, 2026
06ce6c2
cleanup: Remove TODO BL: instances (#4)
blorente Feb 21, 2026
5de5912
fix: Pin bazel version to match sonic-buildimage
blorente Mar 3, 2026
4ab7547
feat: Add swssloglevel binary
blorente Mar 4, 2026
379960f
feat: Add libswsscommon.deb package
blorente Mar 4, 2026
33c3432
cleanup: Update MODULE.bazel.lock file
blorente Mar 6, 2026
58dd3d1
fix: Switch to libnl3 built from buildimage
blorente Mar 9, 2026
2c3269f
cgo: include dynamic library when interface library is a linker script
thesayyn Mar 14, 2026
64ee262
fix goext
thesayyn Mar 18, 2026
a5791d7
fix: Add workaround for rules_m4
blorente Mar 30, 2026
6dc7dba
feat: Add sonic-db-cli_pkg debian package
blorente Mar 31, 2026
bfb6798
fix: re-enable ignored swig statements
blorente Mar 31, 2026
27ea4b5
chore: Update lockfile
blorente Mar 31, 2026
2bc15b2
cleanup: Remove packages.lock after updating rules_distroless
blorente Apr 1, 2026
85f37c9
fix: Use git_override for rules_distroless
blorente Apr 2, 2026
6108a25
fix: Adapt local_path_overrides to buildimage submodules
blorente Apr 2, 2026
9d06d6c
feat: Use local registry from sonic-buildimage
blorente Apr 2, 2026
c707627
fix: Handle const * strings in swsscommon.i constants
blorente Apr 5, 2026
cff3921
fix: Replace rules_go with patched version for cgo import propagation
blorente Apr 5, 2026
390b0fe
fix: Only ignore default strings in SWIGGO, leave Python alone
blorente Apr 5, 2026
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
9 changes: 9 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
common --check_direct_dependencies=off
common --noincompatible_disallow_empty_glob

# TODO(bazel-ready): This assumes this repo is a submodule of sonic-buildimage.
common --registry=file://%workspace%/../../tools/bazel/registry

# Custom registry for swig 4.1.0
common --registry=https://raw.githubusercontent.com/thesayyn/bazel-central-registry/main/
common --registry=https://bcr.bazel.build/
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0
8.5.1
226 changes: 218 additions & 8 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,32 +1,242 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_distroless//distroless:defs.bzl", "flatten")
load("@tar.bzl", "mtree_mutate", "mtree_spec", "tar")
load("//:always_link_transition.bzl", "alwayslink_cc_binary")
load("//bazel:flags.bzl", "CXXFLAGS_COMMON", "DBGFLAGS")

package(default_visibility = ["//visibility:public"])

exports_files(["LICENSE"])

swss_common_hdrs = glob([
"common/*.h",
"common/*.hpp",
], allow_empty = True)

swss_common_deps = [
"@bookworm//libhiredis-dev:libhiredis",
"@bookworm//nlohmann-json3-dev:nlohmann-json3",
"@libnl3//:libnl_3",
"@libnl3//:libnl_route_3",
"@libnl3//:libnl_nf_3",
"@bookworm//libyang2-dev:libyang2",
"@bookworm//libzmq3-dev:libzmq3",
"@bookworm//uuid-dev:uuid",
"@bookworm//libboost-dev:libboost",
"@bookworm//libboost-serialization-dev:libboost-serialization",
]

filegroup(
name = "hdrs",
srcs = swss_common_hdrs,
)

# Necessary for when we import swss_common as a prebuilt .so file.
# We want all the deps from swsscommon, but none of the symbols.
# The symbols will come from the prebuilt .so file.
# TODO Remove once the cc_shared_library version of swss_common works with rules_distroless.
cc_library(
name = "common_deps",
deps = swss_common_deps,
)

# Necessary for when we import swss_common as a dynamic .so file.
# We don't want to include the whole archive when we want to override them with mocks.
# TODO Remove once the cc_shared_library version of swss_common works with rules_distroless.
bool_flag(
name = "alwayslink",
build_setting_default = False,
)

config_setting(
name = "alwayslink_false",
flag_values = { ":alwayslink": "false" }
)

config_setting(
name = "alwayslink_true",
flag_values = { ":alwayslink": "true" }
)

cc_library(
name = "common",
srcs = glob(["common/*.cpp"], exclude=["common/loglevel.cpp", "common/loglevel_util.cpp"]),
hdrs = glob([
"common/*.h",
"common/*.hpp",
]),
srcs = glob(
["common/*.cpp"],
["common/loglevel.cpp", "common/loglevel_util.cpp"]
),
hdrs = swss_common_hdrs,
copts = [
"-fPIC",
"-std=c++14",
"-I/usr/include/libnl3", # Expected location in the SONiC build container"
# TODO: this is not required with apt.installed debs.
# "-I/usr/include/libnl3", # Expected location in the SONiC build container"
],
# Not needed with apt.install
# linkopts = ["-lpthread -lhiredis -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 -lzmq -luuid -lyang"],
includes = [
"common",
],
linkopts = ["-lpthread -lhiredis -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 -lzmq -lboost_serialization -luuid -lyang"],
linkopts = ["-lboost_serialization"],
# Approach 1:
deps = swss_common_deps,
# Approach 2: BCR entries compiled from source
# deps = [
# "@boost.algorithm",
# "@boost.serialization",
# "@nlohmann_json//:json",
# "@libuuid//:libuuid",
# "@swig//:swig",
# ],
visibility = ["//visibility:public"],
# Force all symbols to be included when linking into shared library
# This is required for the consolidated .so to export all symbols needed by SWIG bindings
# However, some builds like `sonic-swss` will refuse to link if they are always linked,
# because symbols in `libcommon.a` will conflict with test mocks. Hence, the select()
alwayslink = select({
":alwayslink_true": True,
":alwayslink_false": False,
}),
)

cc_library(
name = "libswsscommon",
hdrs = glob([
"common/*.h",
"common/*.hpp",
]),
], allow_empty = True),
include_prefix = "swss",
strip_include_prefix = "common",
deps = [":common"],
)

# Consolidated shared library for cgo to avoid argument list too long
# The :common library has alwayslink=True to ensure all symbols are exported
cc_binary(
name = "libswsscommon_consolidated_base",
srcs = [
# Include static libraries directly to force static linking and bypass linker scripts
"@@rules_distroless++apt+bookworm_libbsd-dev-amd64_0.11.7-2//:usr/lib/x86_64-linux-gnu/libbsd.a",
"@@rules_distroless++apt+bookworm_libmd-dev-amd64_1.0.4-2//:usr/lib/x86_64-linux-gnu/libmd.a",
],
linkshared = True,
linkopts = [
"-static-libstdc++",
"-static-libgcc",
# Allow undefined symbols from external runtime deps (hiredis, zmq, etc.)
# These are resolved at runtime when the .so is loaded
"-Wl,--allow-shlib-undefined",
"-Wl,--undefined-version",
# Exclude libbsd from dynamic linking - we use static .a files above
"-Wl,--exclude-libs,libbsd.a",
"-Wl,--exclude-libs,libmd.a",
],
deps = [":common"],
)

# If we're building the consolidated binary, we always want to link it.
alwayslink_cc_binary(
name = "libswsscommon_consolidated.so",
binary = "libswsscommon_consolidated_base",
)

# Alias for compatibility with existing references
alias(
name = "swsscommon_base",
actual = ":common",
)

# Filegroups for swig bindings and other assets
filegroup(
name = "all_hdrs",
srcs = glob([
"common/*.h",
"common/*.hpp",
], allow_empty = True),
)

filegroup(
name = "swig_template",
srcs = ["//pyext:swsscommon.i"],
)

filegroup(
name = "all_luas",
srcs = glob(["common/*.lua"]),
)

# TODO(bazel-ready): CFLAGS_COMMON is not respected yet in many of these targets.

cc_binary(
name = "swssloglevel",
srcs = [
"common/loglevel.cpp",
"common/loglevel_util.cpp",
"common/loglevel.h",
],
deps = ["libswsscommon"],
linkopts = [
"-Wl,-z,now",
],
cxxopts = CXXFLAGS_COMMON,
linkstatic = True,
)

# libswsscommon deb-style distribution package
# Matches debian/libswsscommon.install:
# usr/lib/*/lib*.so.*
# usr/share/swss/*.lua
# var/run/redis/sonic-db/database_config.json
# usr/bin/swssloglevel

mtree_spec(
name = "dist_lua_mtree_base",
srcs = [":all_luas"],
)

mtree_mutate(
name = "dist_lua_mtree",
mtree = ":dist_lua_mtree_base",
strip_prefix = "common",
package_dir = "usr/share/swss",
)

tar(
name = "dist_lua",
srcs = [":all_luas"],
mtree = ":dist_lua_mtree",
)

# Loose files: shared library, config, and binaries
tar(
name = "dist_loose",
srcs = [
":libswsscommon_consolidated.so",
"common/database_config.json",
":swssloglevel",
],
mtree = [
"usr/lib/x86_64-linux-gnu/libswsscommon.so type=file content=$(location :libswsscommon_consolidated.so)",
"var/run/redis/sonic-db/database_config.json type=file content=$(location common/database_config.json)",
"usr/bin/swssloglevel type=file mode=0755 content=$(location :swssloglevel)",
],
)

flatten(
name = "libswsscommon_pkg",
tars = [
":dist_lua",
":dist_loose",
],
visibility = ["//visibility:public"],
)

tar(
name = "sonic-db-cli_pkg",
srcs = [
"//sonic-db-cli:sonic-db-cli",
],
mtree = [
"usr/bin/sonic-db-cli type=file mode=0755 content=$(location //sonic-db-cli:sonic-db-cli)",
],
visibility = ["//visibility:public"],
)
98 changes: 98 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Keep bazel_compatibility in sync with sonic-buildimage's .bazelversion.
module(
name = "sonic-swss-common",
version = "0.0.0",
bazel_compatibility = [">=8.5.1", "<=8.5.1"],
)

bazel_dep(name = "googletest", version = "1.11.0", repo_name = "com_google_googletest")
bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")
bazel_dep(name = "rules_python", version = "1.7.0")
bazel_dep(name = "rules_go", version = "0.60.0.sonic-patched", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_cc", version = "0.2.8")

bazel_dep(name = "rules_pkg", version = "1.1.0")
bazel_dep(name = "tar.bzl", version = "0.9.0")
bazel_dep(name = "bazel_skylib", version = "1.8.2")

bazel_dep(name = "rules_distroless", version = "0.0.0")
git_override(
module_name = "rules_distroless",
commit = "ebfd74a2e07b83235e064bb63ace98a1a5223e02",
remote = "https://github.com/bazel-contrib/rules_distroless",
)

bazel_dep(name = "sonic-build-infra", version = "0.0.0", repo_name = "sonic_build_infra")

bazel_dep(name = "libnl3", version = "3.7.0")

# TODO(bazel-ready): replace with new version of rules_m4 when this merges:
# https://github.com/jmillikin/rules_m4/pull/23
git_override(
module_name = "rules_m4",
commit = "54e35332761523b8b8c7e7a17c8fd3733e53e3e7",
remote = "https://github.com/blorente/rules_m4",
)

register_toolchains("@sonic_build_infra//toolchains/gcc:host_gcc_toolchain")

apt = use_extension("@rules_distroless//apt:extensions.bzl", "apt")

apt.sources_list(
architectures = ["amd64"],
components = ["main"],
suites = ["bookworm", "bookworm-updates"],
uris = ["https://snapshot.debian.org/archive/debian/20251001T023456Z"],
)

apt.sources_list(
architectures = ["amd64"],
components = ["main"],
suites = ["bookworm-security"],
uris = ["https://snapshot.debian.org/archive/debian-security/20251001T023456Z"],
)

# sudo apt-get install -y
# make libtool m4 autoconf dh-exec debhelper cmake pkg-config
# nlohmann-json3-dev libhiredis-dev swig3.0 libpython2.7-dev libboost-dev
# libboost-serialization-dev uuid-dev libzmq3-dev
# libnl-3-dev libnl-genl-3-dev libnl-route-3-dev libnl-nf-3-dev -> @libnl3 module

apt.install(
dependency_set = "bookworm",
suites = [
"bookworm",
"bookworm-security",
"bookworm-updates",
],
packages = [
"nlohmann-json3-dev",
"libhiredis-dev",
"libboost-dev",
"libboost-serialization-dev",
"uuid-dev",
"libzmq3-dev",
"libyang2-dev",
"swig",
"python3-dev"

# These seem to be unused
# "swig3.0",
# "libpython2.7-dev",
# "libgtest-dev",
# "libgmock-dev",
]
)

use_repo(apt, "bookworm")

# bazel_dep(name = "googletest", version = "1.11.0", repo_name = "com_google_googletest")
# bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")
# bazel_dep(name = "nlohmann_json", version = "3.12.0")
# bazel_dep(name = "boost.algorithm", version = "1.87.0")
# bazel_dep(name = "boost.serialization", version = "1.87.0")
# bazel_dep(name = "libuuid", version = "2.39.3.bcr.1")
# bazel_dep(name = "libzmq", version = "4.3.5.bcr.3")
# bazel_dep(name = "swig", version = "4.3.0")
# bazel_dep(name = "abseil-cpp", version = "20210324.2")
# bazel_dep(name = "gflags", version = "2.2.2")
Loading
Loading