Skip to content

Commit 6325f3c

Browse files
committed
build: disable debug information on release builds
Disable the default build from emitting debug information. This will speed up the build and reduce the output size. This is particularly important for the Swift side which will emit a large amount of metadata into the final binaries which is not stripped. This is intended to be the default build type for CI. For local builds, developers may use `-BuildType RelWithDebInfo` to get debug information emitted.
1 parent f262d4a commit 6325f3c

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

build.ps1

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,11 @@ function Build-CMakeProject {
352352
TryAdd-KeyValue $Defines CMAKE_BUILD_TYPE $BuildType
353353
TryAdd-KeyValue $Defines CMAKE_MT "mt"
354354

355-
$CFlags = "/GS- /Gw /Gy /Oi /Oy /Zi /Zc:inline"
356-
$CXXFlags = "/GS- /Gw /Gy /Oi /Oy /Zi /Zc:inline /Zc:__cplusplus"
355+
$IsRelease = $Defines["CMAKE_BUILD_TYPE"] -eq "Release"
356+
$Zi = if ($IsRelease) { "" } else { "/Zi" }
357+
358+
$CFlags = "/GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline"
359+
$CXXFlags = "/GS- /Gw /Gy /Oi /Oy $Zi /Zc:inline /Zc:__cplusplus"
357360
if ($UseMSVCCompilers.Contains("C")) {
358361
TryAdd-KeyValue $Defines CMAKE_C_COMPILER cl
359362
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
@@ -370,13 +373,17 @@ function Build-CMakeProject {
370373
if ($UseBuiltCompilers.Contains("C")) {
371374
TryAdd-KeyValue $Defines CMAKE_C_COMPILER "$BinaryCache\1\bin\clang-cl.exe"
372375
TryAdd-KeyValue $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
373-
Append-FlagsDefine $Defines CMAKE_C_FLAGS -gdwarf
376+
if (-not $IsRelease) {
377+
Append-FlagsDefine $Defines CMAKE_C_FLAGS -gdwarf
378+
}
374379
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
375380
}
376381
if ($UseBuiltCompilers.Contains("CXX")) {
377382
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER "$BinaryCache\1\bin\clang-cl.exe"
378383
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
379-
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS -gdwarf
384+
if (-not $IsRelease) {
385+
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS -gdwarf
386+
}
380387
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
381388
}
382389
if ($UseBuiltCompilers.Contains("Swift")) {
@@ -397,11 +404,18 @@ function Build-CMakeProject {
397404
}
398405

399406
# Debug Information
400-
# $SwiftArgs.Add("-g -debug-info-format=codeview") | Out-Null
401-
$SwiftArgs.Add("-g") | Out-Null
402-
$SwiftArgs.Add("-use-ld=lld-link") | Out-Null
407+
if ($IsRelease) {
408+
$SwiftArgs.Add("-gnone") | Out-Null
409+
} 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
413+
}
403414
$SwiftArgs.Add("-Xlinker /INCREMENTAL:NO") | Out-Null
404-
$SwiftArgs.Add("-Xlinker /DEBUG:DWARF") | Out-Null
415+
if (-not $IsRelease) {
416+
# $SwiftArgs.Add("-Xlinker -debug") | Out-Null
417+
$SwiftArgs.Add("-Xlinker /DEBUG:DWARF") | Out-Null
418+
}
405419

406420
# Swift Requries COMDAT folding and de-duplication
407421
$SwiftArgs.Add("-Xlinker /OPT:REF") | Out-Null
@@ -545,6 +559,11 @@ function Build-Compilers($Arch, [switch]$Test = $false) {
545559
}
546560
}
547561

562+
$LLVM_ENABLE_PDB = switch ($BuildType) {
563+
"Release" { "NO" }
564+
default { "YES" }
565+
}
566+
548567
Build-CMakeProject `
549568
-Src $SourceCache\llvm-project\llvm `
550569
-Bin $BinaryCache\1 `
@@ -555,13 +574,17 @@ function Build-Compilers($Arch, [switch]$Test = $false) {
555574
-Defines ($TestingDefines + @{
556575
CLANG_TABLEGEN = "$BinaryCache\0\bin\clang-tblgen.exe";
557576
CLANG_TIDY_CONFUSABLE_CHARS_GEN = "$BinaryCache\0\bin\clang-tidy-confusable-chars-gen.exe";
577+
# LLVM plays tricks with flags and prefers to use `LLVM_ENABLE_PDB` for
578+
# debug information on Windows rather than the CMake handling. This
579+
# give us a sligtly faster build.
580+
CMAKE_BUILD_TYPE = "Release";
558581
CMAKE_INSTALL_PREFIX = "$($Arch.ToolchainInstallRoot)\usr";
559582
LLDB_PYTHON_EXE_RELATIVE_PATH = "python.exe";
560583
LLDB_PYTHON_EXT_SUFFIX = ".pyd";
561584
LLDB_PYTHON_RELATIVE_PATH = "lib/site-packages";
562585
LLDB_TABLEGEN = "$BinaryCache\0\bin\lldb-tblgen.exe";
563586
LLVM_CONFIG_PATH = "$BinaryCache\0\bin\llvm-config.exe";
564-
LLVM_ENABLE_PDB = "YES";
587+
LLVM_ENABLE_PDB = $LLVM_ENABLE_PDB;
565588
LLVM_EXTERNAL_CMARK_SOURCE_DIR = "$SourceCache\cmark";
566589
LLVM_EXTERNAL_SWIFT_SOURCE_DIR = "$SourceCache\swift";
567590
LLVM_NATIVE_TOOL_DIR = "$BinaryCache\0\bin";
@@ -725,7 +748,7 @@ function Build-Runtime($Arch) {
725748
SWIFT_PATH_TO_LIBDISPATCH_SOURCE = "$SourceCache\swift-corelibs-libdispatch";
726749
SWIFT_PATH_TO_STRING_PROCESSING_SOURCE = "$SourceCache\swift-experimental-string-processing";
727750
SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE = "$SourceCache\swift-syntax";
728-
CMAKE_SHARED_LINKER_FLAGS = "/DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF";
751+
CMAKE_SHARED_LINKER_FLAGS = "/INCREMENTAL:NO /OPT:REF /OPT:ICF";
729752
}
730753

731754
Invoke-Program $python -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'DEFAULT_USE_RUNTIME': 'MD' } }), encoding='utf-8'))" `

0 commit comments

Comments
 (0)