Skip to content

Commit

Permalink
Emit debug info for Release builds (shader-slang#5783)
Browse files Browse the repository at this point in the history
* Remove unnecessary warnings on windows

* Correctly set debug flags on gcc

* Emit debug info for Release builds

* Perform LTO for relwithdebinfo builds

* Release from release builds not relwithdebinfo
  • Loading branch information
expipiplus1 authored Dec 6, 2024
1 parent 8ce7c6f commit 27b7ac0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 71 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/release-linux-glibc-2-17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:
cd /home/app
git config --global --add safe.directory /home/app
cmake --preset default --fresh -DSLANG_SLANG_LLVM_FLAVOR=DISABLE
cmake --build --preset releaseWithDebugInfo
cpack --preset releaseWithDebugInfo -G ZIP
cpack --preset releaseWithDebugInfo -G TGZ
cmake --build --preset release
cpack --preset release -G ZIP
cpack --preset release -G TGZ
- name: Package Slang
id: package
Expand All @@ -38,15 +38,15 @@ jobs:
version=${triggering_ref#v}
base=$(pwd)/slang-${version}-linux-x86_64-glibc-2.17
sudo mv "$(pwd)/build/dist-releaseWithDebugInfo/slang.zip" "${base}.zip"
sudo mv "$(pwd)/build/dist-release/slang.zip" "${base}.zip"
echo "SLANG_BINARY_ARCHIVE_ZIP=${base}.zip" >> "$GITHUB_OUTPUT"
sudo mv "$(pwd)/build/dist-releaseWithDebugInfo/slang.tar.gz" "${base}.tar.gz"
sudo mv "$(pwd)/build/dist-release/slang.tar.gz" "${base}.tar.gz"
echo "SLANG_BINARY_ARCHIVE_TAR=${base}.tar.gz" >> "$GITHUB_OUTPUT"
- name: File check
run: |
find "build/dist-releaseWithDebugInfo" -print0 ! -iname '*.md' ! -iname '*.h' -type f | xargs -0 file
find "build/dist-release" -print0 ! -iname '*.md' ! -iname '*.h' -type f | xargs -0 file
- name: UploadBinary
uses: softprops/action-gh-release@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
os: [linux, macos, windows]
config: [releaseWithDebugInfo]
config: [release]
platform: [x86_64, aarch64]
test-category: [smoke]
include:
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ enum_option(
"Build slang as a static library"
)

option(
SLANG_ENABLE_RELEASE_DEBUG_INFO
"Generate debug info for Release builds"
ON
)

option(
SLANG_ENABLE_SPLIT_DEBUG_INFO
"Generate split debug info for debug builds"
Expand Down
86 changes: 22 additions & 64 deletions cmake/SlangTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ function(slang_add_target dir type)
# See: https://cmake.org/cmake/help/latest/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html
set_target_properties(
${target}
PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE
)

#
Expand Down Expand Up @@ -200,12 +202,26 @@ function(slang_add_target dir type)
PDB_OUTPUT_DIRECTORY "${output_dir}/${runtime_subdir}"
)

if(NOT MSVC)
set_target_properties(
set(debug_configs "Debug,RelWithDebInfo")
if(SLANG_ENABLE_RELEASE_DEBUG_INFO)
set(debug_configs "Debug,RelWithDebInfo,Release")
endif()

set_target_properties(
${target}
PROPERTIES
MSVC_DEBUG_INFORMATION_FORMAT
"$<$<CONFIG:${debug_configs}>:Embedded>"
)
if(MSVC)
target_link_options(
${target}
PRIVATE "$<$<CONFIG:${debug_configs}>:/DEBUG>"
)
else()
target_compile_options(
${target}
PROPERTIES
COMPILE_OPTIONS
"$<$<CONFIG:Debug,RelWithDebInfo>:-fdebug-prefix-map=${CMAKE_CURRENT_BINARY_DIR}=${output_dir}>"
PRIVATE "$<$<CONFIG:${debug_configs}>:-g>"
)
endif()

Expand Down Expand Up @@ -234,70 +250,13 @@ function(slang_add_target dir type)

if(generate_split_debug_info)
if(MSVC)
get_target_property(
c_compiler_launcher
${target}
C_COMPILER_LAUNCHER
)
get_target_property(
cxx_compiler_launcher
${target}
CXX_COMPILER_LAUNCHER
)

if(
c_compiler_launcher MATCHES "ccache"
OR cxx_compiler_launcher MATCHES "ccache"
)
message(
WARNING
"(s)ccache detected for target ${target}. Removing launcher as it's incompatible with split debug info compiled with MSVC."
)
set_target_properties(
${target}
PROPERTIES C_COMPILER_LAUNCHER "" CXX_COMPILER_LAUNCHER ""
)
endif()

get_target_property(
msvc_debug_information_format
${target}
MSVC_DEBUG_INFORMATION_FORMAT
)
if(
NOT msvc_debug_information_format
MATCHES
"(ProgramDatabase|EditAndContinue)"
)
message(
WARNING
"Debug format must be ProgramDatabase or EditAndContinue to generate split debug info with MSVC"
)
endif()

set_target_properties(
${target}
PROPERTIES
# While it would be nice to set this here, we don't know if
# the user wants ProgramDatabase or EditAndContinue, so
# just check above
# MSVC_DEBUG_INFORMATION_FORMAT
# "$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>"
COMPILE_PDB_NAME "${target}"
COMPILE_PDB_OUTPUT_DIRECTORY "${output_dir}"
)
else()
# Common debug flags for GCC/Clang
target_compile_options(
${target}
PRIVATE
$<$<CONFIG:Debug,RelWithDebInfo>:
-g
-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.
-fdebug-prefix-map=${CMAKE_BINARY_DIR}=.
>
)

if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
# macOS - use dsymutil with --flat to create separate debug file
add_custom_command(
Expand Down Expand Up @@ -582,7 +541,6 @@ function(slang_add_target dir type)
install(
FILES ${debug_file}
DESTINATION ${debug_dest}
CONFIGURATIONS Debug RelWithDebInfo
COMPONENT ${debug_component}
EXCLUDE_FROM_ALL
OPTIONAL
Expand Down
1 change: 1 addition & 0 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ See the [documentation on testing](../tools/slang-test/README.md) for more infor
| `SLANG_ENABLE_TESTS` | `TRUE` | Enable test targets, requires SLANG_ENABLE_GFX, SLANG_ENABLE_SLANGD and SLANG_ENABLE_SLANGRT |
| `SLANG_ENABLE_EXAMPLES` | `TRUE` | Enable example targets, requires SLANG_ENABLE_GFX |
| `SLANG_LIB_TYPE` | `SHARED` | How to build the slang library |
| `SLANG_ENABLE_RELEASE_DEBUG_INFO` | `TRUE` | Enable generating debug info for Release configs |
| `SLANG_ENABLE_SPLIT_DEBUG_INFO` | `TRUE` | Enable generating split debug info for Debug and RelWithDebInfo configs |
| `SLANG_SLANG_LLVM_FLAVOR` | `FETCH_BINARY_IF_POSSIBLE` | How to set up llvm support |
| `SLANG_SLANG_LLVM_BINARY_URL` | System dependent | URL specifying the location of the slang-llvm prebuilt library |
Expand Down

0 comments on commit 27b7ac0

Please sign in to comment.