Skip to content

utils: split Build-* into Build- and Test- #80082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 121 additions & 116 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2283,25 +2283,31 @@ function Write-SDKSettingsPlist([Platform]$Platform, $Arch) {
$SDKSettings | ConvertTo-JSON | Out-FIle -FilePath "$(Get-SwiftSDK $Platform)\SDKSettings.json"
}

function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
Invoke-IsolatingEnvVars {
if ($Test) {
$Targets = @("default", "ExperimentalTest")
$InstallPath = ""
$env:CTEST_OUTPUT_ON_FAILURE = "YES"
} else {
$Targets = @("install")
$InstallPath = "$(Get-SwiftSDK $Platform)\usr"
function Build-Dispatch([Platform]$Platform, $Arch) {
Build-CMakeProject `
-Src $SourceCache\swift-corelibs-libdispatch `
-Bin (Get-ProjectBinaryCache $Arch Dispatch) `
-InstallTo "$(Get-SwiftSDK $Platform)\usr" `
-Arch $Arch `
-Platform $Platform `
-SwiftSDK (Get-SwiftSDK $Platform) `
-UseBuiltCompilers C,CXX,Swift `
-Defines @{
ENABLE_SWIFT = "YES";
}
}

function Test-Dispatch {
Invoke-IsolatingEnvVars {
$env:CTEST_OUTPUT_ON_FAILURE = "YES"

Build-CMakeProject `
-Src $SourceCache\swift-corelibs-libdispatch `
-Bin (Get-ProjectBinaryCache $Arch Dispatch) `
-InstallTo $InstallPath `
-Arch $Arch `
-Platform $Platform `
-BuildTargets $Targets `
-SwiftSDK (Get-SwiftSDK $Platform) `
-Bin (Get-ProjectBinaryCache $BuildArch Dispatch) `
-Arch $BuildArch `
-Platform Windows `
-SwiftSDK (Get-SwiftSDK Windows) `
-BuildTargets default,ExperimentalTest `
-UseBuiltCompilers C,CXX,Swift `
-Defines @{
ENABLE_SWIFT = "YES";
Expand All @@ -2317,72 +2323,68 @@ function Build-Foundation {
[Platform] $Platform,
[Parameter(Position = 1, Mandatory = $true)]
[hashtable] $Arch,
[switch] $Static = $false,
[switch] $Test = $false
[switch] $Static = $false
)

if ($Test) {
# Foundation tests build via swiftpm rather than CMake
Build-SPMProject `
-Action Test `
-Src $SourceCache\swift-foundation `
-Bin "$BinaryCache\$($Arch.LLVMTarget)\CoreFoundationTests" `
-Arch $HostArch `
-Configuration $FoundationTestConfiguration

$ShortArch = $Arch.LLVMName
Invoke-IsolatingEnvVars {
$env:DISPATCH_INCLUDE_PATH="$(Get-SwiftSDK $Platform)/usr/include"
$env:LIBXML_LIBRARY_PATH="$LibraryRoot/libxml2-2.11.5/usr/lib/$Platform/$ShortArch"
$env:LIBXML_INCLUDE_PATH="$LibraryRoot/libxml2-2.11.5/usr/include/libxml2"
$env:ZLIB_LIBRARY_PATH="$LibraryRoot/zlib-1.3.1/usr/lib/$Platform/$ShortArch"
$env:CURL_LIBRARY_PATH="$LibraryRoot/curl-8.9.1/usr/lib/$Platform/$ShortArch"
$env:CURL_INCLUDE_PATH="$LibraryRoot/curl-8.9.1/usr/include"
Build-SPMProject `
-Action Test `
-Src $SourceCache\swift-corelibs-foundation `
-Bin "$BinaryCache\$($Arch.LLVMTarget)\FoundationTests" `
-Arch $HostArch `
-Configuration $FoundationTestConfiguration
}
$FoundationBinaryCache = if ($Static) {
Get-ProjectBinaryCache $Arch StaticFoundation
} else {
$FoundationBinaryCache = if ($Static) {
Get-ProjectBinaryCache $Arch StaticFoundation
} else {
Get-ProjectBinaryCache $Arch DynamicFoundation
Get-ProjectBinaryCache $Arch DynamicFoundation
}

Build-CMakeProject `
-Src $SourceCache\swift-corelibs-foundation `
-Bin $FoundationBinaryCache `
-InstallTo $(if ($Static) { "$(Get-SwiftSDK $Platform -Identifier "${Platform}Experimental")\usr" } else { "$(Get-SwiftSDK $Platform)\usr" }) `
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers ASM,C,CXX,Swift `
-SwiftSDK (Get-SwiftSDK $Platform) `
-Defines @{
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
CMAKE_FIND_PACKAGE_PREFER_CONFIG = "YES";
CMAKE_NINJA_FORCE_RESPONSE_FILE = "YES";
CMAKE_STATIC_LIBRARY_PREFIX_Swift = "lib";
ENABLE_TESTING = "NO";
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$($Arch.LLVMName)\cmake\CURL";
LibXml2_DIR = "$LibraryRoot\libxml2-2.11.5\usr\lib\$Platform\$($Arch.LLVMName)\cmake\libxml2-2.11.5";
ZLIB_LIBRARY = if ($Platform -eq "Windows") {
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$($Arch.LLVMName)\zlibstatic.lib"
} else {
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$($Arch.LLVMName)\libz.a"
};
ZLIB_INCLUDE_DIR = "$LibraryRoot\zlib-1.3.1\usr\include";
dispatch_DIR = (Get-ProjectCMakeModules $Arch Dispatch);
SwiftSyntax_DIR = (Get-ProjectBinaryCache $HostArch Compilers);
_SwiftFoundation_SourceDIR = "$SourceCache\swift-foundation";
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections";
SwiftFoundation_MACRO = "$(Get-ProjectBinaryCache $BuildArch FoundationMacros)\bin"
}
$ShortArch = $Arch.LLVMName
}

Build-CMakeProject `
function Test-Foundation {
# Foundation tests build via swiftpm rather than CMake
Build-SPMProject `
-Action Test `
-Src $SourceCache\swift-foundation `
-Bin "$BinaryCache\$($BuildArch.LLVMTarget)\CoreFoundationTests" `
-Arch $BuildArch

Invoke-IsolatingEnvVars {
$env:DISPATCH_INCLUDE_PATH="$(Get-SwiftSDK Windows)/usr/include"
$env:LIBXML_LIBRARY_PATH="$LibraryRoot/libxml2-2.11.5/usr/lib/windows/$($BuildArch.LLVMName)"
$env:LIBXML_INCLUDE_PATH="$LibraryRoot/libxml2-2.11.5/usr/include/libxml2"
$env:ZLIB_LIBRARY_PATH="$LibraryRoot/zlib-1.3.1/usr/lib/windows/$($BuildArch.LLVMName)"
$env:CURL_LIBRARY_PATH="$LibraryRoot/curl-8.9.1/usr/lib/windows/$($BuildArch.LLVMName)"
$env:CURL_INCLUDE_PATH="$LibraryRoot/curl-8.9.1/usr/include"
Build-SPMProject `
-Action Test `
-Src $SourceCache\swift-corelibs-foundation `
-Bin $FoundationBinaryCache `
-InstallTo $(if ($Static) { "$(Get-SwiftSDK $Platform -Identifier "${Platform}Experimental")\usr" } else { "$(Get-SwiftSDK $Platform)\usr" }) `
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers ASM,C,CXX,Swift `
-SwiftSDK (Get-SwiftSDK $Platform) `
-Defines @{
BUILD_SHARED_LIBS = if ($Static) { "NO" } else { "YES" };
CMAKE_FIND_PACKAGE_PREFER_CONFIG = "YES";
CMAKE_NINJA_FORCE_RESPONSE_FILE = "YES";
CMAKE_STATIC_LIBRARY_PREFIX_Swift = "lib";
ENABLE_TESTING = "NO";
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
LibXml2_DIR = "$LibraryRoot\libxml2-2.11.5\usr\lib\$Platform\$ShortArch\cmake\libxml2-2.11.5";
ZLIB_LIBRARY = if ($Platform -eq "Windows") {
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$ShortArch\zlibstatic.lib"
} else {
"$LibraryRoot\zlib-1.3.1\usr\lib\$Platform\$ShortArch\libz.a"
};
ZLIB_INCLUDE_DIR = "$LibraryRoot\zlib-1.3.1\usr\include";
dispatch_DIR = (Get-ProjectCMakeModules $Arch Dispatch);
SwiftSyntax_DIR = (Get-ProjectBinaryCache $HostArch Compilers);
_SwiftFoundation_SourceDIR = "$SourceCache\swift-foundation";
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections";
SwiftFoundation_MACRO = "$(Get-ProjectBinaryCache $BuildArch FoundationMacros)\bin"
}
-Bin "$BinaryCache\$($BuildArch.LLVMTarget)\FoundationTests" `
-Arch $BuildArch `
-Configuration $FoundationTestConfiguration
}
}

Expand Down Expand Up @@ -2474,6 +2476,10 @@ function Build-Testing([Platform]$Platform, $Arch) {
}
}

function Test-Testing {
throw "testing Testing is not supported"
}

function Write-PlatformInfoPlist([Platform] $Platform) {
$Settings = @{
DefaultProperties = @{
Expand Down Expand Up @@ -2579,46 +2585,53 @@ function Build-ToolsSupportCore($Arch) {
}
}

function Build-LLBuild($Arch, [switch]$Test = $false) {
function Build-LLBuild($Arch) {
Build-CMakeProject `
-Src $SourceCache\llbuild `
-Bin (Get-ProjectBinaryCache $Arch LLBuild) `
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
-Arch $Arch `
-Platform Windows `
-UseMSVCCompilers CXX `
-UseBuiltCompilers Swift `
-SwiftSDK (Get-SwiftSDK Windows) `
-Defines @{
BUILD_SHARED_LIBS = "YES";
LLBUILD_SUPPORT_BINDINGS = "Swift";
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
}
}

function Test-LLBuild {
# Build additional llvm executables needed by tests
Invoke-IsolatingEnvVars {
if ($Test) {
# Build additional llvm executables needed by tests
Invoke-IsolatingEnvVars {
Invoke-VsDevShell $BuildArch
Invoke-Program ninja.exe -C (Get-ProjectBinaryCache $BuildArch BuildTools) FileCheck not
}
Invoke-VsDevShell $BuildArch
Invoke-Program ninja.exe -C (Get-ProjectBinaryCache $BuildArch BuildTools) FileCheck not
}

$Targets = @("default", "test-llbuild")
$TestingDefines = @{
FILECHECK_EXECUTABLE = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch BuildTools), "bin", "FileCheck.exe"));
LIT_EXECUTABLE = "$SourceCache\llvm-project\llvm\utils\lit\lit.py";
}
$env:Path = "$env:Path;$UnixToolsBinDir"
$env:AR = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch Compilers), "bin", "llvm-ar.exe"))
$env:CLANG = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch Compilers), "bin", "clang.exe"))
$InstallPath = ""
} else {
$Targets = @()
$TestingDefines = @{}
$InstallPath = "$($Arch.ToolchainInstallRoot)\usr"
}
Invoke-IsolatingEnvVars {
$env:Path = "$env:Path;$UnixToolsBinDir"
$env:AR = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch Compilers), "bin", "llvm-ar.exe"))
$env:CLANG = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch Compilers), "bin", "clang.exe"))

Build-CMakeProject `
-Src $SourceCache\llbuild `
-Bin (Get-ProjectBinaryCache $Arch LLBuild) `
-InstallTo $InstallPath `
-Arch $Arch `
-Bin (Get-ProjectBinaryCache $BuildArch LLBuild) `
-Arch $BuildArch `
-Platform Windows `
-UseMSVCCompilers CXX `
-UseBuiltCompilers Swift `
-SwiftSDK (Get-SwiftSDK Windows) `
-BuildTargets $Targets `
-Defines ($TestingDefines + @{
-BuildTargets default,test-llbuild `
-Defines = @{
BUILD_SHARED_LIBS = "YES";
FILECHECK_EXECUTABLE = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildArch BuildTools), "bin", "FileCheck.exe"));
LIT_EXECUTABLE = "$SourceCache\llvm-project\llvm\utils\lit\lit.py";
LLBUILD_SUPPORT_BINDINGS = "Swift";
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
})
}
}
}

Expand Down Expand Up @@ -3280,20 +3293,12 @@ if (-not $IsCrossCompiling) {
Build-Compilers $HostArch @Tests
}

if ($Test -contains "dispatch") {
Build-Dispatch Windows $HostArch -Test
}
if ($Test -contains "foundation") {
Build-Foundation Windows $HostArch -Test
}
if ($Test -contains "xctest") {
Test-XCTest
}
if ($Test -contains "testing") {
Build-Testing Windows $HostArch -Test
}
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
if ($Test -contains "dispatch") { Test-Dispatch }
if ($Test -contains "foundation") { Test-Foundation }
if ($Test -contains "xctest") { Test-XCTest }
if ($Test -contains "testing") { Test-Testing }
if ($Test -contains "llbuild") { Test-LLBuild }
if ($Test -contains "swiftpm") { Test-PackageManager }
if ($Test -contains "swift-format") { Test-Format }
if ($Test -contains "sourcekit-lsp") { Test-SourceKitLSP }

Expand Down