Skip to content

Commit 222fd1d

Browse files
[6.0] Build and install swift-testing in toolchains (swiftlang#75837)
* Add swift-testing to update-checkout (cherry picked from commit 19910c6) * Build script changes to begin building and installing swift-testing into toolchains (on Darwin, so far) (cherry picked from commit 97e85a6) * Add swift-testing to Linux presets too (cherry picked from commit ff5ece1) * Improve description of new build-script flags (cherry picked from commit c8d7d13) * Fix header comment (cherry picked from commit 155e4c8) * [swift-testing] Build tweak * Remove SwiftSyntax product dependency * Correct CMAKE_BUILD_TYPE (cherry picked from commit e06d38b) * [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) * [build-preset] Add swift-testing to incrmental bots (cherry picked from commit 6a38329) * [build-script] Separate SwiftTestinMacros from SwiftTesting product Also, build them for all hosts including cross compiling host. (cherry picked from commit e98c5ea) * [6.0] Add swift-testing to update-checkout-config.json To release/6.0 scheme. * [build-script] Fix product dependencies SwiftPM now depends on `SwiftTesting`, `SwiftTesting` depends on `SwiftTestingMacros` rdar://133946466 (cherry picked from commit 852aa77) --------- Co-authored-by: Stuart Montgomery <[email protected]>
1 parent 6a46c2d commit 222fd1d

12 files changed

+363
-10
lines changed

utils/build-presets.ini

+21
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ sourcekit-lsp
379379
# swift-inspect
380380
swiftsyntax
381381
swiftformat
382+
swift-testing
383+
swift-testing-macros
382384

383385
skstresstester
384386

@@ -402,6 +404,8 @@ install-swiftpm
402404
install-swift-driver
403405
install-swiftsyntax
404406
install-swiftformat
407+
install-swift-testing
408+
install-swift-testing-macros
405409

406410
[preset: buildbot_incremental,tools=RA,stdlib=RA,apple_silicon]
407411
mixin-preset=buildbot_incremental,tools=RA,stdlib=RA
@@ -835,6 +839,8 @@ mixin-preset=
835839
llbuild
836840
swiftpm
837841
swift-driver
842+
swift-testing
843+
swift-testing-macros
838844
xctest
839845
libicu
840846
swiftdocc
@@ -849,6 +855,8 @@ install-llbuild
849855
install-swiftpm
850856
install-swift-driver
851857
install-swiftsyntax
858+
install-swift-testing
859+
install-swift-testing-macros
852860
install-xctest
853861
install-libicu
854862
install-prefix=/usr
@@ -1169,12 +1177,15 @@ llbuild
11691177
swiftpm
11701178
swift-driver
11711179
xctest
1180+
swift-testing
1181+
swift-testing-macros
11721182
foundation
11731183
libdispatch
11741184
swiftsyntax
11751185
swiftformat
11761186
indexstore-db
11771187
sourcekit-lsp
1188+
11781189
install-llvm
11791190
install-static-linux-config
11801191
install-swift
@@ -1186,6 +1197,8 @@ install-swiftsyntax
11861197
install-foundation
11871198
install-libdispatch
11881199
install-xctest
1200+
install-swift-testing
1201+
install-swift-testing-macros
11891202
install-swiftformat
11901203

11911204
[preset: buildbot_incremental_linux,long_test]
@@ -1309,6 +1322,8 @@ swift-driver
13091322
# Failing to build in CI: rdar://78408440
13101323
# swift-inspect
13111324
swiftsyntax
1325+
swift-testing
1326+
swift-testing-macros
13121327
swiftformat
13131328
playgroundsupport
13141329
indexstore-db
@@ -1351,6 +1366,8 @@ install-llbuild
13511366
install-swiftpm
13521367
install-swift-driver
13531368
install-swiftsyntax
1369+
install-swift-testing
1370+
install-swift-testing-macros
13541371
install-playgroundsupport
13551372
install-sourcekit-lsp
13561373
install-swiftformat
@@ -1652,6 +1669,8 @@ swiftpm
16521669
# swift-inspect
16531670
swift-driver
16541671
swiftsyntax
1672+
swift-testing
1673+
swift-testing-macros
16551674
swiftformat
16561675
swiftdocc
16571676

@@ -1671,6 +1690,8 @@ install-llbuild
16711690
install-swiftpm
16721691
install-swift-driver
16731692
install-swiftsyntax
1693+
install-swift-testing
1694+
install-swift-testing-macros
16741695
install-swiftdocc
16751696
install-swiftformat
16761697

utils/build.ps1

+61-2
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) {
@@ -311,6 +315,7 @@ enum HostComponent {
311315
LMDB
312316
SymbolKit
313317
DocC
318+
SwiftTestingMacros
314319
}
315320

316321
function Get-HostProjectBinaryCache([HostComponent]$Project) {
@@ -1548,11 +1553,43 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
15481553
dispatch_DIR = "$DispatchBinaryCache\cmake\modules";
15491554
Foundation_DIR = "$FoundationBinaryCache\cmake\modules";
15501555
} + $TestingDefines)
1556+
}
1557+
}
1558+
1559+
function Build-SwiftTesting([Platform]$Platform, $Arch, [switch]$Test = $false) {
1560+
$SwiftTestingBinaryCache = Get-TargetProjectBinaryCache $Arch SwiftTesting
1561+
1562+
Isolate-EnvVars {
1563+
if ($Test) {
1564+
# TODO: Test
1565+
return
1566+
} else {
1567+
$Targets = @("default")
1568+
$InstallPath = "$($Arch.SwiftTestingInstallRoot)\usr"
1569+
}
15511570

1571+
Build-CMakeProject `
1572+
-Src $SourceCache\swift-testing `
1573+
-Bin $SwiftTestingBinaryCache `
1574+
-InstallTo $InstallPath `
1575+
-Arch $Arch `
1576+
-Platform $Platform `
1577+
-UseBuiltCompilers C,CXX,Swift `
1578+
-BuildTargets $Targets `
1579+
-Defines (@{
1580+
BUILD_SHARED_LIBS = "YES";
1581+
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
1582+
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
1583+
# FIXME: Build the plugin for the builder and specify the path.
1584+
SwiftTesting_MACRO = "NO";
1585+
})
1586+
}
1587+
}
1588+
1589+
function Write-PlatformInfoPlist([Platform]$Platform, $Arch) {
15521590
$PList = [IO.Path]::Combine($Arch.BinaryCache, "${Platform}.platform".ToLower(), "Info.plist")
1553-
Invoke-Program $python -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'XCTEST_VERSION': 'development', 'SWIFTC_FLAGS': ['-use-ld=lld'] } }), encoding='utf-8'))" `
1591+
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'))" `
15541592
-OutFile "$PList"
1555-
}
15561593
}
15571594

15581595
# Copies files installed by CMake from the arch-specific platform root,
@@ -1956,6 +1993,21 @@ function Build-SourceKitLSP($Arch) {
19561993
}
19571994
}
19581995

1996+
function Build-SwiftTestingMacros($Arch) {
1997+
Build-CMakeProject `
1998+
-Src $SourceCache\swift-testing\Sources\TestingMacros `
1999+
-Bin (Get-HostProjectBinaryCache SwiftTestingMacros) `
2000+
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2001+
-Arch $Arch `
2002+
-Platform Windows `
2003+
-UseBuiltCompilers Swift `
2004+
-SwiftSDK ([IO.Path]::Combine((Get-InstallDir $HostArch), "Platforms", "Windows.platform", "Developer", "SDKs", "Windows.sdk")) `
2005+
-BuildTargets default `
2006+
-Defines @{
2007+
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
2008+
}
2009+
}
2010+
19592011
function Install-HostToolchain() {
19602012
if ($ToBatch) { return }
19612013

@@ -2116,6 +2168,8 @@ if (-not $SkipBuild) {
21162168
Invoke-BuildStep Build-FoundationMacros -Build Windows $BuildArch
21172169
Invoke-BuildStep Build-Foundation Windows $Arch
21182170
Invoke-BuildStep Build-XCTest Windows $Arch
2171+
Invoke-BuildStep Build-SwiftTesting Windows $Arch
2172+
Invoke-BuildStep Write-PlatformInfoPlist Windows $Arch
21192173
}
21202174
}
21212175

@@ -2139,6 +2193,8 @@ if (-not $ToBatch) {
21392193
}
21402194

21412195
if (-not $SkipBuild) {
2196+
# TestingMacros can't be built before the standard library for the host as it is required for the Swift code.
2197+
Invoke-BuildStep Build-SwiftTestingMacros $HostArch
21422198
Invoke-BuildStep Build-SQLite $HostArch
21432199
Invoke-BuildStep Build-System $HostArch
21442200
Invoke-BuildStep Build-ToolsSupportCore $HostArch
@@ -2193,6 +2249,9 @@ if (-not $IsCrossCompiling) {
21932249
if ($Test -contains "xctest") {
21942250
Build-XCTest Windows $HostArch -Test
21952251
}
2252+
if ($Test -contains "testing") {
2253+
Build-SwiftTesting Windows $HostArch -Test
2254+
}
21962255
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
21972256
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
21982257
}

utils/build_swift/build_swift/driver_arguments.py

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

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

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,
@@ -565,6 +569,8 @@ class BuildScriptImplOption(_BaseOption):
565569
SetTrueOption('--swiftpm', dest='build_swiftpm'),
566570
SetTrueOption('--swift-driver', dest='build_swift_driver'),
567571
SetTrueOption('--swiftsyntax', dest='build_swiftsyntax'),
572+
SetTrueOption('--swift-testing', dest='build_swift_testing'),
573+
SetTrueOption('--swift-testing-macros', dest='build_swift_testing_macros'),
568574
SetTrueOption('--skstresstester', dest='build_skstresstester'),
569575
SetTrueOption('--swiftformat', dest='build_swiftformat'),
570576
SetTrueOption('--swiftdocc', dest='build_swiftdocc'),
@@ -644,6 +650,9 @@ class BuildScriptImplOption(_BaseOption):
644650
EnableOption('--install-llvm', dest='install_llvm'),
645651
EnableOption('--install-static-linux-config', dest='install_static_linux_config'),
646652
EnableOption('--install-swiftsyntax', dest='install_swiftsyntax'),
653+
EnableOption('--install-swift-testing', dest='install_swift_testing'),
654+
EnableOption('--install-swift-testing-macros',
655+
dest='install_swift_testing_macros'),
647656
EnableOption('--swiftsyntax-verify-generated-files',
648657
dest='swiftsyntax_verify_generated_files'),
649658
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
@@ -662,6 +662,10 @@ def compute_product_pipelines(self):
662662
# Begin the post build-script-impl build phase.
663663
builder.begin_pipeline()
664664

665+
builder.add_product(products.SwiftTestingMacros,
666+
is_enabled=self.args.build_swift_testing_macros)
667+
builder.add_product(products.SwiftTesting,
668+
is_enabled=self.args.build_swift_testing)
665669
builder.add_product(products.SwiftPM,
666670
is_enabled=self.args.build_swiftpm)
667671
builder.add_product(products.SwiftSyntax,

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
@@ -65,6 +67,8 @@
6567
'SwiftInspect',
6668
'SwiftPM',
6769
'SwiftDriver',
70+
'SwiftTesting',
71+
'SwiftTestingMacros',
6872
'EarlySwiftDriver',
6973
'XCTest',
7074
'SwiftSyntax',

utils/swift_build_support/swift_build_support/products/product.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ def target_for_platform(self, platform, arch, include_version=True):
293293
arch, self.args.darwin_deployment_version_xros)
294294
return target
295295

296-
def generate_darwin_toolchain_file(self, platform, arch):
296+
def generate_darwin_toolchain_file(self, platform, arch,
297+
macos_deployment_version=None):
297298
"""
298299
Generates a new CMake tolchain file that specifies Darwin as a target
299300
plaftorm.
@@ -306,9 +307,14 @@ def generate_darwin_toolchain_file(self, platform, arch):
306307

307308
cmake_osx_sysroot = xcrun.sdk_path(platform)
308309

309-
target = self.target_for_platform(platform, arch)
310-
if not target:
311-
raise RuntimeError('Unhandled platform {}?!'.format(platform))
310+
if platform == 'macosx':
311+
if macos_deployment_version is None:
312+
macos_deployment_version = self.args.darwin_deployment_version_osx
313+
target = '{}-apple-macosx{}'.format(arch, macos_deployment_version)
314+
else:
315+
target = self.target_for_platform(platform, arch)
316+
if not target:
317+
raise RuntimeError('Unhandled platform {}?!'.format(platform))
312318

313319
toolchain_args = {}
314320

@@ -429,7 +435,8 @@ def generate_linux_toolchain_file(self, platform, arch):
429435

430436
return toolchain_file
431437

432-
def generate_toolchain_file_for_darwin_or_linux(self, host_target):
438+
def generate_toolchain_file_for_darwin_or_linux(
439+
self, host_target, override_macos_deployment_version=None):
433440
"""
434441
Checks `host_target` platform and generates a new CMake tolchain file
435442
appropriate for that target plaftorm (either Darwin or Linux). Defines
@@ -448,7 +455,9 @@ def generate_toolchain_file_for_darwin_or_linux(self, host_target):
448455

449456
toolchain_file = None
450457
if self.is_darwin_host(host_target):
451-
toolchain_file = self.generate_darwin_toolchain_file(platform, arch)
458+
toolchain_file = self.generate_darwin_toolchain_file(
459+
platform, arch,
460+
macos_deployment_version=override_macos_deployment_version)
452461
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
453462
elif platform == "linux":
454463
toolchain_file = self.generate_linux_toolchain_file(platform, arch)

0 commit comments

Comments
 (0)