From 8359cbe76c603505c1fa14c937c288dfff64f541 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 5 Mar 2025 02:18:49 +0300 Subject: [PATCH] scripts: waifulib: add flag --enable-limited-debuginfo which enables -gline-tables-only on GCC and Clang compilers This saves ~30mb of APK size on Android. --- android/app/CMakeLists.txt | 4 ++-- scripts/waifulib/compiler_optimizations.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/android/app/CMakeLists.txt b/android/app/CMakeLists.txt index 7a24c54c..77f01d81 100644 --- a/android/app/CMakeLists.txt +++ b/android/app/CMakeLists.txt @@ -17,7 +17,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set(BUILD_TYPE "debug") else() set(BUILD_TYPE "release") - list(APPEND WAF_EXTRA_ARGS --enable-poly-opt --enable-lto) + list(APPEND WAF_EXTRA_ARGS --enable-poly-opt --enable-lto --enable-limited-debuginfo) endif() if(ANDROID_ABI STREQUAL "x86") @@ -75,7 +75,7 @@ ExternalProject_Add( BUILD_CMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} WAFLOCK=.lock-waf_android_${ANDROID_ABI}_build ${WAF} configure -T ${BUILD_TYPE} --android=${ANDROID_ABI},,${CMAKE_SYSTEM_VERSION} - -s "${ENGINE_SOURCE_DIR}/3rdparty/SDL" --enable-bundled-deps + -s "${ENGINE_SOURCE_DIR}/3rdparty/SDL" --enable-bundled-deps ${WAF_EXTRA_ARGS} BUILD_COMMAND ${CMAKE_COMMAND} -E env WAFLOCK=.lock-waf_android_${ANDROID_ABI}_build diff --git a/scripts/waifulib/compiler_optimizations.py b/scripts/waifulib/compiler_optimizations.py index c3fb9990..308c41fe 100644 --- a/scripts/waifulib/compiler_optimizations.py +++ b/scripts/waifulib/compiler_optimizations.py @@ -177,6 +177,9 @@ def options(opt): grp.add_option('--enable-profile', action = 'store_true', dest = 'PROFILE_GENERATE', default = False, help = 'enable profile generating build (stored in xash3d-prof directory) [default: %(default)s]') + grp.add_option('--enable-limited-debuginfo', action = 'store_true', dest = 'LIMITED_DEBUGINFO', default = False, + help = 'only save line debuginfo, useful for release builds [default: %(default)s]') + grp.add_option('--use-profile', action = 'store', dest = 'PROFILE_USE', default = None, help = 'use profile during build [default: %(default)s]') @@ -254,7 +257,14 @@ def get_optimization_flags(conf): # this port don't have stack printing support cflags.remove('-fasynchronous-unwind-tables') - if conf.env.COMPILER_CC == 'gcc' or conf.env.COMPILER_CC == 'clang' and conf.env.DEST_OS not in ['android']: + if conf.env.COMPILER_CC in ['gcc', 'clang'] and conf.options.LIMITED_DEBUGINFO: + # probably not a good idea to do this, but it should save space on Android builds especially + # that are never going to be run under debugger, but we still want that readable fileline + # info in backtraces + # might enable this for release/fast/fastnative builds in the future + cflags = ['-gline-tables-only' if flag.startswith('-g') else flag for flag in cflags] + + if conf.env.COMPILER_CC in ['gcc', 'clang'] and conf.env.DEST_OS not in ['android']: # HLSDK by default compiles with these options under Linux # no reason for us to not do the same