Skip to content

Commit d6ac1ec

Browse files
[windows][toolchain] Run non-executable Swift Runtime tests for Android (#79185)
We cross-compile the Swift runtime libs for the Android SDKs in the Windows toolchain. This patch adds a build step that runs non-executable tests for them.
1 parent d566903 commit d6ac1ec

File tree

4 files changed

+337
-40
lines changed

4 files changed

+337
-40
lines changed

test/lit.cfg

+27-23
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ elif platform.system() == 'Darwin':
239239
config.substitutions.append( ('%lto_flags', lto_flags) )
240240
config.substitutions.append( ('%use_just_built_liblto', use_just_built_liblto) )
241241
config.substitutions.append( ('%llvm_libs_dir', llvm_libs_dir) )
242-
config.substitutions.append( ('%llvm_plugin_ext', llvm_plugin_ext) )
242+
243+
if llvm_plugin_ext is not None:
244+
config.substitutions.append( ('%llvm_plugin_ext', llvm_plugin_ext) )
243245

244246
# Allow tests to restore the original environment if they need to.
245247
config.substitutions.append( ('%original_path_env', config.environment['PATH']) )
@@ -395,28 +397,6 @@ lit_config.note('Using resource dir: ' + test_resource_dir)
395397
test_clang_resource_dir = lit.util.executeCommand([config.clang, '-print-resource-dir'])[0].rstrip()
396398
lit_config.note('Using Clang resource dir: ' + test_clang_resource_dir)
397399

398-
config.swift_system_overlay_opt = ""
399-
config.clang_system_overlay_opt = ""
400-
config.windows_vfs_overlay_opt = ""
401-
if kIsWindows:
402-
# ucrt.modulemap currently requires -fbuiltin-headers-in-system-modules. -strict-implicit-module-context
403-
# is necessary for -Xcc arguments to be passed through ModuleInterfaceLoader.
404-
config.swift_system_overlay_opt = "-vfsoverlay {} -strict-implicit-module-context -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
405-
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
406-
)
407-
# this variant is for extract-symbolgraph which doesn't accept all the same arugments as swiftc
408-
# so the extra ceremony lets us pass in the relevant pieces needed for Windows SDK access.
409-
config.windows_vfs_overlay_opt = "-Xcc -vfsoverlay -Xcc {} -Xcc -strict-implicit-module-context -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
410-
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
411-
)
412-
config.clang_system_overlay_opt = "-Xcc -ivfsoverlay -Xcc {} -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
413-
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
414-
)
415-
config.substitutions.append( ('%windows_vfs_overlay_opt', config.windows_vfs_overlay_opt) )
416-
stdlib_resource_dir_opt = config.resource_dir_opt
417-
sourcekitd_framework_dir = config.swift_lib_dir
418-
config.substitutions.append( ('%test-resource-dir', test_resource_dir) )
419-
420400
# Parse the variant triple.
421401
# FIXME: We ought to parse 'run_environment' separately from 'run_os'.
422402
(run_cpu, run_vendor, run_os, run_vers) = re.match('([^-]+)-([^-]+)-([^0-9]+)(.*)', config.variant_triple).groups()
@@ -479,6 +459,28 @@ if test_sdk_overlay_dir is not None:
479459
lit_config.note('Using SDK overlay dir: ' + test_sdk_overlay_dir)
480460
config.resource_dir_opt += (" %s" % sdk_overlay_dir_opt)
481461

462+
config.swift_system_overlay_opt = ""
463+
config.clang_system_overlay_opt = ""
464+
config.windows_vfs_overlay_opt = ""
465+
if kIsWindows and run_os in ['windows-msvc']:
466+
# ucrt.modulemap currently requires -fbuiltin-headers-in-system-modules. -strict-implicit-module-context
467+
# is necessary for -Xcc arguments to be passed through ModuleInterfaceLoader.
468+
config.swift_system_overlay_opt = "-vfsoverlay {} -strict-implicit-module-context -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
469+
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
470+
)
471+
# this variant is for extract-symbolgraph which doesn't accept all the same arugments as swiftc
472+
# so the extra ceremony lets us pass in the relevant pieces needed for Windows SDK access.
473+
config.windows_vfs_overlay_opt = "-Xcc -vfsoverlay -Xcc {} -Xcc -strict-implicit-module-context -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
474+
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
475+
)
476+
config.clang_system_overlay_opt = "-Xcc -ivfsoverlay -Xcc {} -Xcc -Xclang -Xcc -fbuiltin-headers-in-system-modules".format(
477+
os.path.join(config.swift_obj_root, "stdlib", "windows-vfs-overlay.yaml")
478+
)
479+
config.substitutions.append( ('%windows_vfs_overlay_opt', config.windows_vfs_overlay_opt) )
480+
stdlib_resource_dir_opt = config.resource_dir_opt
481+
sourcekitd_framework_dir = config.swift_lib_dir
482+
config.substitutions.append( ('%test-resource-dir', test_resource_dir) )
483+
482484
# Default to Swift 4 for now.
483485
# Note that this accepts both `--param swift-version` (like the compiler flag)
484486
# and `--param swift_version` (like a lit configuration parameter).
@@ -1944,6 +1946,7 @@ elif run_os == 'linux-androideabi' or run_os == 'linux-android':
19441946
config.target_swift_symbolgraph_extract = ' '.join([
19451947
config.swift_symbolgraph_extract,
19461948
'-target', config.variant_triple,
1949+
'-sdk', config.variant_sdk, config.resource_dir_opt,
19471950
mcp_opt])
19481951
config.target_swift_synthesize_interface = ' '.join([
19491952
config.swift_synthesize_interface,
@@ -2747,6 +2750,7 @@ config.substitutions.insert(0, ('%check-c-header-in-clang',
27472750
# Verifies that a C++ file can be compiled without warnings except for some exceptions.
27482751
config.substitutions.insert(0, ('%check-cxx-header-in-clang',
27492752
'%clangxx -fsyntax-only -x c++-header ' + extraCheckWarningFlags +
2753+
' --sysroot %r ' % config.variant_sdk +
27502754
# Use standard header/framework search paths.
27512755
'-F %%clang-importer-sdk-path/frameworks '
27522756
'-I %%clang-include-dir %%cxx-stdlib-include '

test/refactoring/lit.local.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
config.substitutions.append((r'%refactor-check-compiles', f'{config.python} {config.refactor_check_compiles} -swift-refactor {config.swift_refactor} -swift-frontend {config.swift_frontend} -temp-dir %t {config.resource_dir_opt}'))
2-
config.substitutions.append((r'%refactor', f'{config.swift_refactor} {config.resource_dir_opt}'))
1+
config.substitutions.append((r'%refactor-check-compiles', f'{config.python} {config.refactor_check_compiles} -swift-refactor {config.swift_refactor} -swift-frontend {config.swift_frontend} -temp-dir %t {config.resource_dir_opt} -target {config.variant_triple}'))
2+
config.substitutions.append((r'%refactor', f'{config.swift_refactor} {config.resource_dir_opt} -target {config.variant_triple}'))

utils/build.ps1

+60-15
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,24 @@ function Write-PList {
16421642
-OutFile $Path
16431643
}
16441644

1645+
function Load-LitTestOverrides($Filename) {
1646+
function Select-LitTestOverrides($Prefix) {
1647+
$MatchingLines = Get-Content $Filename | Select-String -Pattern "`^${Prefix}.*$"
1648+
return $MatchingLines | ForEach-Object { ($_ -replace $Prefix,"").Trim() }
1649+
}
1650+
1651+
$TestsToXFail = Select-LitTestOverrides "xfail"
1652+
Write-Host "TestsToXFail=$TestsToXFail"
1653+
if ($TestsToXFail -and $TestsToXFail.Length -ne 0) {
1654+
$env:LIT_XFAIL = $TestsToXFail -join ";"
1655+
}
1656+
$TestsToSkip = Select-LitTestOverrides "skip"
1657+
Write-Host "TestsToSkip=$TestsToSkip"
1658+
if ($TestsToSkip -and $TestsToSkip.Length -gt 0) {
1659+
$env:LIT_FILTER_OUT = "($($TestsToSkip -join '|'))"
1660+
}
1661+
}
1662+
16451663
function Build-Compilers() {
16461664
[CmdletBinding(PositionalBinding = $false)]
16471665
param
@@ -1681,19 +1699,8 @@ function Build-Compilers() {
16811699
if ($TestLLDB) {
16821700
$Targets += @("check-lldb")
16831701

1684-
function Select-LitTestOverrides {
1685-
param([string] $TestStatus)
1686-
1687-
$MatchingLines=(Get-Content $PSScriptRoot/windows-llvm-lit-test-overrides.txt | Select-String -Pattern "`^${TestStatus}.*$")
1688-
$TestNames=$MatchingLines | ForEach-Object { ($_ -replace $TestStatus,"").Trim() }
1689-
return $TestNames
1690-
}
1691-
1692-
# Override some test results with llvm-lit.
1693-
$TestsToXFail=Select-LitTestOverrides "xfail"
1694-
$TestsToSkip=Select-LitTestOverrides "skip"
1695-
$env:LIT_XFAIL=$TestsToXFail -join ";"
1696-
$env:LIT_FILTER_OUT="($($TestsToSkip -join '|'))"
1702+
# Override test filter for known issues in downstream LLDB
1703+
Load-LitTestOverrides $PSScriptRoot/windows-llvm-lit-test-overrides.txt
16971704

16981705
# Transitive dependency of _lldb.pyd
16991706
$RuntimeBinaryCache = Get-TargetProjectBinaryCache $Arch Runtime
@@ -2143,8 +2150,6 @@ function Build-Runtime([Platform]$Platform, $Arch) {
21432150
$PlatformDefines += @{
21442151
LLVM_ENABLE_LIBCXX = "YES";
21452152
SWIFT_USE_LINKER = "lld";
2146-
SWIFT_INCLUDE_TESTS = "NO";
2147-
SWIFT_INCLUDE_TEST_BINARIES = "NO";
21482153
# Clang[<18] doesn't provide the _Builtin_float module.
21492154
SWIFT_BUILD_CLANG_OVERLAYS_SKIP_BUILTIN_FLOAT = "YES";
21502155
}
@@ -2188,6 +2193,40 @@ function Build-Runtime([Platform]$Platform, $Arch) {
21882193
}
21892194
}
21902195

2196+
function Test-Runtime([Platform]$Platform, $Arch) {
2197+
if ($IsCrossCompiling) {
2198+
throw "Swift runtime tests are not supported when cross-compiling"
2199+
}
2200+
if (-not (Test-Path (Get-TargetProjectBinaryCache $Arch Runtime))) {
2201+
throw "Swift runtime tests are supposed to reconfigure the existing build"
2202+
}
2203+
$CompilersBinaryCache = Get-HostProjectBinaryCache Compilers
2204+
if (-not (Test-Path "$CompilersBinaryCache\bin\FileCheck.exe")) {
2205+
# These will exist if we test any of llvm/clang/lldb/lld/swift as well
2206+
throw "LIT test utilities not found in $CompilersBinaryCache\bin"
2207+
}
2208+
2209+
Invoke-IsolatingEnvVars {
2210+
# Filter known issues when testing on Windows
2211+
Load-LitTestOverrides $PSScriptRoot/windows-swift-android-lit-test-overrides.txt
2212+
$env:Path = "$(Get-CMarkBinaryCache $Arch)\src;$(Get-PinnedToolchainRuntime);${env:Path};$UnixToolsBinDir"
2213+
Build-CMakeProject `
2214+
-Src $SourceCache\swift `
2215+
-Bin (Get-TargetProjectBinaryCache $Arch Runtime) `
2216+
-Arch $Arch `
2217+
-Platform $Platform `
2218+
-UseBuiltCompilers C,CXX,Swift `
2219+
-BuildTargets check-swift-validation-only_non_executable `
2220+
-Defines @{
2221+
SWIFT_INCLUDE_TESTS = "YES";
2222+
SWIFT_INCLUDE_TEST_BINARIES = "YES";
2223+
SWIFT_BUILD_TEST_SUPPORT_MODULES = "YES";
2224+
SWIFT_NATIVE_LLVM_TOOLS_PATH = Join-Path -Path $CompilersBinaryCache -ChildPath "bin";
2225+
LLVM_LIT_ARGS = "-vv";
2226+
}
2227+
}
2228+
}
2229+
21912230
function Build-ExperimentalRuntime {
21922231
[CmdletBinding(PositionalBinding = $false)]
21932232
param
@@ -3327,6 +3366,12 @@ if (-not $IsCrossCompiling) {
33273366
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
33283367
if ($Test -contains "swift-format") { Test-Format }
33293368
if ($Test -contains "sourcekit-lsp") { Test-SourceKitLSP }
3369+
3370+
if ($Test -contains "swift") {
3371+
foreach ($Arch in $AndroidSDKArchs) {
3372+
Test-Runtime Android $Arch
3373+
}
3374+
}
33303375
}
33313376

33323377
# Custom exception printing for more detailed exception information

0 commit comments

Comments
 (0)