Skip to content

Commit 1c6552f

Browse files
authored
Merge pull request #75515 from rintaro/add-swift-testing
Build and install swift-testing in toolchains
2 parents 0e2a8bd + e98c5ea commit 1c6552f

File tree

11 files changed

+374
-20
lines changed

11 files changed

+374
-20
lines changed

utils/build-presets.ini

+21
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ sourcekit-lsp
383383
# swift-inspect
384384
swiftsyntax
385385
swiftformat
386+
swift-testing
387+
swift-testing-macros
386388

387389
skstresstester
388390

@@ -406,6 +408,8 @@ install-swiftpm
406408
install-swift-driver
407409
install-swiftsyntax
408410
install-swiftformat
411+
install-swift-testing
412+
install-swift-testing-macros
409413

410414
[preset: buildbot_incremental,tools=RA,stdlib=RA,apple_silicon]
411415
mixin-preset=buildbot_incremental,tools=RA,stdlib=RA
@@ -839,6 +843,8 @@ mixin-preset=
839843
llbuild
840844
swiftpm
841845
swift-driver
846+
swift-testing
847+
swift-testing-macros
842848
xctest
843849
swiftdocc
844850
swiftformat
@@ -852,6 +858,8 @@ install-llbuild
852858
install-swiftpm
853859
install-swift-driver
854860
install-swiftsyntax
861+
install-swift-testing
862+
install-swift-testing-macros
855863
install-xctest
856864
install-prefix=/usr
857865
install-sourcekit-lsp
@@ -1180,12 +1188,15 @@ llbuild
11801188
swiftpm
11811189
swift-driver
11821190
xctest
1191+
swift-testing
1192+
swift-testing-macros
11831193
foundation
11841194
libdispatch
11851195
swiftsyntax
11861196
swiftformat
11871197
indexstore-db
11881198
sourcekit-lsp
1199+
11891200
install-llvm
11901201
install-static-linux-config
11911202
install-swift
@@ -1196,6 +1207,8 @@ install-swiftsyntax
11961207
install-foundation
11971208
install-libdispatch
11981209
install-xctest
1210+
install-swift-testing
1211+
install-swift-testing-macros
11991212
install-swiftformat
12001213

12011214
[preset: buildbot_incremental_linux,long_test]
@@ -1319,6 +1332,8 @@ swift-driver
13191332
# Failing to build in CI: rdar://78408440
13201333
# swift-inspect
13211334
swiftsyntax
1335+
swift-testing
1336+
swift-testing-macros
13221337
swiftformat
13231338
playgroundsupport
13241339
indexstore-db
@@ -1363,6 +1378,8 @@ install-llbuild
13631378
install-swiftpm
13641379
install-swift-driver
13651380
install-swiftsyntax
1381+
install-swift-testing
1382+
install-swift-testing-macros
13661383
install-playgroundsupport
13671384
install-sourcekit-lsp
13681385
install-swiftformat
@@ -1686,6 +1703,8 @@ swiftpm
16861703
# swift-inspect
16871704
swift-driver
16881705
swiftsyntax
1706+
swift-testing
1707+
swift-testing-macros
16891708
swiftformat
16901709
swiftdocc
16911710

@@ -1705,6 +1724,8 @@ install-llbuild
17051724
install-swiftpm
17061725
install-swift-driver
17071726
install-swiftsyntax
1727+
install-swift-testing
1728+
install-swift-testing-macros
17081729
install-swiftdocc
17091730
install-swiftformat
17101731

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) {
@@ -1749,11 +1758,43 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
17491758
dispatch_DIR = "$DispatchBinaryCache\cmake\modules";
17501759
Foundation_DIR = "$FoundationBinaryCache\cmake\modules";
17511760
} + $TestingDefines)
1761+
}
1762+
}
1763+
1764+
function Build-SwiftTesting([Platform]$Platform, $Arch, [switch]$Test = $false) {
1765+
$SwiftTestingBinaryCache = Get-TargetProjectBinaryCache $Arch SwiftTesting
1766+
1767+
Isolate-EnvVars {
1768+
if ($Test) {
1769+
# TODO: Test
1770+
return
1771+
} else {
1772+
$Targets = @("default")
1773+
$InstallPath = "$($Arch.SwiftTestingInstallRoot)\usr"
1774+
}
1775+
1776+
Build-CMakeProject `
1777+
-Src $SourceCache\swift-testing `
1778+
-Bin $SwiftTestingBinaryCache `
1779+
-InstallTo $InstallPath `
1780+
-Arch $Arch `
1781+
-Platform $Platform `
1782+
-UseBuiltCompilers C,CXX,Swift `
1783+
-BuildTargets $Targets `
1784+
-Defines (@{
1785+
BUILD_SHARED_LIBS = "YES";
1786+
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
1787+
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
1788+
# FIXME: Build the plugin for the builder and specify the path.
1789+
SwiftTesting_MACRO = "NO";
1790+
})
1791+
}
1792+
}
17521793

1794+
function Write-PlatformInfoPlist($Arch) {
17531795
$PList = Join-Path -Path $Arch.PlatformInstallRoot -ChildPath "Info.plist"
1754-
Invoke-Program $python -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'XCTEST_VERSION': 'development', 'SWIFTC_FLAGS': ['-use-ld=lld'] } }), encoding='utf-8'))" `
1796+
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'))" `
17551797
-OutFile "$PList"
1756-
}
17571798
}
17581799

17591800
# Copies files installed by CMake from the arch-specific platform root,
@@ -2185,6 +2226,21 @@ function Build-SourceKitLSP($Arch) {
21852226
}
21862227
}
21872228

2229+
function Build-SwiftTestingMacros($Arch) {
2230+
Build-CMakeProject `
2231+
-Src $SourceCache\swift-testing\Sources\TestingMacros `
2232+
-Bin (Get-HostProjectBinaryCache SwiftTestingMacros) `
2233+
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2234+
-Arch $Arch `
2235+
-Platform Windows `
2236+
-UseBuiltCompilers Swift `
2237+
-SwiftSDK (Get-HostSwiftSDK) `
2238+
-BuildTargets default `
2239+
-Defines @{
2240+
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
2241+
}
2242+
}
2243+
21882244
function Install-HostToolchain() {
21892245
if ($ToBatch) { return }
21902246

@@ -2343,20 +2399,24 @@ if (-not $SkipBuild) {
23432399
Invoke-BuildStep Build-Dispatch Windows $Arch
23442400
Invoke-BuildStep Build-Foundation Windows $Arch
23452401
Invoke-BuildStep Build-XCTest Windows $Arch
2402+
Invoke-BuildStep Build-SwiftTesting Windows $Arch
2403+
Invoke-BuildStep Write-PlatformInfoPlist $Arch
23462404
}
23472405

2348-
foreach ($Arch in $AndroidSDKArchs) {
2349-
Invoke-BuildStep Build-ZLib Android $Arch
2350-
Invoke-BuildStep Build-XML2 Android $Arch
2351-
Invoke-BuildStep Build-CURL Android $Arch
2352-
Invoke-BuildStep Build-LLVM Android $Arch
2406+
foreach ($Arch in $AndroidSDKArchs) {
2407+
Invoke-BuildStep Build-ZLib Android $Arch
2408+
Invoke-BuildStep Build-XML2 Android $Arch
2409+
Invoke-BuildStep Build-CURL Android $Arch
2410+
Invoke-BuildStep Build-LLVM Android $Arch
23532411

2354-
# Build platform: SDK, Redist and XCTest
2355-
Invoke-BuildStep Build-Runtime Android $Arch
2356-
Invoke-BuildStep Build-Dispatch Android $Arch
2357-
Invoke-BuildStep Build-Foundation Android $Arch
2358-
Invoke-BuildStep Build-XCTest Android $Arch
2359-
}
2412+
# Build platform: SDK, Redist and XCTest
2413+
Invoke-BuildStep Build-Runtime Android $Arch
2414+
Invoke-BuildStep Build-Dispatch Android $Arch
2415+
Invoke-BuildStep Build-Foundation Android $Arch
2416+
Invoke-BuildStep Build-XCTest Android $Arch
2417+
Invoke-BuildStep Build-SwiftTesting Android $Arch
2418+
Invoke-BuildStep Write-PlatformInfoPlist $Arch
2419+
}
23602420
}
23612421

23622422
if (-not $ToBatch) {
@@ -2378,6 +2438,8 @@ if (-not $ToBatch) {
23782438
}
23792439

23802440
if (-not $SkipBuild) {
2441+
# TestingMacros can't be built before the standard library for the host as it is required for the Swift code.
2442+
Invoke-BuildStep Build-SwiftTestingMacros $HostArch
23812443
Invoke-BuildStep Build-SQLite $HostArch
23822444
Invoke-BuildStep Build-System $HostArch
23832445
Invoke-BuildStep Build-ToolsSupportCore $HostArch
@@ -2432,6 +2494,9 @@ if (-not $IsCrossCompiling) {
24322494
if ($Test -contains "xctest") {
24332495
Build-XCTest Windows $HostArch -Test
24342496
}
2497+
if ($Test -contains "testing") {
2498+
Build-SwiftTesting Windows $HostArch -Test
2499+
}
24352500
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
24362501
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
24372502
}

utils/build_swift/build_swift/driver_arguments.py

+10
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,16 @@ def create_argument_parser():
809809
option(['--wasmkit'], toggle_true('build_wasmkit'),
810810
help='build WasmKit')
811811

812+
option('--swift-testing', toggle_true('build_swift_testing'),
813+
help='build Swift Testing')
814+
option('--install-swift-testing', toggle_true('install_swift_testing'),
815+
help='install Swift Testing')
816+
option('--swift-testing-macros', toggle_true('build_swift_testing_macros'),
817+
help='build Swift Testing macro plugin')
818+
option('--install-swift-testing-macros',
819+
toggle_true('install_swift_testing_macros'),
820+
help='install Swift Testing macro plugin')
821+
812822
option('--xctest', toggle_true('build_xctest'),
813823
help='build xctest')
814824

utils/build_swift/tests/expected_options.py

+9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
'build_swiftpm': False,
9696
'build_swift_driver': False,
9797
'build_swift_libexec': True,
98+
'build_swift_testing': False,
99+
'build_swift_testing_macros': False,
98100
'build_early_swift_driver': True,
99101
'build_early_swiftsyntax': True,
100102
'build_swiftsyntax': False,
@@ -111,6 +113,8 @@
111113
'install_static_linux_config': False,
112114
'install_swiftpm': False,
113115
'install_swiftsyntax': False,
116+
'install_swift_testing': False,
117+
'install_swift_testing_macros': False,
114118
'install_swift_driver': False,
115119
'install_swiftdocc': False,
116120
'swiftsyntax_verify_generated_files': False,
@@ -566,6 +570,8 @@ class BuildScriptImplOption(_BaseOption):
566570
SetTrueOption('--swiftpm', dest='build_swiftpm'),
567571
SetTrueOption('--swift-driver', dest='build_swift_driver'),
568572
SetTrueOption('--swiftsyntax', dest='build_swiftsyntax'),
573+
SetTrueOption('--swift-testing', dest='build_swift_testing'),
574+
SetTrueOption('--swift-testing-macros', dest='build_swift_testing_macros'),
569575
SetTrueOption('--skstresstester', dest='build_skstresstester'),
570576
SetTrueOption('--swiftformat', dest='build_swiftformat'),
571577
SetTrueOption('--swiftdocc', dest='build_swiftdocc'),
@@ -646,6 +652,9 @@ class BuildScriptImplOption(_BaseOption):
646652
EnableOption('--install-llvm', dest='install_llvm'),
647653
EnableOption('--install-static-linux-config', dest='install_static_linux_config'),
648654
EnableOption('--install-swiftsyntax', dest='install_swiftsyntax'),
655+
EnableOption('--install-swift-testing', dest='install_swift_testing'),
656+
EnableOption('--install-swift-testing-macros',
657+
dest='install_swift_testing_macros'),
649658
EnableOption('--swiftsyntax-verify-generated-files',
650659
dest='swiftsyntax_verify_generated_files'),
651660
EnableOption('--swiftsyntax-enable-rawsyntax-validation',

utils/swift_build_support/swift_build_support/build_script_invocation.py

+4
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,10 @@ def compute_product_pipelines(self):
678678
is_enabled=self.args.build_foundation)
679679
builder.add_product(products.SwiftSyntax,
680680
is_enabled=self.args.build_swiftsyntax)
681+
builder.add_product(products.SwiftTestingMacros,
682+
is_enabled=self.args.build_swift_testing_macros)
683+
builder.add_product(products.SwiftTesting,
684+
is_enabled=self.args.build_swift_testing)
681685
builder.add_product(products.SwiftFormat,
682686
is_enabled=self.args.build_swiftformat)
683687
builder.add_product(products.SKStressTester,

utils/swift_build_support/swift_build_support/productpipeline_list_builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def add_product(self, product_cls, is_enabled):
101101
self.current_pipeline.append(product_cls, is_enabled)
102102

103103
def add_impl_product(self, product_cls, is_enabled):
104-
"""Add a non-impl product to the current pipeline begin constructed"""
104+
"""Add an impl product to the current pipeline begin constructed"""
105105
assert self.current_pipeline is not None
106106
assert self.is_current_pipeline_impl
107107
assert product_cls.is_build_script_impl_product()

utils/swift_build_support/swift_build_support/products/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
from .sourcekitlsp import SourceKitLSP
3131
from .staticswiftlinux import StaticSwiftLinuxConfig
3232
from .swift import Swift
33+
from .swift_testing import SwiftTesting
34+
from .swift_testing_macros import SwiftTestingMacros
3335
from .swiftdocc import SwiftDocC
3436
from .swiftdoccrender import SwiftDocCRender
3537
from .swiftdriver import SwiftDriver
@@ -68,6 +70,8 @@
6870
'SwiftInspect',
6971
'SwiftPM',
7072
'SwiftDriver',
73+
'SwiftTesting',
74+
'SwiftTestingMacros',
7175
'EarlySwiftDriver',
7276
'XCTest',
7377
'SwiftSyntax',

0 commit comments

Comments
 (0)