From 418ba361dc5d8f04cde2464b6c20e47db52ec54c Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 10 Jul 2025 10:30:12 -0700 Subject: [PATCH 1/3] utils: update toolchain snapshot to permit building early swift-driver The early swift-driver on Windows requires statically linking to the runtime. Update to a snapshot that is new enough to contain the static runtime with the appropriate fixes to enable building the early swift-driver. --- utils/build.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index c5499f6cd9c72..1daae5e59b5bf 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -204,9 +204,9 @@ if ($Test -contains "*") { $DefaultPinned = @{ AMD64 = @{ - PinnedBuild = "https://download.swift.org/swift-6.0.3-release/windows10/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-windows10.exe"; - PinnedSHA256 = "AB205D83A38047882DB80E6A88C7D33B651F3BAC96D4515D7CBA5335F37999D3"; - PinnedVersion = "6.0.3"; + PinnedBuild = "https://ci-external.swift.org/job/swift-PR-build-toolchain-windows/5966/artifact/build/artifacts/installer.exe"; + PinnedSHA256 = "026A768DE2339D7F4BD314D59CCA2C14EF34BACA46FA282402213F04293C7388"; + PinnedVersion = "0.0.0"; }; ARM64 = @{ PinnedBuild = "https://download.swift.org/swift-6.0.3-release/windows10-arm64/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-windows10-arm64.exe"; From bcf54374df2c693963aee04b2ea650929cb09604 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 14 May 2025 17:35:36 -0700 Subject: [PATCH 2/3] utils: build early swift-driver on Windows This prepares the swift-driver building on Windows. By statically linking the runtime and its dependencies, this will allow us to avoid the runtime shuffling that is required to get the runtime required to get the swift-driver working. --- utils/build.ps1 | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index 1daae5e59b5bf..208906508c1af 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -674,6 +674,7 @@ function Invoke-BuildStep { enum Project { BuildTools RegsGen2 + EarlySwiftDriver Compilers FoundationMacros @@ -1203,10 +1204,10 @@ function Get-PinnedToolchainToolsDir() { "unknown-Asserts-development.xctoolchain", "usr", "bin") } -function Get-PinnedToolchainSDK() { +function Get-PinnedToolchainSDK([OS] $OS = $BuildPlatform.OS, [string] $Identifier = $OS.ToString()) { return [IO.Path]::Combine("$BinaryCache\", "toolchains", $PinnedToolchain, "LocalApp", "Programs", "Swift", "Platforms", (Get-PinnedToolchainVersion), - "Windows.platform", "Developer", "SDKs", "Windows.sdk") + "$($OS.ToString()).platform", "Developer", "SDKs", "$Identifier.sdk") } function Get-PinnedToolchainRuntime() { @@ -1469,7 +1470,7 @@ function Build-CMakeProject { } else { Add-KeyValueIfNew $Defines CMAKE_Swift_COMPILER_TARGET $Platform.Triple - $SwiftArgs += @("-sdk", (Get-PinnedToolchainSDK)) + $SwiftArgs += @("-sdk", $(if ($SwiftSDK) { $SwiftSDK } else { Get-PinnedToolchainSDK })) } # Debug Information @@ -1754,6 +1755,26 @@ function Build-BuildTools([Hashtable] $Platform) { } } +function Build-EarlySwiftDriver { + Build-CMakeProject ` + -Src $SourceCache\swift-driver ` + -Bin (Get-ProjectBinaryCache $Platform EarlySwiftDriver) ` + -Platform $BuildPlatform ` + -UsePinnedCompilers C,CXX,Swift ` + -SwiftSDK (Get-PinnedToolchainSDK -OS $BuildPlatform.OS -Identifier "$($BuildPlatform.OS)Experimental") ` + -BuildTargets default ` + -Defines @{ + BUILD_SHARED_LIBS = "NO"; + BUILD_TESTING = "NO"; + CMAKE_STATIC_LIBRARY_PREFIX_Swift = "lib"; + # TODO(compnerd) - enforce dynamic BlocksRuntime and dispatch + CMAKE_Swift_FLAGS = @("-static-stdlib", "-Xfrontend", "-use-static-resource-dir", "-Xcc", "-static-libclosure", "-Xcc", "-Ddispatch_STATIC"); + SWIFT_DRIVER_BUILD_TOOLS = "NO"; + SQLite3_INCLUDE_DIR = "$SourceCache\swift-toolchain-sqlite\Sources\CSQLite\include"; + SQLite3_LIBRARY = "$(Get-ProjectBinaryCache $Platform SQLite)\SQLite3.lib"; + } +} + function Write-PList { [CmdletBinding(PositionalBinding = $false)] param @@ -1823,6 +1844,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [string] $Variant, [switch] CLANG_TABLEGEN = (Join-Path -Path $BuildTools -ChildPath "clang-tblgen.exe"); CLANG_TIDY_CONFUSABLE_CHARS_GEN = (Join-Path -Path $BuildTools -ChildPath "clang-tidy-confusable-chars-gen.exe"); CMAKE_FIND_PACKAGE_PREFER_CONFIG = "YES"; + CMAKE_STATIC_LIBRARY_PREFIX_Swift = "lib"; CMAKE_Swift_FLAGS = $SwiftFlags; LibXml2_DIR = "$BinaryCache\$($Platform.Triple)\usr\lib\cmake\libxml2-2.11.5"; LLDB_LIBXML2_VERSION = "2.11.5"; @@ -3429,6 +3451,8 @@ if (-not $SkipBuild) { Invoke-BuildStep Build-CMark $BuildPlatform Invoke-BuildStep Build-BuildTools $BuildPlatform + Invoke-BuildStep Build-SQLite $BuildPlatform + Invoke-BuildStep Build-EarlySwiftDriver $BuildPlatform if ($IsCrossCompiling) { Invoke-BuildStep Build-XML2 $BuildPlatform Invoke-BuildStep Build-Compilers $BuildPlatform -Variant "Asserts" From 4e71cbd2c1df144a2b2673f31e99be40a999ea1b Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 9 Jul 2025 14:42:42 -0700 Subject: [PATCH 3/3] utils: enable the early swift-driver for Windows Enable the use of the early swift-driver to build the Swift toolchain. This is the first step towards removing the accumulated debt and workarounds when building the toolchain on Windows. --- utils/build.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/build.ps1 b/utils/build.ps1 index 208906508c1af..c413c49442462 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -1867,6 +1867,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [string] $Variant, [switch] SWIFT_TOOLCHAIN_VERSION = "${ToolchainIdentifier}"; SWIFT_BUILD_SWIFT_SYNTAX = "YES"; SWIFT_CLANG_LOCATION = (Get-PinnedToolchainToolsDir); + SWIFT_EARLY_SWIFT_DRIVER_BUILD = "$(Get-ProjectBinaryCache $BuildPlatform EarlySwiftDriver)\bin"; SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES"; SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES"; SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";