Skip to content

Commit

Permalink
[Windows] Run swift-format tests from build.ps1
Browse files Browse the repository at this point in the history
The basic idea is that we build all libraries for the executable that will be included in the toolchain using CMake. swift-format then has a mode in its Package manifest that allows it to build just the test and test support targets, requiring all search paths to find those libraries to be passed in. We use that to only build swift-format's test using SwiftPM and re-use all the libraries that were already built using CMake.
  • Loading branch information
ahoppen committed Oct 11, 2024
1 parent 8ae66ec commit bb217a3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion utils/build-windows-toolchain.bat
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ set TMPDIR=%BuildRoot%\tmp
set NINJA_STATUS=[%%f/%%t][%%p][%%es]

:: Build the -Test argument, if any, by subtracting skipped tests
set TestArg=-Test lld,swift,dispatch,foundation,xctest,
set TestArg=-Test lld,swift,dispatch,foundation,xctest,swift-format,
for %%I in (%SKIP_TESTS%) do (call set TestArg=%%TestArg:%%I,=%%)
if "%TestArg:~-1%"=="," (set TestArg=%TestArg:~0,-1%) else (set TestArg= )

Expand Down
47 changes: 43 additions & 4 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ function Build-CMakeProject {
}

if ($UseBuiltCompilers.Contains("Swift")) {
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$($BuildArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMark-BinaryCache($Arch))\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
} elseif ($UsePinnedCompilers.Contains("Swift")) {
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
}
Expand Down Expand Up @@ -1326,12 +1326,15 @@ function Build-WiXProject() {
Invoke-Program $msbuild @MSBuildArgs
}

function Get-CMark-BinaryCache($Arch) {
return "$($Arch.BinaryCache)\cmark-gfm-0.29.0.gfm.13"
}
function Build-CMark($Arch) {
$ArchName = $Arch.LLVMName

Build-CMakeProject `
-Src $SourceCache\cmark `
-Bin "$($Arch.BinaryCache)\cmark-gfm-0.29.0.gfm.13" `
-Bin (Get-CMark-BinaryCache($Arch)) `
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
-Arch $Arch `
-Defines @{
Expand Down Expand Up @@ -1400,7 +1403,7 @@ function Build-Compilers() {
$BuildTools = Join-Path -Path (Get-BuildProjectBinaryCache BuildTools) -ChildPath bin

if ($TestClang -or $TestLLD -or $TestLLDB -or $TestLLVM -or $TestSwift) {
$env:Path = "$($HostArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$CompilersBinaryCache\tools\swift\libdispatch-windows-$($Arch.LLVMName)-prefix\bin;$CompilersBinaryCache\bin;$env:Path;$VSInstallRoot\DIA SDK\bin\$($HostArch.VSName);$UnixToolsBinDir"
$env:Path = "$(Get-CMark-BinaryCache($Arch))\src;$CompilersBinaryCache\tools\swift\libdispatch-windows-$($Arch.LLVMName)-prefix\bin;$CompilersBinaryCache\bin;$env:Path;$VSInstallRoot\DIA SDK\bin\$($HostArch.VSName);$UnixToolsBinDir"
$Targets = @()
$TestingDefines = @{
SWIFT_BUILD_DYNAMIC_SDK_OVERLAY = "YES";
Expand Down Expand Up @@ -1745,7 +1748,7 @@ function Build-Runtime([Platform]$Platform, $Arch) {


Isolate-EnvVars {
$env:Path = "$($BuildArch.BinaryCache)\cmark-gfm-0.29.0.gfm.13\src;$(Get-PinnedToolchainRuntime);${env:Path}"
$env:Path = "$(Get-CMark-BinaryCache($Arch))\src;$(Get-PinnedToolchainRuntime);${env:Path}"

$CompilersBinaryCache = if ($IsCrossCompiling) {
Get-BuildProjectBinaryCache Compilers
Expand Down Expand Up @@ -2374,6 +2377,41 @@ function Build-Format($Arch) {
}
}

function Test-Format {
$SwiftPMArguments = @(
# swift-syntax
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Compilers)\lib\swift\host",
"-Xswiftc", "-L$(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$($SourceCache)\cmark\src\include",
"-Xswiftc", "-I$($SourceCache)\cmark\extensions\include",
"-Xlinker", "-I$($SourceCache)\cmark\extensions\include",
"-Xlinker", "$(Get-CMark-BinaryCache($HostArch))\src\cmark-gfm.lib",
"-Xlinker", "$(Get-CMark-BinaryCache($HostArch))\extensions\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",
# swift-format
"-Xswiftc", "-I$(Get-HostProjectBinaryCache Format)\swift",
"-Xlinker", "-L$(Get-HostProjectBinaryCache Format)\lib"
)

Isolate-EnvVars {
$env:SWIFTFORMAT_BUILD_ONLY_TESTS=1
Build-SPMProject `
-Src "$SourceCache\swift-format" `
-Bin (Join-Path -Path $HostArch.BinaryCache -ChildPath swift-format) `
-Arch $HostArch `
-Test `
@SwiftPMArguments
}
}

function Build-IndexStoreDB($Arch) {
$SDKInstallRoot = (Get-HostSwiftSDK);

Expand Down Expand Up @@ -2744,6 +2782,7 @@ if (-not $IsCrossCompiling) {
}
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
if ($Test -contains "swift-format") { Test-Format }
}

# Custom exception printing for more detailed exception information
Expand Down

0 comments on commit bb217a3

Please sign in to comment.