Skip to content

Commit ba0eae3

Browse files
Consolidate CMAKE_Swift_FLAGS in build.ps1
* Consolidate CMAKE_Swift_FLAGS * Fix missing flags for indexstoredb * Remove local test code Co-authored-by: Saleem Abdulrasool <[email protected]>
1 parent 07defe1 commit ba0eae3

File tree

1 file changed

+44
-33
lines changed

1 file changed

+44
-33
lines changed

build.ps1

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,23 @@ function Invoke-VsDevShell($Arch)
8888
Check-LastExitCode
8989
}
9090

91-
function TryAddKeyValue([hashtable]$Hashtable, [string]$Key, [string]$Value)
91+
function TryAdd-Define([hashtable]$Defines, [string]$Name, [string]$Value)
9292
{
93-
if (-not $Hashtable.Contains($Key))
93+
if (-not $Defines.Contains($Name))
9494
{
95-
$Hashtable.Add($Key, $Value)
95+
$Defines.Add($Name, $Value)
96+
}
97+
}
98+
99+
function Append-FlagsDefine([hashtable]$Defines, [string]$Name, [string]$Value)
100+
{
101+
if ($Defines.Contains($Name))
102+
{
103+
$Defines[$name] += " $Value"
104+
}
105+
else
106+
{
107+
$Defines.Add($Name, $Value)
96108
}
97109
}
98110

@@ -126,57 +138,57 @@ function Build-CMakeProject
126138

127139
# Add additional defines (unless already present)
128140
$Defines = $Defines.Clone()
129-
TryAddKeyValue $Defines CMAKE_BUILD_TYPE $BuildType
130-
TryAddKeyValue $Defines CMAKE_MT "mt"
141+
TryAdd-Define $Defines CMAKE_BUILD_TYPE $BuildType
142+
TryAdd-Define $Defines CMAKE_MT "mt"
131143

132144
$CFlags = "/GS- /Gw /Gy /Oi /Oy /Zi /Zc:inline"
133145
$CXXFlags = "/GS- /Gw /Gy /Oi /Oy /Zi /Zc:inline /Zc:__cplusplus"
134146
if ($UseMSVCCompilers.Contains("C"))
135147
{
136-
TryAddKeyValue $Defines CMAKE_C_COMPILER cl
137-
TryAddKeyValue $Defines CMAKE_C_FLAGS $CFlags
148+
TryAdd-Define $Defines CMAKE_C_COMPILER cl
149+
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
138150
}
139151
if ($UseMSVCCompilers.Contains("CXX"))
140152
{
141-
TryAddKeyValue $Defines CMAKE_CXX_COMPILER cl
142-
TryAddKeyValue $Defines CMAKE_CXX_FLAGS $CXXFlags
153+
TryAdd-Define $Defines CMAKE_CXX_COMPILER cl
154+
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
143155
}
144156
if ($UseBuiltCompilers.Contains("ASM")) {
145-
TryAddKeyValue $Defines CMAKE_ASM_COMPILER S:/b/1/bin/clang-cl.exe
146-
TryAddKeyValue $Defines CMAKE_ASM_FLAGS "--target=$($Arch.LLVMTarget)"
147-
TryAddKeyValue $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "/MD"
157+
TryAdd-Define $Defines CMAKE_ASM_COMPILER S:/b/1/bin/clang-cl.exe
158+
Append-FlagsDefine $Defines CMAKE_ASM_FLAGS "--target=$($Arch.LLVMTarget)"
159+
TryAdd-Define $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "/MD"
148160
}
149161
if ($UseBuiltCompilers.Contains("C")) {
150-
TryAddKeyValue $Defines CMAKE_C_COMPILER S:/b/1/bin/clang-cl.exe
151-
TryAddKeyValue $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
152-
TryAddKeyValue $Defines CMAKE_C_FLAGS $CFlags
162+
TryAdd-Define $Defines CMAKE_C_COMPILER S:/b/1/bin/clang-cl.exe
163+
TryAdd-Define $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
164+
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
153165
}
154166
if ($UseBuiltCompilers.Contains("CXX")) {
155-
TryAddKeyValue $Defines CMAKE_CXX_COMPILER S:/b/1/bin/clang-cl.exe
156-
TryAddKeyValue $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
157-
TryAddKeyValue $Defines CMAKE_CXX_FLAGS $CXXFlags
167+
TryAdd-Define $Defines CMAKE_CXX_COMPILER S:/b/1/bin/clang-cl.exe
168+
TryAdd-Define $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
169+
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
158170
}
159171
if ($UseBuiltCompilers.Contains("Swift")) {
160-
TryAddKeyValue $Defines CMAKE_Swift_COMPILER S:/b/1/bin/swiftc.exe
161-
TryAddKeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget
172+
TryAdd-Define $Defines CMAKE_Swift_COMPILER S:/b/1/bin/swiftc.exe
173+
TryAdd-Define $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget
162174

163175
$RuntimeBuildDir = Get-ProjectBuildDir $Arch 1
164176
$SwiftResourceDir = "${RuntimeBuildDir}\lib\swift"
165177
$SwiftcFlags = @(
166178
"-resource-dir $SwiftResourceDir",
167-
" -L $SwiftResourceDir\windows",
168-
" -vfsoverlay $RuntimeBuildDir\stdlib\windows-vfs-overlay.yaml",
169-
" -g -debug-info-format=codeview",
170-
" -Xlinker /INCREMENTAL:NO",
171-
" -Xlinker /DEBUG",
172-
" -Xlinker /OPT:REF",
173-
" -Xlinker /OPT:ICF"
179+
"-L $SwiftResourceDir\windows",
180+
"-vfsoverlay $RuntimeBuildDir\stdlib\windows-vfs-overlay.yaml",
181+
"-g -debug-info-format=codeview",
182+
"-Xlinker /INCREMENTAL:NO",
183+
"-Xlinker /DEBUG",
184+
"-Xlinker /OPT:REF",
185+
"-Xlinker /OPT:ICF"
174186
) -Join " "
175187

176-
TryAddKeyValue $Defines CMAKE_Swift_FLAGS $SwiftcFlags
188+
Append-FlagsDefine $Defines CMAKE_Swift_FLAGS $SwiftcFlags
177189
}
178190
if ("" -ne $InstallTo) {
179-
TryAddKeyValue $Defines CMAKE_INSTALL_PREFIX $InstallTo
191+
TryAdd-Define $Defines CMAKE_INSTALL_PREFIX $InstallTo
180192
}
181193

182194
# Generate the project
@@ -797,8 +809,6 @@ function Build-Certificates($Arch)
797809

798810
function Build-PackageManager($Arch)
799811
{
800-
$RuntimeBuildDir = Get-ProjectBuildDir $Arch 1
801-
$SwiftResourceDir = "${RuntimeBuildDir}\lib\swift"
802812
$DispatchBuildDir = Get-ProjectBuildDir $Arch 2
803813
$FoundationBuildDir = Get-ProjectBuildDir $Arch 3
804814

@@ -811,7 +821,7 @@ function Build-PackageManager($Arch)
811821
-BuildDefaultTarget `
812822
-Defines @{
813823
BUILD_SHARED_LIBS = "YES";
814-
CMAKE_Swift_FLAGS = "-DCRYPTO_v2 -resource-dir $SwiftResourceDir -L $SwiftResourceDir\windows -vfsoverlay $RuntimeBuildDir\stdlib\windows-vfs-overlay.yaml";
824+
CMAKE_Swift_FLAGS = "-DCRYPTO_v2";
815825
dispatch_DIR = "$DispatchBuildDir\cmake\modules";
816826
Foundation_DIR = "$FoundationBuildDir\cmake\modules";
817827
SwiftSystem_DIR = "$BinaryCache\2\cmake\modules";
@@ -841,6 +851,7 @@ function Build-IndexStoreDB($Arch)
841851
-BuildDefaultTarget `
842852
-Defines @{
843853
BUILD_SHARED_LIBS = "NO";
854+
CMAKE_C_FLAGS = "-Xclang -fno-split-cold-code";
844855
CMAKE_CXX_FLAGS = "-Xclang -fno-split-cold-code";
845856
dispatch_DIR = "$DispatchBuildDir\cmake\modules";
846857
Foundation_DIR = "$FoundationBuildDir\cmake\modules";
@@ -927,7 +938,7 @@ Copy-Item -Force $BinaryCache\7\bin\swift-driver.exe $ToolchainInstallRoot\usr\b
927938
$python = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Shared\Python39_64\python.exe"
928939
if (-not (Test-Path $python))
929940
{
930-
$python = (where.exe python) | Select -First 1
941+
$python = (where.exe python) | Select-Object -First 1
931942
if (-not (Test-Path $python))
932943
{
933944
throw "Python.exe not found"

0 commit comments

Comments
 (0)