Skip to content

Commit 321aa20

Browse files
committed
scripts: add proper 386 and amd64 target triples and builds
We need these to match the Makefile detection of the right gcc for runc-dmz, as well as making sure that everything builds properly for our cross-i386 tests. While we're at it, add x86 to the list of build targets for release builds (presumably nobody will use it, but since we do test builds of this anyway it probably won't hurt). In addition, clean up the handling of the native architecture build by treating it the same as any other build (ensuring that building runc from a different platform will work the same way regardless of the native architecture). In practice, the build works the same way as before. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 1d9b158 commit 321aa20

File tree

5 files changed

+83
-40
lines changed

5 files changed

+83
-40
lines changed

Dockerfile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ ARG CRIU_REPO=https://download.opensuse.org/repositories/devel:/tools:/criu/Debi
99
RUN KEYFILE=/usr/share/keyrings/criu-repo-keyring.gpg; \
1010
wget -nv $CRIU_REPO/Release.key -O- | gpg --dearmor > "$KEYFILE" \
1111
&& echo "deb [signed-by=$KEYFILE] $CRIU_REPO/ /" > /etc/apt/sources.list.d/criu.list \
12+
&& dpkg --add-architecture i386 \
1213
&& apt-get update \
1314
&& apt-get install -y --no-install-recommends \
1415
build-essential \
1516
criu \
16-
gcc-aarch64-linux-gnu libc-dev-arm64-cross \
17-
gcc-arm-linux-gnueabi libc-dev-armel-cross \
18-
gcc-arm-linux-gnueabihf libc-dev-armhf-cross \
19-
gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross \
20-
gcc-s390x-linux-gnu libc-dev-s390x-cross \
21-
gcc-riscv64-linux-gnu libc-dev-riscv64-cross \
17+
gcc \
18+
gcc-multilib \
2219
curl \
2320
gawk \
24-
gcc \
2521
gperf \
2622
iptables \
2723
jq \
@@ -32,6 +28,14 @@ RUN KEYFILE=/usr/share/keyrings/criu-repo-keyring.gpg; \
3228
sudo \
3329
uidmap \
3430
iproute2 \
31+
&& apt-get install -y --no-install-recommends \
32+
libc-dev:i386 libgcc-s1:i386 \
33+
gcc-aarch64-linux-gnu libc-dev-arm64-cross \
34+
gcc-arm-linux-gnueabi libc-dev-armel-cross \
35+
gcc-arm-linux-gnueabihf libc-dev-armhf-cross \
36+
gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross \
37+
gcc-s390x-linux-gnu libc-dev-s390x-cross \
38+
gcc-riscv64-linux-gnu libc-dev-riscv64-cross \
3539
&& apt-get clean \
3640
&& rm -rf /var/cache/apt /var/lib/apt/lists/* /etc/apt/sources.list.d/*.list
3741

@@ -54,7 +58,7 @@ RUN cd /tmp \
5458
ARG LIBSECCOMP_VERSION
5559
COPY script/seccomp.sh script/lib.sh /tmp/script/
5660
RUN mkdir -p /opt/libseccomp \
57-
&& /tmp/script/seccomp.sh "$LIBSECCOMP_VERSION" /opt/libseccomp arm64 armel armhf ppc64le riscv64 s390x
61+
&& /tmp/script/seccomp.sh "$LIBSECCOMP_VERSION" /opt/libseccomp 386 amd64 arm64 armel armhf ppc64le riscv64 s390x
5862
ENV LIBSECCOMP_VERSION=$LIBSECCOMP_VERSION
5963
ENV LD_LIBRARY_PATH=/opt/libseccomp/lib
6064
ENV PKG_CONFIG_PATH=/opt/libseccomp/lib/pkgconfig

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ recvtty sd-helper seccompagent fs-idmap:
6868
static:
6969
$(GO_BUILD_STATIC) -o runc .
7070

71-
releaseall: RELEASE_ARGS := "-a arm64 -a armel -a armhf -a ppc64le -a riscv64 -a s390x"
71+
releaseall: RELEASE_ARGS := "-a 386 -a amd64 -a arm64 -a armel -a armhf -a ppc64le -a riscv64 -a s390x"
7272
releaseall: release
7373

7474
release: runcimage

script/lib.sh

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,74 @@
11
#!/bin/bash
22

3+
# NOTE: Make sure you keep this file in sync with cc_platform.mk.
4+
35
# set_cross_vars sets a few environment variables used for cross-compiling,
46
# based on the architecture specified in $1.
57
function set_cross_vars() {
68
GOARCH="$1" # default, may be overridden below
79
unset GOARM
810

11+
PLATFORM=linux-gnu
12+
# openSUSE has a custom PLATFORM
13+
if grep -iq "ID_LIKE=.*suse" /etc/os-release; then
14+
PLATFORM=suse-linux
15+
is_suse=1
16+
fi
17+
918
case $1 in
19+
386)
20+
# Always use the 64-bit compiler to build the 386 binary, which works
21+
# for the more common cross-build method for x86 (namely, the
22+
# equivalent of dpkg --add-architecture).
23+
local cpu_type
24+
if [ -v is_suse ]; then
25+
# There is no x86_64-suse-linux-gcc, so use the native one.
26+
HOST=
27+
cpu_type=i586
28+
else
29+
HOST=x86_64-${PLATFORM}
30+
cpu_type=i686
31+
fi
32+
CFLAGS="-m32 -march=$cpu_type ${CFLAGS[*]}"
33+
;;
34+
amd64)
35+
if [ -n "${is_suse:-}" ]; then
36+
# There is no x86_64-suse-linux-gcc, so use the native one.
37+
HOST=
38+
else
39+
HOST=x86_64-${PLATFORM}
40+
fi
41+
;;
1042
arm64)
11-
HOST=aarch64-linux-gnu
43+
HOST=aarch64-${PLATFORM}
1244
;;
1345
armel)
14-
HOST=arm-linux-gnueabi
46+
HOST=arm-${PLATFORM}eabi
1547
GOARCH=arm
1648
GOARM=6
1749
;;
1850
armhf)
19-
HOST=arm-linux-gnueabihf
51+
HOST=arm-${PLATFORM}eabihf
2052
GOARCH=arm
2153
GOARM=7
2254
;;
2355
ppc64le)
24-
HOST=powerpc64le-linux-gnu
56+
HOST=powerpc64le-${PLATFORM}
2557
;;
2658
riscv64)
27-
HOST=riscv64-linux-gnu
59+
HOST=riscv64-${PLATFORM}
2860
;;
2961
s390x)
30-
HOST=s390x-linux-gnu
62+
HOST=s390x-${PLATFORM}
3163
;;
3264
*)
3365
echo "set_cross_vars: unsupported architecture: $1" >&2
3466
exit 1
3567
;;
3668
esac
3769

38-
CC=$HOST-gcc
39-
STRIP=$HOST-strip
70+
CC="${HOST:+$HOST-}gcc"
71+
STRIP="${HOST:+$HOST-}strip"
4072

41-
export HOST GOARM GOARCH CC STRIP
73+
export HOST CFLAGS GOARM GOARCH CC STRIP
4274
}

script/release_build.sh

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,14 @@ function build_project() {
6060
# it can reuse cached pkg-config results).
6161
local make_args=(COMMIT_NO= EXTRA_FLAGS="-a" EXTRA_LDFLAGS="${ldflags}" static)
6262

63-
# Build natively.
64-
make -C "$root" \
65-
PKG_CONFIG_PATH="$seccompdir/lib/pkgconfig" \
66-
"${make_args[@]}"
67-
strip "$root/$project"
68-
# Sanity check: make sure libseccomp version is as expected.
69-
local ver
70-
ver=$("$root/$project" --version | awk '$1 == "libseccomp:" {print $2}')
71-
if [ "$ver" != "$LIBSECCOMP_VERSION" ]; then
72-
echo >&2 "libseccomp version mismatch: want $LIBSECCOMP_VERSION, got $ver"
73-
exit 1
74-
fi
63+
# Save the original cflags.
64+
local original_cflags="${CFLAGS:-}"
7565

76-
mv "$root/$project" "$builddir/$project.$native_arch"
77-
78-
# Cross-build for for other architectures.
66+
# Build for all requested architectures.
7967
local arch
8068
for arch in "${arches[@]}"; do
69+
# Reset CFLAGS.
70+
CFLAGS="$original_cflags"
8171
set_cross_vars "$arch"
8272
make -C "$root" \
8373
PKG_CONFIG_PATH="$seccompdir/$arch/lib/pkgconfig" \
@@ -86,6 +76,14 @@ function build_project() {
8676
mv "$root/$project" "$builddir/$project.$arch"
8777
done
8878

79+
# Sanity check: make sure libseccomp version is as expected.
80+
local ver
81+
ver=$("$builddir/$project.$native_arch" --version | awk '$1 == "libseccomp:" {print $2}')
82+
if [ "$ver" != "$LIBSECCOMP_VERSION" ]; then
83+
echo >&2 "libseccomp version mismatch: want $LIBSECCOMP_VERSION, got $ver"
84+
exit 1
85+
fi
86+
8987
# Copy libseccomp source tarball.
9088
cp "$seccompdir"/src/* "$builddir"
9189

@@ -122,12 +120,17 @@ commit="HEAD"
122120
version=""
123121
releasedir=""
124122
hashcmd=""
125-
declare -a add_arches
123+
# Always build a native binary.
124+
native_arch="$(go env GOARCH || echo "amd64")"
125+
arches=("$native_arch")
126126

127127
while getopts "a:c:H:hr:v:" opt; do
128128
case "$opt" in
129129
a)
130-
add_arches+=("$OPTARG")
130+
# Add architecture if not already present in arches.
131+
if ! (printf "%s\0" "${arches[@]}" | grep -zqxF "$OPTARG"); then
132+
arches+=("$OPTARG")
133+
fi
131134
;;
132135
c)
133136
commit="$OPTARG"
@@ -158,9 +161,8 @@ done
158161
version="${version:-$(<"$root/VERSION")}"
159162
releasedir="${releasedir:-release/$version}"
160163
hashcmd="${hashcmd:-sha256sum}"
161-
native_arch="$(go env GOARCH || echo "amd64")"
162164
# Suffixes of files to checksum/sign.
163-
suffixes=("$native_arch" "${add_arches[@]}" tar.xz)
165+
suffixes=("${arches[@]}" tar.xz)
164166

165167
log "creating $project release in '$releasedir'"
166168
log " version: $version"
@@ -174,7 +176,7 @@ set -x
174176
rm -rf "$releasedir" && mkdir -p "$releasedir"
175177

176178
# Build project.
177-
build_project "$releasedir/$project" "$native_arch" "${add_arches[@]}"
179+
build_project "$releasedir/$project" "$native_arch" "${arches[@]}"
178180

179181
# Generate new archive.
180182
git archive --format=tar --prefix="$project-$version/" "$commit" | xz >"$releasedir/$project.tar.xz"

script/seccomp.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,21 @@ function build_libseccomp() {
3333
tar xf "$tar" -C "$srcdir"
3434
pushd "$srcdir/libseccomp-$ver" || return
3535

36-
# Build natively and install to /usr/local.
36+
# Install native version for Dockerfile builds.
3737
./configure \
3838
--prefix="$dest" --libdir="$dest/lib" \
3939
--enable-static --enable-shared
4040
make install
4141
make clean
4242

43-
# Build and install for additional architectures.
43+
# Save the original cflags.
44+
local original_cflags="${CFLAGS:-}"
45+
46+
# Build and install for all requested architectures.
4447
local arch
4548
for arch in "${arches[@]}"; do
49+
# Reset CFLAGS.
50+
CFLAGS="$original_cflags"
4651
set_cross_vars "$arch"
4752
./configure --host "$HOST" \
4853
--prefix="$dest/$arch" --libdir="$dest/$arch/lib" \

0 commit comments

Comments
 (0)