Skip to content

Support specifying the debug info format for C/C++ and Swift code #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ similar to the /Library or ~/Library directories on macOS.
.PARAMETER BuildType
The CMake build type to use, one of: Release, RelWithDebInfo, Debug.

.PARAMETER CDebugFormat
The debug information format for C/C++ code: dwarf or codeview.

.PARAMETER SwiftDebugFormat
The debug information format for Swift code: dwarf or codeview.

.PARAMETER SDKs
An array of architectures for which the Swift SDK should be built.

Expand Down Expand Up @@ -70,6 +76,8 @@ param(
[string] $BinaryCache = "S:\b",
[string] $LibraryRoot = "S:\Library",
[string] $BuildType = "Release",
[string] $CDebugFormat = "dwarf",
[string] $SwiftDebugFormat = "dwarf",
[string[]] $SDKs = @("X64","X86","Arm64"),
[string] $ProductVersion = "0.0.0",
[switch] $SkipBuild = $false,
Expand Down Expand Up @@ -352,8 +360,8 @@ function Build-CMakeProject {
TryAdd-KeyValue $Defines CMAKE_BUILD_TYPE $BuildType
TryAdd-KeyValue $Defines CMAKE_MT "mt"

$IsRelease = $Defines["CMAKE_BUILD_TYPE"] -eq "Release"
$Zi = if ($IsRelease) { "" } else { "/Zi" }
$GenerateDebugInfo = $Defines["CMAKE_BUILD_TYPE"] -ne "Release"
$Zi = if ($GenerateDebugInfo) { "/Zi" } else { "" }

$CFlags = "/GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline"
$CXXFlags = "/GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline /Zc:__cplusplus"
Expand All @@ -373,15 +381,15 @@ function Build-CMakeProject {
if ($UseBuiltCompilers.Contains("C")) {
TryAdd-KeyValue $Defines CMAKE_C_COMPILER "$BinaryCache\1\bin\clang-cl.exe"
TryAdd-KeyValue $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
if (-not $IsRelease) {
if ($GenerateDebugInfo -and $CDebugFormat -eq "dwarf") {
Append-FlagsDefine $Defines CMAKE_C_FLAGS -gdwarf
}
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
}
if ($UseBuiltCompilers.Contains("CXX")) {
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER "$BinaryCache\1\bin\clang-cl.exe"
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
if (-not $IsRelease) {
if ($GenerateDebugInfo -and $CDebugFormat -eq "dwarf") {
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS -gdwarf
}
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
Expand All @@ -404,18 +412,16 @@ function Build-CMakeProject {
}

# Debug Information
if ($IsRelease) {
$SwiftArgs.Add("-gnone") | Out-Null
if ($GenerateDebugInfo) {
if ($SwiftDebugFormat -eq "dwarf") {
$SwiftArgs.Add("-g -Xlinker /DEBUG:DWARF -use-ld=lld-link") | Out-Null
} else {
$SwiftArgs.Add("-g -debug-info-format=codeview -Xlinker -debug") | Out-Null
}
} else {
# $SwiftArgs.Add("-g -debug-info-format=codeview") | Out-Null
$SwiftArgs.Add("-g") | Out-Null
$SwiftArgs.Add("-use-ld=lld-link") | Out-Null
$SwiftArgs.Add("-gnone") | Out-Null
}
$SwiftArgs.Add("-Xlinker /INCREMENTAL:NO") | Out-Null
if (-not $IsRelease) {
# $SwiftArgs.Add("-Xlinker -debug") | Out-Null
$SwiftArgs.Add("-Xlinker /DEBUG:DWARF") | Out-Null
}

# Swift Requries COMDAT folding and de-duplication
$SwiftArgs.Add("-Xlinker /OPT:REF") | Out-Null
Expand Down