k3s/scripts/binary_size_check.sh
Silvio Moioli dbc7c72416
Disable optimizations and symbol stripping on debug builds (#6147)
Signed-off-by: Silvio Moioli <silvio@moioli.net>
Co-authored-by: Brad Davidson <brad@oatmail.org>
2022-10-28 09:17:49 -07:00

39 lines
903 B
Bash
Executable File

#!/bin/bash
set -e
if [ "${DEBUG}" = 1 ]; then
set -x
fi
. ./scripts/version.sh
# Try to keep the K3s binary under 70 megabytes.
# "64M ought to be enough for anybody"
MAX_BINARY_MB=70
MAX_BINARY_SIZE=$((MAX_BINARY_MB * 1024 * 1024))
BIN_SUFFIX="-${ARCH}"
if [ ${ARCH} = amd64 ]; then
BIN_SUFFIX=""
elif [ ${ARCH} = arm ]; then
BIN_SUFFIX="-armhf"
elif [ ${ARCH} = s390x ]; then
BIN_SUFFIX="-s390x"
fi
CMD_NAME="dist/artifacts/k3s${BIN_SUFFIX}"
SIZE=$(stat -c '%s' ${CMD_NAME})
if [ -n "${DEBUG}" ]; then
echo "DEBUG is set, ignoring binary size"
exit 0
fi
if [ ${SIZE} -gt ${MAX_BINARY_SIZE} ]; then
echo "k3s binary ${CMD_NAME} size ${SIZE} exceeds max acceptable size of ${MAX_BINARY_SIZE} bytes (${MAX_BINARY_MB} MiB)"
exit 1
fi
echo "k3s binary ${CMD_NAME} size ${SIZE} is less than max acceptable size of ${MAX_BINARY_SIZE} bytes (${MAX_BINARY_MB} MiB)"
exit 0