From 7ca8495c7b98aceaddcdc7284e089392e3e1612d Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 10 Jul 2025 10:30:12 -0700 Subject: [PATCH 1/4] 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 a8072c369a6da..81360cb7c1237 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/5970/artifact/build/artifacts/installer.exe"; + PinnedSHA256 = "779E000C0C0244E54B6999F7283C2FBC73E633B81F696AA27ACA6F60DE101842"; + 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 6db919307f76fe6af58462ea0f35b9cd9b5f2376 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 14 May 2025 17:35:36 -0700 Subject: [PATCH 2/4] 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 81360cb7c1237..f44de2a996a15 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"; @@ -3430,6 +3452,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 3b12c52e186eefcdd4d8096f3ff080188e9e5cf6 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 9 Jul 2025 14:42:42 -0700 Subject: [PATCH 3/4] 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 f44de2a996a15..a94b6c37c58b2 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"; From 618d098fad4c9ae71c9aed6db4ac99b655233d49 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 17 Jul 2025 13:48:39 -0700 Subject: [PATCH 4/4] DNM: enable verbosity on Foundation build for debugging --- utils/build.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index a94b6c37c58b2..ab17c02e41fcf 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -2573,7 +2573,8 @@ function Build-Foundation { CMAKE_FIND_PACKAGE_PREFER_CONFIG = "YES"; CMAKE_NINJA_FORCE_RESPONSE_FILE = "YES"; CMAKE_STATIC_LIBRARY_PREFIX_Swift = "lib"; - CMAKE_Swift_FLAGS = $SwiftFlags; + # FIXME(compnerd) workaround undiagnosed crash during the build + CMAKE_Swift_FLAGS = $SwiftFlags + @("-v", "-j", "1"); ENABLE_TESTING = "NO"; FOUNDATION_BUILD_TOOLS = if ($Platform.OS -eq [OS]::Windows) { "YES" } else { "NO" }; CURL_DIR = "$BinaryCache\$($Platform.Triple)\usr\lib\cmake\CURL";