Skip to content

Commit e7f48e1

Browse files
committed
add expoerts for gnmi, add consolidated libswsscommon for CGO
1 parent 49a4a8b commit e7f48e1

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

BUILD

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ cc_library(
5353
# "@swig//:swig",
5454
# ],
5555
visibility = ["//visibility:public"],
56+
# Force all symbols to be included when linking into shared library
57+
# This is required for the consolidated .so to export all symbols needed by SWIG bindings
58+
alwayslink = True,
5659
)
5760

5861
cc_library(
@@ -65,3 +68,53 @@ cc_library(
6568
strip_include_prefix = "common",
6669
deps = [":common"],
6770
)
71+
72+
73+
# Consolidated shared library for cgo to avoid argument list too long
74+
# The :common library has alwayslink=True to ensure all symbols are exported
75+
cc_binary(
76+
name = "libswsscommon_consolidated.so",
77+
srcs = [
78+
# Include static libraries directly to force static linking and bypass linker scripts
79+
"@@rules_distroless++apt+bookworm_libbsd-dev-amd64_0.11.7-2//:usr/lib/x86_64-linux-gnu/libbsd.a",
80+
"@@rules_distroless++apt+bookworm_libmd-dev-amd64_1.0.4-2//:usr/lib/x86_64-linux-gnu/libmd.a",
81+
],
82+
linkshared = True,
83+
linkopts = [
84+
"-static-libstdc++",
85+
"-static-libgcc",
86+
# Allow undefined symbols from external runtime deps (hiredis, zmq, etc.)
87+
# These are resolved at runtime when the .so is loaded
88+
"-Wl,--allow-shlib-undefined",
89+
"-Wl,--undefined-version",
90+
# Exclude libbsd from dynamic linking - we use static .a files above
91+
"-Wl,--exclude-libs,libbsd.a",
92+
"-Wl,--exclude-libs,libmd.a",
93+
],
94+
deps = [":common"],
95+
)
96+
97+
# Alias for compatibility with existing references
98+
alias(
99+
name = "swsscommon_base",
100+
actual = ":common",
101+
)
102+
103+
# Filegroups for swig bindings and other assets
104+
filegroup(
105+
name = "all_hdrs",
106+
srcs = glob([
107+
"common/*.h",
108+
"common/*.hpp",
109+
], allow_empty = True),
110+
)
111+
112+
filegroup(
113+
name = "swig_template",
114+
srcs = ["//pyext:swsscommon.i"],
115+
)
116+
117+
filegroup(
118+
name = "all_luas",
119+
srcs = glob(["common/*.lua"]),
120+
)

pyext/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_shared_library")
33
load("@sonic-build-infra//swig:gen.bzl", "swig_gen")
44
load(":py_native_library.bzl", "py_native_library")
55

6+
exports_files(["swsscommon.i"])
7+
68
swig_gen(
79
name = "swsscommon_pyy",
810
interface = "swsscommon.i",

0 commit comments

Comments
 (0)