Skip to content

Commit 07defe1

Browse files
build: various tweaks (#459)
* build: various tweaks - Centralise `-D CMAKE_M=mt` as that is a CMake workaround - Clean up bleeding whitespace - Avoid installing static Swift packages - Support multiple python.exe in Path Co-authored-by: Tristan Labelle <[email protected]>
1 parent de67eb0 commit 07defe1

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

build.ps1

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ function Build-CMakeProject
123123
Invoke-VsDevShell $Arch
124124
$CurrentVSDevShellTargetArch = $Arch
125125
}
126-
126+
127127
# Add additional defines (unless already present)
128128
$Defines = $Defines.Clone()
129129
TryAddKeyValue $Defines CMAKE_BUILD_TYPE $BuildType
130+
TryAddKeyValue $Defines CMAKE_MT "mt"
130131

131132
$CFlags = "/GS- /Gw /Gy /Oi /Oy /Zi /Zc:inline"
132133
$CXXFlags = "/GS- /Gw /Gy /Oi /Oy /Zi /Zc:inline /Zc:__cplusplus"
@@ -158,17 +159,19 @@ function Build-CMakeProject
158159
if ($UseBuiltCompilers.Contains("Swift")) {
159160
TryAddKeyValue $Defines CMAKE_Swift_COMPILER S:/b/1/bin/swiftc.exe
160161
TryAddKeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget
161-
162+
162163
$RuntimeBuildDir = Get-ProjectBuildDir $Arch 1
163164
$SwiftResourceDir = "${RuntimeBuildDir}\lib\swift"
164-
$SwiftcFlags = @("-resource-dir $SwiftResourceDir",
165+
$SwiftcFlags = @(
166+
"-resource-dir $SwiftResourceDir",
165167
" -L $SwiftResourceDir\windows",
166168
" -vfsoverlay $RuntimeBuildDir\stdlib\windows-vfs-overlay.yaml",
167169
" -g -debug-info-format=codeview",
168170
" -Xlinker /INCREMENTAL:NO",
169171
" -Xlinker /DEBUG",
170172
" -Xlinker /OPT:REF",
171-
" -Xlinker /OPT:ICF") -Join " "
173+
" -Xlinker /OPT:ICF"
174+
) -Join " "
172175

173176
TryAddKeyValue $Defines CMAKE_Swift_FLAGS $SwiftcFlags
174177
}
@@ -200,7 +203,7 @@ function Build-CMakeProject
200203
cmake --build $Bin --target $Target
201204
Check-LastExitCode
202205
}
203-
206+
204207
if ("" -ne $InstallTo)
205208
{
206209
cmake --build $Bin --target install
@@ -221,7 +224,6 @@ function Build-Compilers($Arch)
221224
-CacheScript $SourceCache\swift\cmake\caches\Windows-$($Arch.LLVMName).cmake `
222225
-Defines @{
223226
CMAKE_INSTALL_PREFIX = "$ToolchainInstallRoot\usr";
224-
CMAKE_MT = "mt";
225227
LLVM_ENABLE_PDB = "YES";
226228
LLVM_EXTERNAL_CMARK_SOURCE_DIR = "$SourceCache\cmark";
227229
LLVM_EXTERNAL_SWIFT_SOURCE_DIR = "$SourceCache\swift";
@@ -253,15 +255,14 @@ function Build-LLVM($Arch)
253255
-Bin (Get-ProjectBuildDir $Arch 0) `
254256
-Arch $Arch `
255257
-Defines @{
256-
CMAKE_MT = "mt";
257258
LLVM_HOST_TRIPLE = $Arch.LLVMTarget;
258259
}
259260
}
260261

261262
function Build-ZLib($Arch)
262263
{
263264
$ArchName = $Arch.ShortName
264-
265+
265266
Build-CMakeProject `
266267
-Src $SourceCache\zlib `
267268
-Bin $BinaryCache\zlib-1.2.11.$ArchName `
@@ -270,7 +271,6 @@ function Build-ZLib($Arch)
270271
-BuildDefaultTarget `
271272
-Defines @{
272273
BUILD_SHARED_LIBS = "NO";
273-
CMAKE_MT = "mt";
274274
INSTALL_BIN_DIR = "$InstallRoot\zlib-1.2.11\usr\bin\$ArchName";
275275
INSTALL_LIB_DIR = "$InstallRoot\zlib-1.2.11\usr\lib\$ArchName";
276276
}
@@ -288,7 +288,6 @@ function Build-XML2($Arch)
288288
-BuildDefaultTarget `
289289
-Defines @{
290290
BUILD_SHARED_LIBS = "NO";
291-
CMAKE_MT = "mt";
292291
CMAKE_INSTALL_BINDIR = "bin/$ArchName";
293292
CMAKE_INSTALL_LIBDIR = "lib/$ArchName";
294293
LIBXML2_WITH_ICONV = "NO";
@@ -313,7 +312,6 @@ function Build-CURL($Arch)
313312
-BuildDefaultTarget `
314313
-Defines @{
315314
BUILD_SHARED_LIBS = "NO";
316-
CMAKE_MT = "mt";
317315
CMAKE_INSTALL_BINDIR = "bin/$ArchName";
318316
CMAKE_INSTALL_LIBDIR = "lib/$ArchName";
319317
BUILD_CURL_EXE = "NO";
@@ -371,12 +369,11 @@ function Build-ICU($Arch)
371369
-InstallTo "$InstallRoot\icu-69.1\usr" `
372370
-Arch $Arch `
373371
-BuildDefaultTarget `
374-
-Defines (@{
372+
-Defines ($BuildToolsDefines + @{
375373
BUILD_SHARED_LIBS = "NO";
376-
CMAKE_MT = "mt";
377374
CMAKE_INSTALL_BINDIR = "bin/$ArchName";
378375
CMAKE_INSTALL_LIBDIR = "lib/$ArchName";
379-
} + $BuildToolsDefines)
376+
})
380377
}
381378

382379
function Build-Runtime($Arch)
@@ -392,7 +389,6 @@ function Build-Runtime($Arch)
392389
-UseBuiltCompilers C,CXX `
393390
-BuildDefaultTarget `
394391
-Defines @{
395-
CMAKE_MT = "mt";
396392
LLVM_DIR = "$LLVMBuildDir\lib\cmake\llvm";
397393
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
398394
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
@@ -423,7 +419,6 @@ function Build-Dispatch($Arch)
423419
-UseBuiltCompilers C,CXX,Swift `
424420
-BuildDefaultTarget `
425421
-Defines @{
426-
CMAKE_MT = "mt";
427422
CMAKE_SYSTEM_NAME = "Windows";
428423
CMAKE_SYSTEM_PROCESSOR = $Arch.CMakeName;
429424
ENABLE_SWIFT = "YES";
@@ -479,7 +474,6 @@ function Build-Foundation($Arch)
479474
-UseBuiltCompilers ASM,C,Swift `
480475
-BuildDefaultTarget `
481476
-Defines @{
482-
CMAKE_MT = "mt";
483477
CMAKE_SYSTEM_NAME = "Windows";
484478
CMAKE_SYSTEM_PROCESSOR = $Arch.CMakeName;
485479
CURL_DIR = "$InstallRoot\curl-7.77.0\usr\lib\$ShortArch\cmake\CURL";
@@ -592,7 +586,7 @@ function Build-SQLite($Arch)
592586
."$env:ProgramFiles\Git\usr\bin\unzip.exe" -j -o S:\var\cache\sqlite-amalgamation-3360000.zip -d $Dest
593587
Copy-Item $SourceCache\swift-build\cmake\SQLite\CMakeLists.txt $Dest\
594588
}
595-
589+
596590
Build-CMakeProject `
597591
-Src $SourceCache\sqlite-3.36.0 `
598592
-Bin $BinaryCache\sqlite-3.36.0.$ArchName `
@@ -601,7 +595,6 @@ function Build-SQLite($Arch)
601595
-BuildDefaultTarget `
602596
-Defines @{
603597
BUILD_SHARED_LIBS = "NO";
604-
CMAKE_MT = "mt"
605598
}
606599
}
607600

@@ -615,17 +608,15 @@ function Build-System($Arch)
615608
-UseBuiltCompilers C,Swift `
616609
-BuildDefaultTarget `
617610
-Defines @{
618-
BUILD_SHARED_LIBS = "NO";
619-
CMAKE_INSTALL_LIBDIR = "lib/$($Arch.ShortName)";
620-
CMAKE_MT = "mt"
611+
BUILD_SHARED_LIBS = "YES";
621612
}
622613
}
623614

624615
function Build-ToolsSupportCore($Arch)
625616
{
626617
$DispatchBuildDir = Get-ProjectBuildDir $Arch 2
627618
$FoundationBuildDir = Get-ProjectBuildDir $Arch 3
628-
619+
629620
Build-CMakeProject `
630621
-Src $SourceCache\swift-tools-support-core `
631622
-Bin $BinaryCache\3 `
@@ -635,7 +626,6 @@ function Build-ToolsSupportCore($Arch)
635626
-BuildDefaultTarget `
636627
-Defines @{
637628
BUILD_SHARED_LIBS = "YES";
638-
CMAKE_MT = "mt";
639629
dispatch_DIR = "$DispatchBuildDir\cmake\modules";
640630
Foundation_DIR = "$FoundationBuildDir\cmake\modules";
641631
SwiftSystem_DIR = "$BinaryCache\2\cmake\modules";
@@ -648,7 +638,7 @@ function Build-LLBuild($Arch)
648638
{
649639
$DispatchBuildDir = Get-ProjectBuildDir $Arch 2
650640
$FoundationBuildDir = Get-ProjectBuildDir $Arch 3
651-
641+
652642
Build-CMakeProject `
653643
-Src $SourceCache\llbuild `
654644
-Bin $BinaryCache\4 `
@@ -659,8 +649,6 @@ function Build-LLBuild($Arch)
659649
-BuildDefaultTarget `
660650
-Defines @{
661651
BUILD_SHARED_LIBS = "YES";
662-
CMAKE_INSTALL_LIBDIR = "lib/$($Arch.ShortName)";
663-
CMAKE_MT = "mt";
664652
LLBUILD_SUPPORT_BINDINGS = "Swift";
665653
dispatch_DIR = "$DispatchBuildDir\cmake\modules";
666654
Foundation_DIR = "$FoundationBuildDir\cmake\modules";
@@ -674,11 +662,10 @@ function Build-Yams($Arch)
674662
$DispatchBuildDir = Get-ProjectBuildDir $Arch 2
675663
$FoundationBuildDir = Get-ProjectBuildDir $Arch 3
676664
$XCTestBuildDir = Get-ProjectBuildDir $Arch 4
677-
665+
678666
Build-CMakeProject `
679667
-Src $SourceCache\Yams `
680668
-Bin $BinaryCache\5 `
681-
-InstallTo $ToolchainInstallRoot\usr `
682669
-Arch $Arch `
683670
-UseBuiltCompilers Swift `
684671
-BuildDefaultTarget `
@@ -695,7 +682,7 @@ function Build-ArgumentParser($Arch)
695682
$DispatchBuildDir = Get-ProjectBuildDir $Arch 2
696683
$FoundationBuildDir = Get-ProjectBuildDir $Arch 3
697684
$XCTestBuildDir = Get-ProjectBuildDir $Arch 4
698-
685+
699686
Build-CMakeProject `
700687
-Src $SourceCache\swift-argument-parser `
701688
-Bin $BinaryCache\6 `
@@ -746,7 +733,6 @@ function Build-Crypto($Arch)
746733
Build-CMakeProject `
747734
-Src $SourceCache\swift-crypto `
748735
-Bin $BinaryCache\8 `
749-
-InstallTo $ToolchainInstallRoot\usr `
750736
-Arch $Arch `
751737
-UseBuiltCompilers Swift `
752738
-BuildDefaultTarget `
@@ -779,7 +765,6 @@ function Build-ASN1($Arch)
779765
Build-CMakeProject `
780766
-Src $SourceCache\swift-asn1 `
781767
-Bin $BinaryCache\10 `
782-
-InstallTo $ToolchainInstallRoot\usr `
783768
-Arch $Arch `
784769
-UseBuiltCompilers Swift `
785770
-BuildDefaultTarget `
@@ -794,7 +779,7 @@ function Build-Certificates($Arch)
794779
{
795780
$DispatchBuildDir = Get-ProjectBuildDir $Arch 2
796781
$FoundationBuildDir = Get-ProjectBuildDir $Arch 3
797-
782+
798783
Build-CMakeProject `
799784
-Src $SourceCache\swift-certificates `
800785
-Bin $BinaryCache\11 `
@@ -803,7 +788,6 @@ function Build-Certificates($Arch)
803788
-BuildDefaultTarget `
804789
-Defines @{
805790
BUILD_SHARED_LIBS = "NO";
806-
CMAKE_INSTALL_PREFIX = "$ToolchainInstallRoot\usr"; # Don't use -InstallTo, we don't build install
807791
dispatch_DIR = "$DispatchBuildDir\cmake\modules";
808792
Foundation_DIR = "$FoundationBuildDir\cmake\modules";
809793
SwiftASN1_DIR = "$BinaryCache\10\cmake\modules";
@@ -817,7 +801,7 @@ function Build-PackageManager($Arch)
817801
$SwiftResourceDir = "${RuntimeBuildDir}\lib\swift"
818802
$DispatchBuildDir = Get-ProjectBuildDir $Arch 2
819803
$FoundationBuildDir = Get-ProjectBuildDir $Arch 3
820-
804+
821805
Build-CMakeProject `
822806
-Src $SourceCache\swift-package-manager `
823807
-Bin $BinaryCache\12 `
@@ -827,7 +811,6 @@ function Build-PackageManager($Arch)
827811
-BuildDefaultTarget `
828812
-Defines @{
829813
BUILD_SHARED_LIBS = "YES";
830-
CMAKE_MT = "mt";
831814
CMAKE_Swift_FLAGS = "-DCRYPTO_v2 -resource-dir $SwiftResourceDir -L $SwiftResourceDir\windows -vfsoverlay $RuntimeBuildDir\stdlib\windows-vfs-overlay.yaml";
832815
dispatch_DIR = "$DispatchBuildDir\cmake\modules";
833816
Foundation_DIR = "$FoundationBuildDir\cmake\modules";
@@ -849,7 +832,7 @@ function Build-IndexStoreDB($Arch)
849832
{
850833
$DispatchBuildDir = Get-ProjectBuildDir $Arch 2
851834
$FoundationBuildDir = Get-ProjectBuildDir $Arch 3
852-
835+
853836
Build-CMakeProject `
854837
-Src $SourceCache\indexstore-db `
855838
-Bin $BinaryCache\13 `
@@ -858,9 +841,7 @@ function Build-IndexStoreDB($Arch)
858841
-BuildDefaultTarget `
859842
-Defines @{
860843
BUILD_SHARED_LIBS = "NO";
861-
CMAKE_MT = "mt";
862844
CMAKE_CXX_FLAGS = "-Xclang -fno-split-cold-code";
863-
CMAKE_INSTALL_PREFIX = "$ToolchainInstallRoot\usr"; # Specify here to not build the install target
864845
dispatch_DIR = "$DispatchBuildDir\cmake\modules";
865846
Foundation_DIR = "$FoundationBuildDir\cmake\modules";
866847
}
@@ -876,15 +857,15 @@ function Build-Syntax($Arch)
876857
-UseBuiltCompilers Swift `
877858
-BuildDefaultTarget `
878859
-Defines @{
879-
CMAKE_MT = "mt";
860+
BUILD_SHARED_LIBS = "YES";
880861
}
881862
}
882863

883864
function Build-SourceKitLSP($Arch)
884865
{
885866
$DispatchBuildDir = Get-ProjectBuildDir $Arch 2
886867
$FoundationBuildDir = Get-ProjectBuildDir $Arch 3
887-
868+
888869
Build-CMakeProject `
889870
-Src $SourceCache\sourcekit-lsp `
890871
-Bin $BinaryCache\15 `
@@ -893,7 +874,6 @@ function Build-SourceKitLSP($Arch)
893874
-UseBuiltCompilers C,Swift `
894875
-BuildDefaultTarget `
895876
-Defines @{
896-
CMAKE_MT = "mt";
897877
dispatch_DIR = "$DispatchBuildDir\cmake\modules";
898878
Foundation_DIR = "$FoundationBuildDir\cmake\modules";
899879
SwiftSystem_DIR = "$BinaryCache\2\cmake\modules";
@@ -947,7 +927,7 @@ Copy-Item -Force $BinaryCache\7\bin\swift-driver.exe $ToolchainInstallRoot\usr\b
947927
$python = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Shared\Python39_64\python.exe"
948928
if (-not (Test-Path $python))
949929
{
950-
$python = ((where.exe python) | Out-String).Trim()
930+
$python = (where.exe python) | Select -First 1
951931
if (-not (Test-Path $python))
952932
{
953933
throw "Python.exe not found"

0 commit comments

Comments
 (0)