From 6245c02aef81356fe7b8fff7b6ce9483f4deffbc Mon Sep 17 00:00:00 2001 From: herengui Date: Thu, 10 Aug 2023 16:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BE=99=E8=8A=AF=E5=92=8C?= =?UTF-8?q?=E7=94=B3=E5=A8=81=E6=9E=B6=E6=9E=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: herengui --- containernetworking-plugins.spec | 97 ++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 36 deletions(-) diff --git a/containernetworking-plugins.spec b/containernetworking-plugins.spec index 6acb07e..e2344aa 100644 --- a/containernetworking-plugins.spec +++ b/containernetworking-plugins.spec @@ -2,27 +2,28 @@ %global with_bundled 1 %global with_check 0 %global with_unit_test 1 - + %global debug_package %{nil} %global project containernetworking %global repo plugins %global import_path github.com/%{project}/%{repo} - + # Used for comparing with latest upstream tag # to decide whether to autobuild %global built_tag v1.1.1 %global built_tag_strip %(b=%{built_tag}; echo ${b:1}) - + Name: %{project}-%{repo} Version: 1.1.1 -Release: 2 +Release: 3 Summary: Libraries for use by writing CNI plugin License: ASL 2.0 URL: https://github.com/containernetworking/plugins Source0: https://github.com/containernetworking/plugins/archive/%{built_tag}.tar.gz Source1: 0001-k3s-cni-adaptation.patch Source2: https://github.com/zchee/reexec/archive/refs/heads/master.zip + BuildRequires: golang >= 1.16.6 BuildRequires: git BuildRequires: systemd-devel @@ -40,43 +41,43 @@ BuildRequires: golang(github.com/vishvananda/netlink) BuildRequires: golang(golang.org/x/sys/unix) BuildRequires: golang(github.com/coreos/go-iptables/iptables) %endif - + Obsoletes: %{project}-cni < 0.7.1-2 Provides: %{project}-cni = %{version}-%{release} Provides: kubernetes-cni - + %description The CNI (Container Network Interface) project consists of a specification and libraries for writing plugins to configure network interfaces in Linux containers, along with a number of supported plugins. CNI concerns itself only with network connectivity of containers and removing allocated resources when the container is deleted. - + %if 0%{?with_devel} %package devel Summary: %{summary} BuildArch: noarch - + %if 0%{?with_check} && ! 0%{?with_bundled} BuildRequires: golang(github.com/coreos/go-iptables/iptables) BuildRequires: golang(github.com/vishvananda/netlink) BuildRequires: golang(golang.org/x/sys/unix) %endif - + %description devel This package contains library source intended for building other packages which use import path with %{import_path} prefix. %endif - + %if 0%{?with_unit_test} && 0%{?with_devel} %package unit-test-devel Summary: Unit tests for %{name} package %if 0%{?with_check} %endif - + Requires: %{name}-devel = %{version}-%{release} - + %if 0%{?with_check} && ! 0%{?with_bundled} BuildRequires: golang(github.com/d2g/dhcp4) BuildRequires: golang(github.com/onsi/ginkgo) @@ -87,39 +88,51 @@ BuildRequires: golang(github.com/onsi/gomega/gbytes) BuildRequires: golang(github.com/onsi/gomega/gexec) BuildRequires: golang(github.com/vishvananda/netlink/nl) %endif - + %description unit-test-devel This package contains unit tests for project providing packages with %{import_path} prefix. %endif - + %prep %autosetup -Sgit -n %{repo}-%{built_tag_strip} rm -rf plugins/main/windows - + # Use correct paths in cni-dhcp unitfiles sed -i 's/\/opt\/cni\/bin/\%{_prefix}\/libexec\/cni/' plugins/ipam/dhcp/systemd/cni-dhcp.service - + +%ifarch sw_64 loongarch64 +# Replace etcd's own sys with the sys provided by golang +%__rm -rf vendor/golang.org/x/sys +%__cp -af %{_prefix}/lib/golang/src/cmd/vendor/golang.org/x/sys vendor/golang.org/x/ +%endif + %build export ORG_PATH="github.com/%{project}" export REPO_PATH="$ORG_PATH/%{repo}" - + if [ ! -h gopath/src/${REPO_PATH} ]; then mkdir -p gopath/src/${ORG_PATH} ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255 fi - + export GOPATH=$(pwd)/gopath mkdir -p $(pwd)/bin export GO111MODULE=off - + echo "Building plugins" export PLUGINS="plugins/meta/* plugins/main/* plugins/ipam/* plugins/sample" for d in $PLUGINS; do if [ -d "$d" ]; then plugin="$(basename "$d")" echo " $plugin" - go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -s -w -linkmode=external -extldflags '%__global_ldflags %{?__golang_extldflags} -Wl,-z,now ' " -a -v -x -o "${PWD}/bin/$plugin" "$@" github.com/containernetworking/plugins/$d + go build \ +%ifarch sw_64 sw64 + -buildmode exe \ +%else + -buildmode pie \ +%endif + -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x -o "${PWD}/bin/$plugin" "$@" github.com/containernetworking/plugins/$d fi done @@ -192,18 +205,24 @@ VERSIONFLAGS=" " TAGS="apparmor seccomp netcgo osusergo providerless" STATIC="-extldflags '-static -lm -ldl -lz -lpthread'" -GO111MODULE=off CGO_ENABLED=0 GOPATH=$TMPDIR go build -tags "$TAGS" -buildmode=pie -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC -s -w -linkmode=external -extldflags '-Wl,-z,relro -Wl,-z,now ' " -o %{_builddir}/cni - +GO111MODULE=off CGO_ENABLED=0 GOPATH=$TMPDIR go build -tags "$TAGS" \ +%ifarch sw_64 + -buildmode exe \ +%else + -buildmode pie \ +%endif + -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC -s -w -linkmode=external -extldflags '-Wl,-z,relro -Wl,-z,now ' " -o %{_builddir}/cni + %install install -d -p %{buildroot}%{_libexecdir}/cni/ install -p -m 0755 bin/* %{buildroot}/%{_libexecdir}/cni cp %{_builddir}/cni %{buildroot}%{_libexecdir}/cni/ install -d -p %{buildroot}/%{gopath}/src/github.com/containernetworking/plugins/ - + install -dp %{buildroot}%{_unitdir} install -p plugins/ipam/dhcp/systemd/cni-dhcp.service %{buildroot}%{_unitdir} install -p plugins/ipam/dhcp/systemd/cni-dhcp.socket %{buildroot}%{_unitdir} - + # source codes for building projects %if 0%{?with_devel} install -d -p %{buildroot}/%{gopath}/src/%{import_path}/ @@ -214,14 +233,14 @@ for file in $(find . \( -iname "*.go" -or -iname "*.s" \) \! -iname "*_test.go" install -d -p %{buildroot}/%{gopath}/src/%{import_path}/$dirprefix cp -pav $file %{buildroot}/%{gopath}/src/%{import_path}/$file echo "%%{gopath}/src/%%{import_path}/$file" >> devel.file-list - + while [ "$dirprefix" != "." ]; do echo "%%dir %%{gopath}/src/%%{import_path}/$dirprefix" >> devel.file-list dirprefix=$(dirname $dirprefix) done done %endif - + # testing files for this project %if 0%{?with_unit_test} && 0%{?with_devel} install -d -p %{buildroot}/%{gopath}/src/%{import_path}/ @@ -231,18 +250,18 @@ for file in $(find . -iname "*_test.go" | grep -v "vendor") ; do install -d -p %{buildroot}/%{gopath}/src/%{import_path}/$dirprefix cp -pav $file %{buildroot}/%{gopath}/src/%{import_path}/$file echo "%%{gopath}/src/%%{import_path}/$file" >> unit-test-devel.file-list - + while [ "$dirprefix" != "." ]; do echo "%%dir %%{gopath}/src/%%{import_path}/$dirprefix" >> devel.file-list dirprefix=$(dirname $dirprefix) done done %endif - + %if 0%{?with_devel} sort -u -o devel.file-list devel.file-list %endif - + %check %if 0%{?with_check} && 0%{?with_unit_test} && 0%{?with_devel} %if ! 0%{?with_bundled} @@ -253,14 +272,14 @@ export GOPATH=%{buildroot}/%{gopath}:%{gopath} # directory from BUILD dir as a gopath to be searched when executing # tests from the BUILDROOT dir. ln -s ./ ./vendor/src # ./vendor/src -> ./vendor - + export GOPATH=%{buildroot}/%{gopath}:$(pwd)/vendor:%{gopath} %endif - + %if ! 0%{?gotest:1} %global gotest go test %endif - + %gotest %{import_path}/libcni %gotest %{import_path}/pkg/invoke %gotest %{import_path}/pkg/ip @@ -286,10 +305,10 @@ export GOPATH=%{buildroot}/%{gopath}:$(pwd)/vendor:%{gopath} %gotest %{import_path}/plugins/meta/flannel %gotest %{import_path}/plugins/test/noop %endif - + #define license tag if not already defined %{!?_licensedir:%global license %doc} - + %files %license LICENSE %doc *.md @@ -297,14 +316,14 @@ export GOPATH=%{buildroot}/%{gopath}:$(pwd)/vendor:%{gopath} %{_libexecdir}/cni/* %{_unitdir}/cni-dhcp.service %{_unitdir}/cni-dhcp.socket - + %if 0%{?with_devel} %files devel -f devel.file-list %license LICENSE %doc *.md %dir %{gopath}/src/github.com/%{project} %endif - + %if 0%{?with_unit_test} && 0%{?with_devel} %files unit-test-devel -f unit-test-devel.file-list %license LICENSE @@ -313,6 +332,12 @@ export GOPATH=%{buildroot}/%{gopath}:$(pwd)/vendor:%{gopath} %changelog +* Thu Aug 10 2023 herengui - 1.1.1-3 +- Type:sync +- ID:NA +- SUG:NA +- DESC: Add support for sw_64 and loongarch64. + * Thu Feb 09 2023 yaoxin - 1.1.1-2 - Add PIE,BIND_NOW,RELRO,STRIP secure compilation options -- Gitee