Make handling of cross-platform emulation for static builds smarter. (#19470)
* Switch to tonistiigi/binfmt for cross-build emulation. It’s actually being actively updated, and it also supports hosts other than x86-64. * Auto-detect existing QEMU user emulation in static build. Instead of relying on the user to explicitly ask for no emulation.
Austin S. Hemmelgarn committed
Jan 28, 2025 at 09:54 UTC
f5da1f0bf3fe74e86f580dda25ebc08d1247189e
1 file changed
+13
-11
packaging/makeself/build-static.sh
+13
-11
@@ -24,45 +24,47 @@ else
24
exit 1
25
fi
26
27
-DOCKER_IMAGE_NAME="netdata/static-builder:v1"
28
-
29
-if [ "${BUILDARCH}" != "$(uname -m)" ] && [ -z "${SKIP_EMULATION}" ]; then
30
- if [ "$(uname -m)" = "x86_64" ]; then
31
- ${docker} run --rm --privileged multiarch/qemu-user-static --reset -p yes || exit 1
32
- else
33
- echo "Automatic cross-architecture builds are only supported on x86_64 hosts."
34
- exit 1
35
- fi
36
-fi
37
-
27
case "${BUILDARCH}" in
28
x86_64) # x86-64-v2 equivalent
29
+ QEMU_ARCH="x86_64"
30
QEMU_CPU="Nehalem-v2"
31
TUNING_FLAGS="-march=x86-64"
32
GOAMD64="v1"
33
;;
34
armv6l) # Raspberry Pi 1 equivalent
35
+ QEMU_ARCH="arm"
36
QEMU_CPU="arm1176"
37
TUNING_FLAGS="-march=armv6zk -mtune=arm1176jzf-s"
38
GOARM="6"
39
;;
40
armv7l) # Baseline ARMv7 CPU
41
+ QEMU_ARCH="arm"
42
QEMU_CPU="cortex-a7"
43
TUNING_FLAGS="-march=armv7-a"
44
GOARM="7"
45
;;
46
aarch64) # Baseline ARMv8 CPU
47
+ QEMU_ARCH="aarch64"
48
QEMU_CPU="cortex-a53"
49
TUNING_FLAGS="-march=armv8-a"
50
GOARM64="v8.0"
51
;;
52
ppc64le) # Baseline POWER8+ CPU
53
+ QEMU_ARCH="ppc64le"
54
QEMU_CPU="power8nvl"
55
TUNING_FLAGS="-mcpu=power8 -mtune=power9"
56
GOPPC64="power8"
57
;;
58
esac
59
60
+[ -f "/proc/sys/fs/binfmt_misc/qemu-${QEMU_ARCH}" ] && SKIP_EMULATION=1
61
+
62
+if [ "${BUILDARCH}" != "$(uname -m)" ] && [ -z "${SKIP_EMULATION}" ]; then
63
+ ${docker} run --rm --privileged tonistiigi/binfmt:master --install "${QEMU_ARCH}" || exit 1
64
+fi
65
+
66
+DOCKER_IMAGE_NAME="netdata/static-builder:v1"
67
+
68
if ${docker} inspect "${DOCKER_IMAGE_NAME}" > /dev/null 2>&1; then
69
if ${docker} image inspect "${DOCKER_IMAGE_NAME}" | grep -q 'Variant'; then
70
img_platform="$(${docker} image inspect "${DOCKER_IMAGE_NAME}" --format '{{.Os}}/{{.Architecture}}/{{.Variant}}')"