Skip to content

Commit f069aec

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
1 parent e06d38b commit f069aec

File tree

1 file changed

+78
-13
lines changed

1 file changed

+78
-13
lines changed

utils/build.ps1

+78-13
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ $ArchX64 = @{
215215
PlatformInstallRoot = "$BinaryCache\x64\Windows.platform";
216216
SDKInstallRoot = "$BinaryCache\x64\Windows.platform\Developer\SDKs\Windows.sdk";
217217
XCTestInstallRoot = "$BinaryCache\x64\Windows.platform\Developer\Library\XCTest-development";
218+
SwiftTestingInstallRoot = "$BinaryCache\x64\Windows.platform\Developer\Library\Testing-development";
218219
ToolchainInstallRoot = "$BinaryCache\x64\toolchains\$ProductVersion+Asserts";
219220
}
220221

@@ -230,6 +231,7 @@ $ArchX86 = @{
230231
PlatformInstallRoot = "$BinaryCache\x86\Windows.platform";
231232
SDKInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\SDKs\Windows.sdk";
232233
XCTestInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\Library\XCTest-development";
234+
SwiftTestingInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\Library\Testing-development";
233235
}
234236

235237
$ArchARM64 = @{
@@ -245,6 +247,7 @@ $ArchARM64 = @{
245247
SDKInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\SDKs\Windows.sdk";
246248
XCTestInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\Library\XCTest-development";
247249
ToolchainInstallRoot = "$BinaryCache\arm64\toolchains\$ProductVersion+Asserts";
250+
SwiftTestingInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\Library\Testing-development";
248251
}
249252

250253
$AndroidARM64 = @{
@@ -258,6 +261,7 @@ $AndroidARM64 = @{
258261
PlatformInstallRoot = "$BinaryCache\arm64\Android.platform";
259262
SDKInstallRoot = "$BinaryCache\arm64\Android.platform\Developer\SDKs\Android.sdk";
260263
XCTestInstallRoot = "$BinaryCache\arm64\Android.platform\Developer\Library\XCTest-development";
264+
SwiftTestingInstallRoot = "$BinaryCache\arm64\Android.platform\Developer\Library\Testing-development";
261265
}
262266

263267
$AndroidARMv7 = @{
@@ -271,6 +275,7 @@ $AndroidARMv7 = @{
271275
PlatformInstallRoot = "$BinaryCache\armv7\Android.platform";
272276
SDKInstallRoot = "$BinaryCache\armv7\Android.platform\Developer\SDKs\Android.sdk";
273277
XCTestInstallRoot = "$BinaryCache\armv7\Android.platform\Developer\Library\XCTest-development";
278+
SwiftTestingInstallRoot = "$BinaryCache\armv7\Android.platform\Developer\Library\Testing-development";
274279
}
275280

276281
$AndroidX86 = @{
@@ -284,6 +289,7 @@ $AndroidX86 = @{
284289
PlatformInstallRoot = "$BinaryCache\x86\Android.platform";
285290
SDKInstallRoot = "$BinaryCache\x86\Android.platform\Developer\SDKs\Android.sdk";
286291
XCTestInstallRoot = "$BinaryCache\x86\Android.platform\Developer\Library\XCTest-development";
292+
SwiftTestingInstallRoot = "$BinaryCache\x86\Android.platform\Developer\Library\Testing-development";
287293
}
288294

289295
$AndroidX64 = @{
@@ -297,6 +303,7 @@ $AndroidX64 = @{
297303
PlatformInstallRoot = "$BinaryCache\x64\Android.platform";
298304
SDKInstallRoot = "$BinaryCache\x64\Android.platform\Developer\SDKs\Android.sdk";
299305
XCTestInstallRoot = "$BinaryCache\x64\Android.platform\Developer\Library\XCTest-development";
306+
SwiftTestingInstallRoot = "$BinaryCache\x64\Android.platform\Developer\Library\Testing-development";
300307
}
301308

302309
$HostArch = switch ($HostArchName) {
@@ -387,6 +394,7 @@ enum TargetComponent {
387394
Dispatch
388395
Foundation
389396
XCTest
397+
SwiftTesting
390398
}
391399

392400
function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) {
@@ -413,6 +421,7 @@ enum HostComponent {
413421
LMDB
414422
SymbolKit
415423
DocC
424+
SwiftTestingMacros
416425
}
417426

418427
function Get-HostProjectBinaryCache([HostComponent]$Project) {
@@ -1731,11 +1740,43 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
17311740
dispatch_DIR = "$DispatchBinaryCache\cmake\modules";
17321741
Foundation_DIR = "$FoundationBinaryCache\cmake\modules";
17331742
} + $TestingDefines)
1743+
}
1744+
}
1745+
1746+
function Build-SwiftTesting([Platform]$Platform, $Arch, [switch]$Test = $false) {
1747+
$SwiftTestingBinaryCache = Get-TargetProjectBinaryCache $Arch SwiftTesting
1748+
1749+
Isolate-EnvVars {
1750+
if ($Test) {
1751+
# TODO: Test
1752+
return
1753+
} else {
1754+
$Targets = @("default")
1755+
$InstallPath = "$($Arch.SwiftTestingInstallRoot)\usr"
1756+
}
1757+
1758+
Build-CMakeProject `
1759+
-Src $SourceCache\swift-testing `
1760+
-Bin $SwiftTestingBinaryCache `
1761+
-InstallTo $InstallPath `
1762+
-Arch $Arch `
1763+
-Platform $Platform `
1764+
-UseBuiltCompilers C,CXX,Swift `
1765+
-BuildTargets $Targets `
1766+
-Defines (@{
1767+
BUILD_SHARED_LIBS = "YES";
1768+
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
1769+
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
1770+
# FIXME: Build the plugin for the builder and specify the path.
1771+
SwiftTesting_MACRO = "NO";
1772+
})
1773+
}
1774+
}
17341775

1776+
function Write-PlatformInfoPlist($Arch) {
17351777
$PList = Join-Path -Path $Arch.PlatformInstallRoot -ChildPath "Info.plist"
1736-
Invoke-Program $python -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'XCTEST_VERSION': 'development', 'SWIFTC_FLAGS': ['-use-ld=lld'] } }), encoding='utf-8'))" `
1778+
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'))" `
17371779
-OutFile "$PList"
1738-
}
17391780
}
17401781

17411782
# Copies files installed by CMake from the arch-specific platform root,
@@ -2167,6 +2208,21 @@ function Build-SourceKitLSP($Arch) {
21672208
}
21682209
}
21692210

2211+
function Build-SwiftTestingMacros($Arch) {
2212+
Build-CMakeProject `
2213+
-Src $SourceCache\swift-testing\Sources\TestingMacros `
2214+
-Bin (Get-HostProjectBinaryCache SwiftTestingMacros) `
2215+
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2216+
-Arch $Arch `
2217+
-Platform Windows `
2218+
-UseBuiltCompilers Swift `
2219+
-SwiftSDK (Get-HostSwiftSDK) `
2220+
-BuildTargets default `
2221+
-Defines @{
2222+
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
2223+
}
2224+
}
2225+
21702226
function Install-HostToolchain() {
21712227
if ($ToBatch) { return }
21722228

@@ -2325,20 +2381,24 @@ if (-not $SkipBuild) {
23252381
Invoke-BuildStep Build-Dispatch Windows $Arch
23262382
Invoke-BuildStep Build-Foundation Windows $Arch
23272383
Invoke-BuildStep Build-XCTest Windows $Arch
2384+
Invoke-BuildStep Build-SwiftTesting Windows $Arch
2385+
Invoke-BuildStep Write-PlatformInfoPlist $Arch
23282386
}
23292387

2330-
foreach ($Arch in $AndroidSDKArchs) {
2331-
Invoke-BuildStep Build-ZLib Android $Arch
2332-
Invoke-BuildStep Build-XML2 Android $Arch
2333-
Invoke-BuildStep Build-CURL Android $Arch
2334-
Invoke-BuildStep Build-LLVM Android $Arch
2388+
foreach ($Arch in $AndroidSDKArchs) {
2389+
Invoke-BuildStep Build-ZLib Android $Arch
2390+
Invoke-BuildStep Build-XML2 Android $Arch
2391+
Invoke-BuildStep Build-CURL Android $Arch
2392+
Invoke-BuildStep Build-LLVM Android $Arch
23352393

2336-
# Build platform: SDK, Redist and XCTest
2337-
Invoke-BuildStep Build-Runtime Android $Arch
2338-
Invoke-BuildStep Build-Dispatch Android $Arch
2339-
Invoke-BuildStep Build-Foundation Android $Arch
2340-
Invoke-BuildStep Build-XCTest Android $Arch
2341-
}
2394+
# Build platform: SDK, Redist and XCTest
2395+
Invoke-BuildStep Build-Runtime Android $Arch
2396+
Invoke-BuildStep Build-Dispatch Android $Arch
2397+
Invoke-BuildStep Build-Foundation Android $Arch
2398+
Invoke-BuildStep Build-XCTest Android $Arch
2399+
Invoke-BuildStep Build-SwiftTesting Android $Arch
2400+
Invoke-BuildStep Write-PlatformInfoPlist $Arch
2401+
}
23422402
}
23432403

23442404
if (-not $ToBatch) {
@@ -2360,6 +2420,8 @@ if (-not $ToBatch) {
23602420
}
23612421

23622422
if (-not $SkipBuild) {
2423+
# TestingMacros can't be built before the standard library for the host as it is required for the Swift code.
2424+
Invoke-BuildStep Build-SwiftTestingMacros $HostArch
23632425
Invoke-BuildStep Build-SQLite $HostArch
23642426
Invoke-BuildStep Build-System $HostArch
23652427
Invoke-BuildStep Build-ToolsSupportCore $HostArch
@@ -2414,6 +2476,9 @@ if (-not $IsCrossCompiling) {
24142476
if ($Test -contains "xctest") {
24152477
Build-XCTest Windows $HostArch -Test
24162478
}
2479+
if ($Test -contains "testing") {
2480+
Build-SwiftTesting Windows $HostArch -Test
2481+
}
24172482
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
24182483
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
24192484
}

0 commit comments

Comments
 (0)