Skip to content

Commit

Permalink
[Windows] Build swift-format using SwiftPM from build.ps1 and run tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ahoppen committed Oct 7, 2024
1 parent 106e05f commit 2d21e53
Showing 1 changed file with 48 additions and 19 deletions.
67 changes: 48 additions & 19 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ if ($AndroidSDKs.Length -gt 0) {

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

# Architecture definitions
Expand Down Expand Up @@ -1258,6 +1258,14 @@ function Build-SPMProject {

$Action = if ($Test) { "test" } else { "build" }
Invoke-Program "$($HostArch.ToolchainInstallRoot)\usr\bin\swift.exe" $Action @Arguments @AdditionalArguments

if ($InstallExe -ne "") {
$BinPath = (Invoke-Program "$($HostArch.ToolchainInstallRoot)\usr\bin\swift.exe" build @Arguments --show-bin-path)
$ExecPath = Join-Path -Path $BinPath -ChildPath $InstallExe
$InstallDestination = "$($Arch.ToolchainInstallRoot)\usr\bin"
Write-Host "Installing $($ExecPath) to $($InstallDestination)"
Copy-Item -Path $ExecPath -Destination $InstallDestination
}
}

if (-not $ToBatch) {
Expand Down Expand Up @@ -2348,23 +2356,43 @@ function Build-Markdown($Arch) {
}
}

function Build-Format($Arch) {
Build-CMakeProject `
-Src $SourceCache\swift-format `
-Bin (Get-HostProjectBinaryCache Format) `
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
-Arch $Arch `
-Platform Windows `
-UseMSVCCompilers C `
-UseBuiltCompilers Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-Defines @{
BUILD_SHARED_LIBS = "YES";
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
SwiftMarkdown_DIR = (Get-HostProjectCMakeModules Markdown);
"cmark-gfm_DIR" = "$($Arch.ToolchainInstallRoot)\usr\lib\cmake";
}
function Build-Format() {
[CmdletBinding(PositionalBinding = $false)]
param
(
[hashtable]$Arch,
[switch] $Test
)

$SwiftPMArguments = @(
# swift-syntax
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Compilers)\lib\swift\host",
"-Xlinker", "-I$(Get-HostProjectBinaryCache Compilers)\lib\swift\host",
# swift-argument-parser
"-Xswiftc", "-I$(Get-HostProjectBinaryCache ArgumentParser)\swift",
"-Xlinker", "-L$(Get-HostProjectBinaryCache ArgumentParser)\lib",
# swift-cmark
"-Xswiftc", "-I$($Arch.ToolchainInstallRoot)\usr\include\cmark_gfm",
"-Xswiftc", "-I$($Arch.ToolchainInstallRoot)\usr\include\cmark_gfm_extensions",
"-Xlinker", "$($Arch.ToolchainInstallRoot)\usr\lib\cmark-gfm.lib",
"-Xlinker", "$($Arch.ToolchainInstallRoot)\usr\lib\cmark-gfm-extensions.lib",
# swift-markdown
"-Xlinker", "$(Get-HostProjectBinaryCache Markdown)\lib\CAtomic.lib",
"-Xswiftc", "-I$($SourceCache)\swift-markdown\Sources\CAtomic\include",
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Markdown)\swift",
"-Xlinker", "-L$(Get-HostProjectBinaryCache Markdown)\lib",
"--filter", "testNoEmptyLinesOpeningClosingBracesInClosureExpr"
)

$Options = @{
Src = "$SourceCache\swift-format"
Bin = (Get-HostProjectBinaryCache Format)
Arch = $Arch
Test = $Test
InstallExe = If ($Test) { "" } Else { "swift-format.exe" }
}

Build-SPMProject @Options @SwiftPMArguments
}

function Build-IndexStoreDB($Arch) {
Expand Down Expand Up @@ -2687,7 +2715,7 @@ if (-not $SkipBuild) {
Invoke-BuildStep Build-Certificates $HostArch
Invoke-BuildStep Build-PackageManager $HostArch
Invoke-BuildStep Build-Markdown $HostArch
Invoke-BuildStep Build-Format $HostArch
Invoke-BuildStep Build-Format -Arch $HostArch
Invoke-BuildStep Build-IndexStoreDB $HostArch
Invoke-BuildStep Build-SourceKitLSP $HostArch
}
Expand Down Expand Up @@ -2737,6 +2765,7 @@ if (-not $IsCrossCompiling) {
}
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
if ($Test -contains "swift-format") { Build-Format -Arch $HostArch -Test }
}

# Custom exception printing for more detailed exception information
Expand Down

0 comments on commit 2d21e53

Please sign in to comment.