Skip to content

Commit 2d21e53

Browse files
committed
[Windows] Build swift-format using SwiftPM from build.ps1 and run tests
The primary motivation is to run swift-format tests on Windows using 'swift test'. Since we now have infrastructure for testing swift-format using SwiftPM, we should also use it to build swift-format to be included in the toolchain because (1) it means we don't need to build SwiftFormat twice, (2) we test the same build that is also included in the toolchain and (3) it allows us to remove the CMake build of swift-format.
1 parent 106e05f commit 2d21e53

File tree

1 file changed

+48
-19
lines changed

1 file changed

+48
-19
lines changed

utils/build.ps1

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ if ($AndroidSDKs.Length -gt 0) {
218218

219219
if ($Test -contains "*") {
220220
# Explicitly don't include llbuild yet since tests are known to fail on Windows
221-
$Test = @("swift", "dispatch", "foundation", "xctest")
221+
$Test = @("swift", "dispatch", "foundation", "xctest", "swift-format")
222222
}
223223

224224
# Architecture definitions
@@ -1258,6 +1258,14 @@ function Build-SPMProject {
12581258

12591259
$Action = if ($Test) { "test" } else { "build" }
12601260
Invoke-Program "$($HostArch.ToolchainInstallRoot)\usr\bin\swift.exe" $Action @Arguments @AdditionalArguments
1261+
1262+
if ($InstallExe -ne "") {
1263+
$BinPath = (Invoke-Program "$($HostArch.ToolchainInstallRoot)\usr\bin\swift.exe" build @Arguments --show-bin-path)
1264+
$ExecPath = Join-Path -Path $BinPath -ChildPath $InstallExe
1265+
$InstallDestination = "$($Arch.ToolchainInstallRoot)\usr\bin"
1266+
Write-Host "Installing $($ExecPath) to $($InstallDestination)"
1267+
Copy-Item -Path $ExecPath -Destination $InstallDestination
1268+
}
12611269
}
12621270

12631271
if (-not $ToBatch) {
@@ -2348,23 +2356,43 @@ function Build-Markdown($Arch) {
23482356
}
23492357
}
23502358

2351-
function Build-Format($Arch) {
2352-
Build-CMakeProject `
2353-
-Src $SourceCache\swift-format `
2354-
-Bin (Get-HostProjectBinaryCache Format) `
2355-
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
2356-
-Arch $Arch `
2357-
-Platform Windows `
2358-
-UseMSVCCompilers C `
2359-
-UseBuiltCompilers Swift `
2360-
-SwiftSDK (Get-HostSwiftSDK) `
2361-
-Defines @{
2362-
BUILD_SHARED_LIBS = "YES";
2363-
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
2364-
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
2365-
SwiftMarkdown_DIR = (Get-HostProjectCMakeModules Markdown);
2366-
"cmark-gfm_DIR" = "$($Arch.ToolchainInstallRoot)\usr\lib\cmake";
2367-
}
2359+
function Build-Format() {
2360+
[CmdletBinding(PositionalBinding = $false)]
2361+
param
2362+
(
2363+
[hashtable]$Arch,
2364+
[switch] $Test
2365+
)
2366+
2367+
$SwiftPMArguments = @(
2368+
# swift-syntax
2369+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Compilers)\lib\swift\host",
2370+
"-Xlinker", "-I$(Get-HostProjectBinaryCache Compilers)\lib\swift\host",
2371+
# swift-argument-parser
2372+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache ArgumentParser)\swift",
2373+
"-Xlinker", "-L$(Get-HostProjectBinaryCache ArgumentParser)\lib",
2374+
# swift-cmark
2375+
"-Xswiftc", "-I$($Arch.ToolchainInstallRoot)\usr\include\cmark_gfm",
2376+
"-Xswiftc", "-I$($Arch.ToolchainInstallRoot)\usr\include\cmark_gfm_extensions",
2377+
"-Xlinker", "$($Arch.ToolchainInstallRoot)\usr\lib\cmark-gfm.lib",
2378+
"-Xlinker", "$($Arch.ToolchainInstallRoot)\usr\lib\cmark-gfm-extensions.lib",
2379+
# swift-markdown
2380+
"-Xlinker", "$(Get-HostProjectBinaryCache Markdown)\lib\CAtomic.lib",
2381+
"-Xswiftc", "-I$($SourceCache)\swift-markdown\Sources\CAtomic\include",
2382+
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Markdown)\swift",
2383+
"-Xlinker", "-L$(Get-HostProjectBinaryCache Markdown)\lib",
2384+
"--filter", "testNoEmptyLinesOpeningClosingBracesInClosureExpr"
2385+
)
2386+
2387+
$Options = @{
2388+
Src = "$SourceCache\swift-format"
2389+
Bin = (Get-HostProjectBinaryCache Format)
2390+
Arch = $Arch
2391+
Test = $Test
2392+
InstallExe = If ($Test) { "" } Else { "swift-format.exe" }
2393+
}
2394+
2395+
Build-SPMProject @Options @SwiftPMArguments
23682396
}
23692397

23702398
function Build-IndexStoreDB($Arch) {
@@ -2687,7 +2715,7 @@ if (-not $SkipBuild) {
26872715
Invoke-BuildStep Build-Certificates $HostArch
26882716
Invoke-BuildStep Build-PackageManager $HostArch
26892717
Invoke-BuildStep Build-Markdown $HostArch
2690-
Invoke-BuildStep Build-Format $HostArch
2718+
Invoke-BuildStep Build-Format -Arch $HostArch
26912719
Invoke-BuildStep Build-IndexStoreDB $HostArch
26922720
Invoke-BuildStep Build-SourceKitLSP $HostArch
26932721
}
@@ -2737,6 +2765,7 @@ if (-not $IsCrossCompiling) {
27372765
}
27382766
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
27392767
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
2768+
if ($Test -contains "swift-format") { Build-Format -Arch $HostArch -Test }
27402769
}
27412770

27422771
# Custom exception printing for more detailed exception information

0 commit comments

Comments
 (0)