Skip to content

Commit 9e6e17e

Browse files
Support specifying the debug info format. (#573)
1 parent 6325f3c commit 9e6e17e

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

build.ps1

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ similar to the /Library or ~/Library directories on macOS.
2828
.PARAMETER BuildType
2929
The CMake build type to use, one of: Release, RelWithDebInfo, Debug.
3030
31+
.PARAMETER CDebugFormat
32+
The debug information format for C/C++ code: dwarf or codeview.
33+
34+
.PARAMETER SwiftDebugFormat
35+
The debug information format for Swift code: dwarf or codeview.
36+
3137
.PARAMETER SDKs
3238
An array of architectures for which the Swift SDK should be built.
3339
@@ -70,6 +76,8 @@ param(
7076
[string] $BinaryCache = "S:\b",
7177
[string] $LibraryRoot = "S:\Library",
7278
[string] $BuildType = "Release",
79+
[string] $CDebugFormat = "dwarf",
80+
[string] $SwiftDebugFormat = "dwarf",
7381
[string[]] $SDKs = @("X64","X86","Arm64"),
7482
[string] $ProductVersion = "0.0.0",
7583
[switch] $SkipBuild = $false,
@@ -352,8 +360,8 @@ function Build-CMakeProject {
352360
TryAdd-KeyValue $Defines CMAKE_BUILD_TYPE $BuildType
353361
TryAdd-KeyValue $Defines CMAKE_MT "mt"
354362

355-
$IsRelease = $Defines["CMAKE_BUILD_TYPE"] -eq "Release"
356-
$Zi = if ($IsRelease) { "" } else { "/Zi" }
363+
$GenerateDebugInfo = $Defines["CMAKE_BUILD_TYPE"] -ne "Release"
364+
$Zi = if ($GenerateDebugInfo) { "/Zi" } else { "" }
357365

358366
$CFlags = "/GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline"
359367
$CXXFlags = "/GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline /Zc:__cplusplus"
@@ -373,15 +381,15 @@ function Build-CMakeProject {
373381
if ($UseBuiltCompilers.Contains("C")) {
374382
TryAdd-KeyValue $Defines CMAKE_C_COMPILER "$BinaryCache\1\bin\clang-cl.exe"
375383
TryAdd-KeyValue $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
376-
if (-not $IsRelease) {
384+
if ($GenerateDebugInfo -and $CDebugFormat -eq "dwarf") {
377385
Append-FlagsDefine $Defines CMAKE_C_FLAGS -gdwarf
378386
}
379387
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
380388
}
381389
if ($UseBuiltCompilers.Contains("CXX")) {
382390
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER "$BinaryCache\1\bin\clang-cl.exe"
383391
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
384-
if (-not $IsRelease) {
392+
if ($GenerateDebugInfo -and $CDebugFormat -eq "dwarf") {
385393
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS -gdwarf
386394
}
387395
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
@@ -404,18 +412,16 @@ function Build-CMakeProject {
404412
}
405413

406414
# Debug Information
407-
if ($IsRelease) {
408-
$SwiftArgs.Add("-gnone") | Out-Null
415+
if ($GenerateDebugInfo) {
416+
if ($SwiftDebugFormat -eq "dwarf") {
417+
$SwiftArgs.Add("-g -Xlinker /DEBUG:DWARF -use-ld=lld-link") | Out-Null
418+
} else {
419+
$SwiftArgs.Add("-g -debug-info-format=codeview -Xlinker -debug") | Out-Null
420+
}
409421
} else {
410-
# $SwiftArgs.Add("-g -debug-info-format=codeview") | Out-Null
411-
$SwiftArgs.Add("-g") | Out-Null
412-
$SwiftArgs.Add("-use-ld=lld-link") | Out-Null
422+
$SwiftArgs.Add("-gnone") | Out-Null
413423
}
414424
$SwiftArgs.Add("-Xlinker /INCREMENTAL:NO") | Out-Null
415-
if (-not $IsRelease) {
416-
# $SwiftArgs.Add("-Xlinker -debug") | Out-Null
417-
$SwiftArgs.Add("-Xlinker /DEBUG:DWARF") | Out-Null
418-
}
419425

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

0 commit comments

Comments
 (0)