Skip to content

Commit a3f1f1a

Browse files
authored
Reland 'Make changes to building and packaging sairedis (#1116)' (#1194)
* Reland 'Make changes to building and packaging sairedis (#1116)' * Make changes to building and packaging sairedis This commit includes the following changes: 1. Use Debian build profiles instead of custom build targets to build different configurations of sairedis. Build profiles were designed for this purpose. This also makes the debian/rules file a bit cleaner. 2. Rely on the debug packages being automatically created, instead of us explicitly specifying it in debian/control. 3. Add actual support for excluding Python 2 binding during build. 4. Make sure the compile flags used for building Python 2 and Python 3 are actually correct. Signed-off-by: Saikrishna Arcot <[email protected]> * Update pipeline file Signed-off-by: Saikrishna Arcot <[email protected]> * Fix argument for profile Signed-off-by: Saikrishna Arcot <[email protected]> * Exclude libsai package from the list of dependencies Signed-off-by: Saikrishna Arcot <[email protected]> * Allow multiple syslog artifacts during tests Signed-off-by: Saikrishna Arcot <[email protected]> * Fix debug poackage name in dockerfile Signed-off-by: Saikrishna Arcot <[email protected]> * Fix armhf build due to python binary not existing Signed-off-by: Saikrishna Arcot <[email protected]> --------- Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent 14a863a commit a3f1f1a

13 files changed

+406
-126
lines changed

.azure-pipelines/build-template.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
if [ '${{ parameters.asan }}' == True ]; then
160160
extraflags='--enable-asan'
161161
fi
162-
DEB_BUILD_OPTIONS=nocheck fakeroot debian/rules DEB_CONFIGURE_EXTRA_FLAGS=$extraflags DEB_BUILD_PROFILES=nopython2 CFLAGS="" CXXFLAGS="" binary-syncd-vs
162+
DEB_BUILD_OPTIONS=nocheck DEB_CONFIGURE_EXTRA_FLAGS=$extraflags dpkg-buildpackage -us -uc -b -Psyncd,vs,nopython2 -j$(nproc)
163163
mv ../*.deb .
164164
displayName: "Compile sonic sairedis with coverage enabled"
165165
- script: |
@@ -227,6 +227,6 @@ jobs:
227227
contents: 'syslog-all.tgz'
228228
targetFolder: $(Build.ArtifactStagingDirectory)
229229
- publish: $(Build.ArtifactStagingDirectory)/
230-
artifact: ${{ parameters.syslog_artifact_name }}
230+
artifact: ${{ parameters.syslog_artifact_name }}@$(System.JobAttempt)
231231
displayName: "Publish syslog artifacts"
232232
condition: always()

.azure-pipelines/docker-sonic-vs/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ RUN dpkg -i /debs/libswsscommon_1.0.0_amd64.deb \
1414
/debs/syncd-vs_1.0.0_amd64.deb \
1515
/debs/swss_1.0.0_amd64.deb
1616

17-
RUN if [ "$need_dbg" = "y" ] ; then dpkg -i /debs/syncd-vs-dbg_1.0.0_amd64.deb ; fi
17+
RUN if [ "$need_dbg" = "y" ] ; then dpkg -i /debs/syncd-vs-dbgsym_1.0.0_amd64.deb ; fi

configure.ac

+27-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ AC_PROG_CC
1010
AC_PROG_CXX
1111
AC_PROG_LIBTOOL
1212
AC_HEADER_STDC
13-
AM_PATH_PYTHON
1413
AM_PATH_PYTHON3
14+
AX_PYTHON3_DEVEL
1515
AX_CODE_COVERAGE
1616
AX_ADD_AM_MACRO_STATIC([])
1717

@@ -101,6 +101,14 @@ AC_ARG_ENABLE(asan,
101101
*) AC_MSG_ERROR(bad value ${enableval} for --enable-asan) ;;
102102
esac],[asan_enabled=false])
103103

104+
AC_ARG_ENABLE(python2,
105+
[ --enable-python2 Generate Python 2 bindings],
106+
[case "${enableval}" in
107+
yes) python2=true ;;
108+
no) python2=false ;;
109+
*) AC_MSG_ERROR(bad value ${enableval} for --enable-python2) ;;
110+
esac],[python2=true])
111+
104112
if test "x$asan_enabled" = "xtrue"; then
105113
CFLAGS_ASAN+=" -fsanitize=address"
106114
CFLAGS_ASAN+=" -DASAN_ENABLED"
@@ -111,13 +119,31 @@ if test "x$asan_enabled" = "xtrue"; then
111119
AC_SUBST(LDFLAGS_ASAN)
112120
fi
113121

122+
if test "x$python2" = "xtrue"; then
123+
m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
124+
[python2 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
125+
AM_PATH_PYTHON
126+
AX_PYTHON_DEVEL([< '3'])
127+
PYTHON2_CPPFLAGS=$PYTHON_CPPFLAGS
128+
PYTHON2_LIBS=$PYTHON_LIBS
129+
AC_SUBST(PYTHON2_CPPFLAGS)
130+
AC_SUBST(PYTHON2_LIBS)
131+
else
132+
# The py-compile script either uses $PYTHON (which won't be set if we're not building python 2 bindings),
133+
# or assumes a default of `python` (which may or may not exist as a symlink). Therefore, just assign
134+
# PYTHON3 to PYTHON to make sure it always points to a valid binary.
135+
PYTHON=$PYTHON3
136+
fi
137+
114138
AM_CONDITIONAL(ASAN_ENABLED, test x$asan_enabled = xtrue)
139+
AM_CONDITIONAL(PYTHON2, test x$python2 = xtrue)
115140

116141
AC_PATH_PROGS(SWIG, [swig3.0 swig])
117142

118143
CXXFLAGS_COMMON=""
119144
CXXFLAGS_COMMON+=" -ansi"
120145
CXXFLAGS_COMMON+=" -fPIC"
146+
CXXFLAGS_COMMON+=" -pipe"
121147
CXXFLAGS_COMMON+=" -std=c++14"
122148
CXXFLAGS_COMMON+=" -Wall"
123149
CXXFLAGS_COMMON+=" -Wcast-align"

debian/compat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10
1+
12

debian/control

+12-58
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@ Source: sonic
22
Maintainer: Kamil Cudnik <[email protected]>
33
Section: net
44
Priority: optional
5-
Build-Depends: debhelper (>=9), autotools-dev, libzmq5-dev
5+
Build-Depends: debhelper (>= 12), autotools-dev, libzmq5-dev
66
Standards-Version: 1.0.0
77

88
Package: syncd
99
Architecture: any
10+
Build-Profiles: <syncd !rpc !vs>
11+
Depends: ${misc:Pre-Depends}
12+
Recommends: ${shlibs:Depends}
1013
Conflicts: syncd-rpc, syncd-vs
1114
Description: This package contains sync daemon for SONiC project.
1215
This sync daemon syncs the ASIC_DB in Redis database and the real ASIC via SAI.
1316

1417
Package: syncd-rpc
1518
Architecture: any
19+
Build-Profiles: <syncd rpc !vs>
20+
Depends: ${misc:Pre-Depends}
21+
Recommends: ${shlibs:Depends}
1622
Conflicts: syncd, syncd-vs
1723
Description: This package contains sync daemon with rpc for SONiC project.
1824
This sync daemon syncs the ASIC_DB in Redis database and the real ASIC via SAI.
1925
This daemon contains saithrift rpc library for remote control of an ASIC.
2026

2127
Package: syncd-vs
2228
Architecture: any
29+
Build-Profiles: <syncd !rpc vs>
30+
Depends: ${misc:Pre-Depends}
31+
Recommends: ${shlibs:Depends}
2332
Conflicts: syncd-rpc, syncd
2433
Description: This package contains sync daemon for SONiC project linked with virtual switch.
2534
This sync daemon syncs the ASIC_DB in Redis database and the real ASIC via SAI.
@@ -38,6 +47,7 @@ Description: This package contains development files for SAI-Redis.
3847

3948
Package: libsaivs
4049
Architecture: any
50+
Depends: ${shlibs:Depends}, ${misc:Pre-Depends}
4151
Section: libs
4252
Description: This package contains SAI-VirtualSwitch implementation for SONiC project.
4353

@@ -49,6 +59,7 @@ Description: This package contains development files for SAI-VirtualSwitch.
4959

5060
Package: libsaimetadata
5161
Architecture: any
62+
Depends: ${shlibs:Depends}, ${misc:Pre-Depends}
5263
Section: libs
5364
Description: This package contains SAI-Metadata implementation for SONiC project.
5465

@@ -58,63 +69,6 @@ Depends: libsaimetadata (= ${binary:Version})
5869
Section: libdevel
5970
Description: This package contains development files for SAI-Metadata.
6071

61-
Package: syncd-dbg
62-
Architecture: any
63-
Section: debug
64-
Priority: extra
65-
Conflicts: syncd-rpc-dbg, syncd-vs
66-
Depends:
67-
syncd (= ${binary:Version}),
68-
${misc:Depends}
69-
Description: debugging symbols for syncd
70-
71-
Package: syncd-rpc-dbg
72-
Architecture: any
73-
Section: debug
74-
Priority: extra
75-
Conflicts: syncd-dbg, syncd-vs
76-
Depends:
77-
syncd-rpc (= ${binary:Version}),
78-
${misc:Depends}
79-
Description: debugging symbols for syncd-rpc
80-
81-
Package: syncd-vs-dbg
82-
Architecture: any
83-
Section: debug
84-
Priority: extra
85-
Conflicts: syncd-dbg, syncd-rpc-dbg
86-
Depends:
87-
syncd-vs (= ${binary:Version}),
88-
${misc:Depends}
89-
Description: debugging symbols for syncd-vs
90-
91-
Package: libsairedis-dbg
92-
Architecture: any
93-
Section: debug
94-
Priority: extra
95-
Depends:
96-
libsairedis (= ${binary:Version}),
97-
${misc:Depends}
98-
Description: debugging symbols for libsairedis
99-
100-
Package: libsaivs-dbg
101-
Architecture: any
102-
Section: debug
103-
Priority: extra
104-
Depends:
105-
libsaivs (= ${binary:Version}),
106-
${misc:Depends}
107-
Description: debugging symbols for libsaivs
108-
109-
Package: libsaimetadata-dbg
110-
Architecture: any
111-
Section: debug
112-
Priority: extra
113-
Depends:
114-
libsaimetadata (= ${binary:Version}),
115-
${misc:Depends}
116-
Description: debugging symbols for libsaimetadata
117-
11872
Package: python-pysairedis
11973
Architecture: any
12074
Build-Profiles: <!nopython2>

debian/libsaimetadata-dev.install

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
meta/sai*.h usr/include/sai
22
meta/Sai*.h usr/include/sai
33
SAI/meta/sai*.h usr/include/sai
4+
usr/lib/*/libsaimetadata.so
5+
usr/lib/*/libsaimeta.so

debian/libsairedis-dev.install

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
lib/sairedis.h usr/include/sai
2+
usr/lib/*/libsairedis.so

debian/rules

+24-57
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
# output every command that modifies files on the build system.
44
#export DH_VERBOSE = 1
55

6-
.ONESHELL:
7-
SHELL = /bin/bash
8-
.SHELLFLAGS += -ex
9-
10-
# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
11-
DPKG_EXPORT_BUILDFLAGS = 1
12-
include /usr/share/dpkg/default.mk
13-
146
ifneq (${SWSS_COMMON_INC},)
157
SWSS_COMMON_CONFIG = "--with-swss-common-inc=${SWSS_COMMON_INC}"
168
endif
@@ -21,7 +13,7 @@ ifneq (${SWSS_COMMON_LIB},)
2113
endif
2214

2315
# see FEATURE AREAS in dpkg-buildflags(1)
24-
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
16+
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
2517

2618
# see ENVIRONMENT in dpkg-buildflags(1)
2719
# package maintainers to append CFLAGS
@@ -31,78 +23,53 @@ endif
3123

3224
DOPACKAGES = $(shell dh_listpackages)
3325

26+
configure_opts = --disable-static
27+
ifeq ($(ENABLE_ASAN), y)
28+
configure_opts += --enable-asan
29+
endif
30+
3431
# For Debian jessie, stretch, and buster, and Ubuntu bionic and focal, build
3532
# Python 2 bindings. This is controlled by the build profile being used.
36-
ifneq (,$(filter python-pysairedis,$(DOPACKAGES)))
33+
ifeq (,$(filter nopython2,$(DEB_BUILD_PROFILES)))
3734
configure_opts += --enable-python2
3835
else
3936
configure_opts += --disable-python2
4037
endif
4138

42-
clean:
43-
dh $@ --with autotools-dev
44-
45-
build:
46-
echo build stage is skipped. Please use binary to generate debian packages
47-
48-
binary: binary-syncd-rpc binary-syncd
49-
50-
binary-sairedis:
51-
echo '--enable-syncd=no' > /tmp/syncd-build
52-
ENABLESYNCD=no dh clean --with autotools-dev
53-
dh build -N syncd -N syncd-dbg -N syncd-rpc -N syncd-rpc-dbg -N syncd-vs -N syncd-vs-dbg --with autotools-dev
54-
dh binary -N syncd -N syncd-dbg -N syncd-rpc -N syncd-rpc-dbg -N syncd-vs -N syncd-vs-dbg --with autotools-dev
55-
56-
binary-syncd:
57-
echo > /tmp/syncd-build
58-
dh clean --with autotools-dev
59-
dh build -N syncd-rpc -N syncd-rpc-dbg -N syncd-vs -N syncd-vs-dbg --with autotools-dev
60-
dh binary -N syncd-rpc -N syncd-rpc-dbg -N syncd-vs -N syncd-vs-dbg --with autotools-dev
61-
62-
binary-syncd-rpc: | binary-syncd
63-
echo '--enable-rpcserver=yes' > /tmp/syncd-build
64-
dh clean --with autotools-dev
65-
dh build -N syncd -N syncd-dbg -N syncd-vs -N syncd-vs-dbg --with autotools-dev
66-
dh binary -N syncd -N syncd-dbg -N syncd-vs -N syncd-vs-dbg --with autotools-dev
39+
ifneq ($(filter syncd,$(DEB_BUILD_PROFILES)),)
40+
ifneq ($(filter rpc,$(DEB_BUILD_PROFILES)),)
41+
configure_opts += --enable-rpcserver
42+
endif
43+
ifneq ($(filter vs,$(DEB_BUILD_PROFILES)),)
44+
configure_opts += --with-sai=vs
45+
endif
46+
else
47+
configure_opts += --disable-syncd
48+
endif
6749

68-
binary-syncd-vs:
69-
echo '--with-sai=vs' > /tmp/syncd-build
70-
dh clean --with autotools-dev
71-
dh build -N syncd -N syncd-dbg -N syncd-rpc -N syncd-rpc-dbg --with autotools-dev
72-
dh binary -N syncd -N syncd-dbg -N syncd-rpc -N syncd-rpc-dbg --with autotools-dev
50+
%:
51+
dh $@
7352

7453
# dh_make generated override targets
7554
# This is example for Cmake (See https://bugs.debian.org/641051 )
7655
#override_dh_auto_configure:
7756
# dh_auto_configure -- \
7857
# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
7958

80-
configure_opts =
81-
ifeq ($(ENABLE_ASAN), y)
82-
configure_opts += --enable-asan
83-
endif
84-
8559
override_dh_auto_configure:
86-
./autogen.sh
87-
dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS) $(shell cat /tmp/syncd-build) ${SWSS_COMMON_CONFIG} $(configure_opts)
60+
dh_auto_configure -- ${SWSS_COMMON_CONFIG} $(configure_opts)
8861

8962
override_dh_install:
9063
dh_install
9164
# Note: escape $ with an extra $ symbol
92-
if egrep -q '(^| )--enable-rpcserver=yes( |$$)' /tmp/syncd-build && [ -f debian/syncd-rpc/usr/bin/syncd_init_common.sh ] ; then
65+
ifneq ($(filter rpc,$(DEB_BUILD_PROFILES)),)
66+
if [ -f debian/syncd-rpc/usr/bin/syncd_init_common.sh ] ; then
9367
sed -i 's|ENABLE_SAITHRIFT=0|ENABLE_SAITHRIFT=1 # Add a comment to fix https://github.com/Azure/sonic-buildimage/issues/2694 |' debian/syncd-rpc/usr/bin/syncd_init_common.sh
9468
fi
69+
endif
9570

9671
override_dh_installinit:
9772
dh_installinit --init-script=syncd
9873

9974
override_dh_shlibdeps:
100-
$(LD_LIBRARY_PATH_CONFIG) dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
101-
102-
override_dh_strip:
103-
dh_strip -psyncd-rpc --dbg-package=syncd-rpc-dbg
104-
dh_strip -psyncd --dbg-package=syncd-dbg
105-
dh_strip -psyncd-vs --dbg-package=syncd-vs-dbg
106-
dh_strip -plibsairedis --dbg-package=libsairedis-dbg
107-
dh_strip -plibsaivs --dbg-package=libsaivs-dbg
108-
dh_strip -plibsaimetadata --dbg-package=libsaimetadata-dbg
75+
$(LD_LIBRARY_PATH_CONFIG) dh_shlibdeps -- --ignore-missing-info -xlibsai

0 commit comments

Comments
 (0)