Skip to content

Commit 055567e

Browse files
committed
[Windows] Build and install swift-testing in Windows toolchains
* Basically following XCTest scheme. * Build TestingMacro separately from Testing library and install it to the toolchain's `bin` * Testing swift-testing itself is TODO (cherry picked from commit f069aec)
1 parent f9e244b commit 055567e

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

utils/build.ps1

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ $ArchX64 = @{
187187
PlatformInstallRoot = "$BinaryCache\x64\Windows.platform";
188188
SDKInstallRoot = "$BinaryCache\x64\Windows.platform\Developer\SDKs\Windows.sdk";
189189
XCTestInstallRoot = "$BinaryCache\x64\Windows.platform\Developer\Library\XCTest-development";
190+
SwiftTestingInstallRoot = "$BinaryCache\x64\Windows.platform\Developer\Library\Testing-development";
190191
ToolchainInstallRoot = "$BinaryCache\x64\toolchains\$ProductVersion+Asserts";
191192
}
192193

@@ -202,6 +203,7 @@ $ArchX86 = @{
202203
PlatformInstallRoot = "$BinaryCache\x86\Windows.platform";
203204
SDKInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\SDKs\Windows.sdk";
204205
XCTestInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\Library\XCTest-development";
206+
SwiftTestingInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\Library\Testing-development";
205207
}
206208

207209
$ArchARM64 = @{
@@ -217,6 +219,7 @@ $ArchARM64 = @{
217219
SDKInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\SDKs\Windows.sdk";
218220
XCTestInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\Library\XCTest-development";
219221
ToolchainInstallRoot = "$BinaryCache\arm64\toolchains\$ProductVersion+Asserts";
222+
SwiftTestingInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\Library\Testing-development";
220223
}
221224

222225
$HostArch = switch ($HostArchName) {
@@ -284,6 +287,7 @@ enum TargetComponent {
284287
Dispatch
285288
Foundation
286289
XCTest
290+
SwiftTesting
287291
}
288292

289293
function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) {
@@ -310,6 +314,7 @@ enum HostComponent {
310314
LMDB
311315
SymbolKit
312316
DocC
317+
SwiftTestingMacros
313318
}
314319

315320
function Get-HostProjectBinaryCache([HostComponent]$Project) {
@@ -1492,11 +1497,43 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
14921497
dispatch_DIR = "$DispatchBinaryCache\cmake\modules";
14931498
Foundation_DIR = "$FoundationBinaryCache\cmake\modules";
14941499
} + $TestingDefines)
1500+
}
1501+
}
1502+
1503+
function Build-SwiftTesting([Platform]$Platform, $Arch, [switch]$Test = $false) {
1504+
$SwiftTestingBinaryCache = Get-TargetProjectBinaryCache $Arch SwiftTesting
1505+
1506+
Isolate-EnvVars {
1507+
if ($Test) {
1508+
# TODO: Test
1509+
return
1510+
} else {
1511+
$Targets = @("default")
1512+
$InstallPath = "$($Arch.SwiftTestingInstallRoot)\usr"
1513+
}
14951514

1515+
Build-CMakeProject `
1516+
-Src $SourceCache\swift-testing `
1517+
-Bin $SwiftTestingBinaryCache `
1518+
-InstallTo $InstallPath `
1519+
-Arch $Arch `
1520+
-Platform $Platform `
1521+
-UseBuiltCompilers C,CXX,Swift `
1522+
-BuildTargets $Targets `
1523+
-Defines (@{
1524+
BUILD_SHARED_LIBS = "YES";
1525+
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
1526+
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
1527+
# FIXME: Build the plugin for the builder and specify the path.
1528+
SwiftTesting_MACRO = "NO";
1529+
})
1530+
}
1531+
}
1532+
1533+
function Write-PlatformInfoPlist([Platform]$Platform, $Arch) {
14961534
$PList = [IO.Path]::Combine($Arch.BinaryCache, "${Platform}.platform".ToLower(), "Info.plist")
1497-
Invoke-Program $python -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'XCTEST_VERSION': 'development', 'SWIFTC_FLAGS': ['-use-ld=lld'] } }), encoding='utf-8'))" `
1535+
Invoke-Program $python -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'XCTEST_VERSION': 'development', 'SWIFT_TESTING_VERSION': 'development', 'SWIFTC_FLAGS': ['-use-ld=lld'] } }), encoding='utf-8'))" `
14981536
-OutFile "$PList"
1499-
}
15001537
}
15011538

15021539
# Copies files installed by CMake from the arch-specific platform root,
@@ -1900,6 +1937,21 @@ function Build-SourceKitLSP($Arch) {
19001937
}
19011938
}
19021939

1940+
function Build-SwiftTestingMacros($Arch) {
1941+
Build-CMakeProject `
1942+
-Src $SourceCache\swift-testing\Sources\TestingMacros `
1943+
-Bin (Get-HostProjectBinaryCache SwiftTestingMacros) `
1944+
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
1945+
-Arch $Arch `
1946+
-Platform Windows `
1947+
-UseBuiltCompilers Swift `
1948+
-SwiftSDK ([IO.Path]::Combine((Get-InstallDir $HostArch), "Platforms", "Windows.platform", "Developer", "SDKs", "Windows.sdk")) `
1949+
-BuildTargets default `
1950+
-Defines @{
1951+
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
1952+
}
1953+
}
1954+
19031955
function Install-HostToolchain() {
19041956
if ($ToBatch) { return }
19051957

@@ -2059,6 +2111,8 @@ if (-not $SkipBuild) {
20592111
Invoke-BuildStep Build-Dispatch Windows $Arch
20602112
Invoke-BuildStep Build-Foundation Windows $Arch
20612113
Invoke-BuildStep Build-XCTest Windows $Arch
2114+
Invoke-BuildStep Build-SwiftTesting Windows $Arch
2115+
Invoke-BuildStep Write-PlatformInfoPlist Windows $Arch
20622116
}
20632117
}
20642118

@@ -2077,6 +2131,8 @@ if (-not $ToBatch) {
20772131
}
20782132

20792133
if (-not $SkipBuild) {
2134+
# TestingMacros can't be built before the standard library for the host as it is required for the Swift code.
2135+
Invoke-BuildStep Build-SwiftTestingMacros $HostArch
20802136
Invoke-BuildStep Build-SQLite $HostArch
20812137
Invoke-BuildStep Build-System $HostArch
20822138
Invoke-BuildStep Build-ToolsSupportCore $HostArch
@@ -2131,6 +2187,9 @@ if (-not $IsCrossCompiling) {
21312187
if ($Test -contains "xctest") {
21322188
Build-XCTest Windows $HostArch -Test
21332189
}
2190+
if ($Test -contains "testing") {
2191+
Build-SwiftTesting Windows $HostArch -Test
2192+
}
21342193
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
21352194
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
21362195
}

0 commit comments

Comments
 (0)