@@ -21,28 +21,74 @@ set -e
2121project=" runc"
2222root=" $( readlink -f " $( dirname " ${BASH_SOURCE[0]} " ) /.." ) "
2323
24+ # Sets the value of HOST (used in configure --host=$HOST)
25+ # depending on the architecture specified.
26+ function setHOST() {
27+ case $1 in
28+ arm64)
29+ HOST=aarch64-linux-gnu
30+ ;;
31+ * )
32+ echo " setHOST: unsupported architecture: $arch " >&2
33+ exit 1
34+ ;;
35+ esac
36+ }
37+
38+ # Due to libseccomp being LGPL we must include its sources,
39+ # so download, install and build against it.
40+ # Parameters:
41+ # $1 -- destination directory to put the source tarball in.
42+ # $* -- additional architectures to cross-compile for
43+ # (currently only arm64 is supported).
44+ function build_libseccomp() {
45+ local ver=" 2.5.1"
46+ local tar=" libseccomp-${ver} .tar.gz"
47+ local dest=" $1 "
48+ shift
49+
50+ # Download.
51+ wget " https://github.com/seccomp/libseccomp/releases/download/v${ver} /${tar} " {,.asc}
52+
53+ # Build and install natively.
54+ tar xf " $tar "
55+ pushd " libseccomp-${ver} "
56+ local prefix
57+ prefix=" $( mktemp -d) "
58+ ./configure \
59+ --prefix=" $prefix " --libdir=" $prefix /lib" \
60+ --enable-static --disable-shared
61+ LIBSECCOMP_PREFIX=" $prefix "
62+
63+ make install
64+ make clean
65+
66+ # Build and install for additional architectures.
67+ local arch
68+ for arch in " $@ " ; do
69+ prefix=" $( mktemp -d) "
70+ setHOST " $arch "
71+ ./configure --host " $HOST " \
72+ --prefix=" $prefix " --libdir=" $prefix /lib" \
73+ --enable-static --disable-shared
74+ make install
75+ make clean
76+ eval " LIBSECCOMP_PREFIX_${arch} =$prefix "
77+ done
78+
79+ # Place the source tarball to $dest.
80+ popd
81+ mv " $tar " {,.asc} " $dest "
82+ }
83+
2484# This function takes an output path as an argument, where the built
2585# (preferably static) binary should be placed.
2686function build_project() {
2787 local builddir
2888 builddir=" $( dirname " $1 " ) "
89+ shift
2990
30- # Due to libseccomp being LGPL we must include its sources,
31- # so download, install and build against it.
32-
33- local libseccomp_ver=' 2.5.1'
34- local tarball=" libseccomp-${libseccomp_ver} .tar.gz"
35- local prefix
36- prefix=" $( mktemp -d) "
37- wget " https://github.com/seccomp/libseccomp/releases/download/v${libseccomp_ver} /${tarball} " {,.asc}
38- tar xf " $tarball "
39- (
40- cd " libseccomp-${libseccomp_ver} "
41- ./configure --prefix=" $prefix " --libdir=" $prefix /lib" \
42- --enable-static --disable-shared
43- make install
44- )
45- mv " $tarball " {,.asc} " $builddir "
91+ build_libseccomp " $builddir " " $@ "
4692
4793 # For reproducible builds, add these to EXTRA_LDFLAGS:
4894 # -w to disable DWARF generation;
@@ -52,10 +98,25 @@ function build_project() {
5298 # Add -a to go build flags to make sure it links against
5399 # the provided libseccomp, not the system one (otherwise
54100 # it can reuse cached pkg-config results).
55- make -C " $root " PKG_CONFIG_PATH=" ${prefix} /lib/pkgconfig" COMMIT_NO= EXTRA_FLAGS=" -a" EXTRA_LDFLAGS=" ${ldflags} " static
56- rm -rf " $prefix "
101+ local make_args=(COMMIT_NO= EXTRA_FLAGS=" -a" EXTRA_LDFLAGS=" ${ldflags} " static)
102+
103+ # Build natively.
104+ make -C " $root " PKG_CONFIG_PATH=" ${LIBSECCOMP_PREFIX} /lib/pkgconfig" " ${make_args[@]} "
57105 strip " $root /$project "
58- mv " $root /$project " " $1 "
106+ mv " $root /$project " " $builddir /$project .$native_arch "
107+ rm -rf " ${LIBSECCOMP_PREFIX} "
108+
109+ # Cross-build for for other architectures.
110+ local prefix arch
111+ for arch in " $@ " ; do
112+ setHOST " $arch "
113+ eval prefix=\$ " LIBSECCOMP_PREFIX_$arch "
114+ GOARCH=$arch CC=$HOST -gcc make -C " $root " \
115+ PKG_CONFIG_PATH=" ${prefix} /lib/pkgconfig" " ${make_args[@]} "
116+ " $HOST -strip" " $root /$project "
117+ mv " $root /$project " " $builddir /$project .$arch "
118+ rm -rf " $prefix "
119+ done
59120}
60121
61122# End of the easy-to-configure portion.
@@ -122,7 +183,11 @@ done
122183version=" ${version:- $(<" $root /VERSION" )} "
123184releasedir=" ${releasedir:- release/ $version } "
124185hashcmd=" ${hashcmd:- sha256sum} "
125- goarch=" $( go env GOARCH || echo " amd64" ) "
186+ native_arch=" $( go env GOARCH || echo " amd64" ) "
187+ # Also build for amd64.
188+ add_arches=(" arm64" )
189+ # Suffixes of files to checksum/sign.
190+ suffixes=(" $native_arch " " ${add_arches[@]} " tar.xz)
126191
127192log " creating $project release in '$releasedir '"
128193log " version: $version "
@@ -137,15 +202,15 @@ set -x
137202rm -rf " $releasedir " && mkdir -p " $releasedir "
138203
139204# Build project.
140- build_project " $releasedir /$project . $goarch "
205+ build_project " $releasedir /$project " " ${add_arches[@]} "
141206
142207# Generate new archive.
143208git archive --format=tar --prefix=" $project -$version /" " $commit " | xz > " $releasedir /$project .tar.xz"
144209
145- # Generate sha256 checksums for both .
210+ # Generate sha256 checksums for binaries and libseccomp tarball .
146211(
147212 cd " $releasedir "
148- " $hashcmd " " $project " .{ " $goarch " ,tar.xz} > " $project .$hashcmd "
213+ " $hashcmd " " ${suffixes[@] /#/ $project } " > " $project .$hashcmd "
149214)
150215
151216# Set up the gpgflags.
@@ -154,8 +219,9 @@ gpgflags=()
154219gpg_cansign " ${gpgflags[@]} " || bail " Could not find suitable GPG key, skipping signing step."
155220
156221# Sign everything.
157- gpg " ${gpgflags[@]} " --detach-sign --armor " $releasedir /$project .$goarch "
158- gpg " ${gpgflags[@]} " --detach-sign --armor " $releasedir /$project .tar.xz"
222+ for sfx in " ${suffixes[@]} " ; do
223+ gpg " ${gpgflags[@]} " --detach-sign --armor " $releasedir /$project .$sfx "
224+ done
159225gpg " ${gpgflags[@]} " --clear-sign --armor \
160226 --output " $releasedir /$project .$hashcmd " {.tmp,} &&
161227 mv " $releasedir /$project .$hashcmd " {.tmp,}
0 commit comments