build: add size-optimized release build

This commit is contained in:
Marcus Holland-Moritz 2025-03-22 17:08:47 +01:00
parent b082fcb4d9
commit cb883f6df4
3 changed files with 23 additions and 1 deletions

View File

@ -121,6 +121,13 @@ case "-$BUILD_TYPE-" in
CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=Release" CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=Release"
CMAKE_ARGS="${CMAKE_ARGS} -DWITH_BENCHMARKS=1" CMAKE_ARGS="${CMAKE_ARGS} -DWITH_BENCHMARKS=1"
;; ;;
*-relsize-*)
CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=MinSizeRel"
CMAKE_ARGS="${CMAKE_ARGS} -DWITH_BENCHMARKS=1"
export CFLAGS="-ffunction-sections -fdata-sections -fvisibility=hidden -fmerge-all-constants"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-Wl,--gc-sections"
;;
*-reldbg-*) *-reldbg-*)
CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo" CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo"
;; ;;
@ -296,7 +303,10 @@ else
$RUN_TESTS $RUN_TESTS
fi fi
fi
# for release and resize builds, strip the binaries
if [[ "-$BUILD_TYPE-" =~ -(release|relsize)- ]]; then
$BUILD_TOOL strip $BUILD_TOOL strip
fi fi

View File

@ -332,6 +332,18 @@ jobs:
- arch: arm64v8 - arch: arm64v8
dist: alpine dist: alpine
build_type: clang-release-ninja-static build_type: clang-release-ninja-static
- arch: amd64
dist: alpine
build_type: gcc-relsize-ninja-static
- arch: arm64v8
dist: alpine
build_type: gcc-relsize-ninja-static
- arch: amd64
dist: alpine
build_type: clang-relsize-ninja-static
- arch: arm64v8
dist: alpine
build_type: clang-relsize-ninja-static
- arch: amd64 - arch: amd64
dist: alpine dist: alpine
build_type: clang-reldbg-stacktrace-ninja-static build_type: clang-reldbg-stacktrace-ninja-static

View File

@ -920,7 +920,7 @@ add_custom_target(
USES_TERMINAL) USES_TERMINAL)
if(STATIC_BUILD_DO_NOT_USE OR APPLE) if(STATIC_BUILD_DO_NOT_USE OR APPLE)
if(CMAKE_BUILD_TYPE STREQUAL "Release") if(CMAKE_BUILD_TYPE MATCHES "Release|MinSizeRel")
foreach(tgt ${BINARY_TARGETS}) foreach(tgt ${BINARY_TARGETS})
list(APPEND FILES_TO_STRIP $<TARGET_FILE:${tgt}>) list(APPEND FILES_TO_STRIP $<TARGET_FILE:${tgt}>)
endforeach() endforeach()