Skip to content

Commit 581a811

Browse files
authored
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.
1 parent 097068d commit 581a811

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cmake_modules/BaseFunctions.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,20 @@ endfunction()
193193
function(dsn_setup_compiler_flags)
194194
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
195195
add_definitions(-DDSN_BUILD_TYPE=Debug)
196-
add_definitions(-g)
197196
else()
198-
add_definitions(-g)
199197
add_definitions(-O2)
200198
add_definitions(-DDSN_BUILD_TYPE=Release)
201199
endif()
200+
201+
if("$ENV{GITHUB_ACTION}" STREQUAL "" OR APPLE)
202+
add_definitions(-g)
203+
else()
204+
# Reduce the target size when build on GitHub actions and non-macOS.
205+
message(WARNING "Running GitHub actions, the target size will be reduced!")
206+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables")
207+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s -Wl,--gc-sections")
208+
endif()
209+
202210
cmake_host_system_information(RESULT BUILD_HOSTNAME QUERY HOSTNAME)
203211
add_definitions(-DDSN_BUILD_HOSTNAME=${BUILD_HOSTNAME})
204212

0 commit comments

Comments
 (0)