Skip to content

Commit

Permalink
feat cmake: implement -gz=zstd
Browse files Browse the repository at this point in the history
Before:

```
build_debug$ ls -lh samples/hello_service/userver-samples-hello_service
-rwxrwxr-x 1 segoon segoon 78M Jan 28 19:32 samples/hello_service/userver-samples-hello_service
```

After:

```
build_debug$ ls -lh samples/hello_service/userver-samples-hello_service
-rwxrwxr-x 1 segoon segoon 37M Jan 28 19:20 samples/hello_service/userver-samples-hello_service
```
commit_hash:d09e127fadf845e60d1f4be0e59879148a1ac1f5
  • Loading branch information
segoon committed Jan 31, 2025
1 parent d47b4ed commit 475898e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@
"cmake/SetupCURL.cmake":"taxi/uservices/userver/cmake/SetupCURL.cmake",
"cmake/SetupClickhouseCPP.cmake":"taxi/uservices/userver/cmake/SetupClickhouseCPP.cmake",
"cmake/SetupCryptoPP.cmake":"taxi/uservices/userver/cmake/SetupCryptoPP.cmake",
"cmake/SetupDebugInfoCompression.cmake":"taxi/uservices/userver/cmake/SetupDebugInfoCompression.cmake",
"cmake/SetupFmt.cmake":"taxi/uservices/userver/cmake/SetupFmt.cmake",
"cmake/SetupGBench.cmake":"taxi/uservices/userver/cmake/SetupGBench.cmake",
"cmake/SetupGTest.cmake":"taxi/uservices/userver/cmake/SetupGTest.cmake",
Expand Down
38 changes: 38 additions & 0 deletions cmake/SetupDebugInfoCompression.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function(setup_linker_debug_info_compression)
write_file("${CMAKE_CURRENT_BINARY_DIR}/empty.cpp" "int main() {return 0;}")
try_compile(LINKER_HAS_ZSTD ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/empty.cpp
LINK_OPTIONS -Werror -gz=zstd
)
if (NOT LINKER_HAS_ZSTD)
try_compile(LINKER_HAS_GZ ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/empty.cpp
LINK_OPTIONS -Werror -gz
)
endif()

if(LINKER_HAS_ZSTD)
message(STATUS "Using linker debug info compression: zstd")
add_link_options("-gz=zstd")
elseif(LINKER_HAS_GZ)
message(STATUS "Using linker debug info compression: z")
add_link_options("-gz")
else()
message(STATUS "Using linker debug info compression: none")
endif()
endfunction()

function(setup_compiler_debug_info_compression)
userver_is_cxx_compile_option_supported(COMPILER_HAS_ZSTD "-gz=zstd")

if(COMPILER_HAS_ZSTD)
message(STATUS "Using compiler debug info compression: zstd")
add_compile_options("-gz=zstd")
else()
message(STATUS "Using compiler debug info compression: z")
add_compile_options("-gz")
endif()
endfunction()

setup_linker_debug_info_compression()
setup_compiler_debug_info_compression()
4 changes: 3 additions & 1 deletion cmake/UserverSetupEnvironment.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function(_userver_setup_environment_impl)
set(CMAKE_CXX_EXTENSIONS OFF PARENT_SCOPE)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON PARENT_SCOPE)

add_compile_options("-pipe" "-g" "-gz" "-fPIC")
add_compile_options("-pipe" "-g" "-fPIC")
add_compile_definitions("PIC=1")

option(USERVER_COMPILATION_TIME_TRACE "Generate Clang compilation time trace" OFF)
Expand All @@ -63,6 +63,8 @@ function(_userver_setup_environment_impl)
include("${USERVER_CMAKE_DIR}/SetupLinker.cmake")
include("${USERVER_CMAKE_DIR}/SetupLTO.cmake")
include("${USERVER_CMAKE_DIR}/SetupPGO.cmake")
include("${USERVER_CMAKE_DIR}/UserverCxxCompileOptionsIfSupported.cmake")
include("${USERVER_CMAKE_DIR}/SetupDebugInfoCompression.cmake")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" PARENT_SCOPE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" PARENT_SCOPE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION "${CMAKE_INTERPROCEDURAL_OPTIMIZATION}" PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions universal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,10 @@ _userver_directory_install(COMPONENT universal FILES
"${USERVER_ROOT_DIR}/cmake/SetupLTO.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupPGO.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupLinker.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupDebugInfoCompression.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupHomebrew.cmake"
"${USERVER_ROOT_DIR}/cmake/Sanitizers.cmake"
"${USERVER_ROOT_DIR}/cmake/UserverCxxCompileOptionsIfSupported.cmake"
"${USERVER_ROOT_DIR}/cmake/AddGoogleTests.cmake"
"${USERVER_ROOT_DIR}/cmake/DetectVersion.cmake"
"${USERVER_ROOT_DIR}/cmake/UserverSetupEnvironment.cmake"
Expand Down

0 comments on commit 475898e

Please sign in to comment.