Skip to content

Commit f1be556

Browse files
committed
script/release.sh: add arm64 cross-build
Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent af5105b commit f1be556

File tree

2 files changed

+93
-26
lines changed

2 files changed

+93
-26
lines changed

.github/workflows/validate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ jobs:
172172
- name: install deps
173173
run: |
174174
sudo apt -qq update
175-
sudo apt -qq install gperf
175+
sudo apt -qq install gperf gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
176176
- name: make release
177177
run: make release
178178
- name: upload artifacts

script/release.sh

Lines changed: 92 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,74 @@ set -e
2121
project="runc"
2222
root="$(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.
2686
function 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
122183
version="${version:-$(<"$root/VERSION")}"
123184
releasedir="${releasedir:-release/$version}"
124185
hashcmd="${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

127192
log "creating $project release in '$releasedir'"
128193
log " version: $version"
@@ -137,15 +202,16 @@ set -x
137202
rm -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.
143208
git 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+
# Add $project. prefix to all suffixes.
214+
"$hashcmd" "${suffixes[@]/#/$project.}" >"$project.$hashcmd"
149215
)
150216

151217
# Set up the gpgflags.
@@ -154,8 +220,9 @@ gpgflags=()
154220
gpg_cansign "${gpgflags[@]}" || bail "Could not find suitable GPG key, skipping signing step."
155221

156222
# Sign everything.
157-
gpg "${gpgflags[@]}" --detach-sign --armor "$releasedir/$project.$goarch"
158-
gpg "${gpgflags[@]}" --detach-sign --armor "$releasedir/$project.tar.xz"
223+
for sfx in "${suffixes[@]}"; do
224+
gpg "${gpgflags[@]}" --detach-sign --armor "$releasedir/$project.$sfx"
225+
done
159226
gpg "${gpgflags[@]}" --clear-sign --armor \
160227
--output "$releasedir/$project.$hashcmd"{.tmp,} &&
161228
mv "$releasedir/$project.$hashcmd"{.tmp,}

0 commit comments

Comments
 (0)