From 581a811256cc33d300b5f8e0e3a1e1ae2fe17756 Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Fri, 2 Aug 2024 15:52:58 +0800 Subject: [PATCH] chore(CI): Reduce the target size when build on GitHub actions (#2086) The GitHub action runners for free plan is very limit, it's easy to exceed the disk space. This patch adds some build and link flags to reduce the target size to ensure the actions can be completed without disk exhaust issues. Now the release packge is reduced from about 2,600,468,480 bytes to 686,325,578 bytes, and the ASAN package can be built completly now. --- cmake_modules/BaseFunctions.cmake | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmake_modules/BaseFunctions.cmake b/cmake_modules/BaseFunctions.cmake index 33c819fbb5..9b784dc441 100644 --- a/cmake_modules/BaseFunctions.cmake +++ b/cmake_modules/BaseFunctions.cmake @@ -193,12 +193,20 @@ endfunction() function(dsn_setup_compiler_flags) if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-DDSN_BUILD_TYPE=Debug) - add_definitions(-g) else() - add_definitions(-g) add_definitions(-O2) add_definitions(-DDSN_BUILD_TYPE=Release) endif() + + if("$ENV{GITHUB_ACTION}" STREQUAL "" OR APPLE) + add_definitions(-g) + else() + # Reduce the target size when build on GitHub actions and non-macOS. + message(WARNING "Running GitHub actions, the target size will be reduced!") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s -Wl,--gc-sections") + endif() + cmake_host_system_information(RESULT BUILD_HOSTNAME QUERY HOSTNAME) add_definitions(-DDSN_BUILD_HOSTNAME=${BUILD_HOSTNAME})