From 4a3899f0c3037f9fe6e6113e670a161b9aa0a007 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 24 May 2025 22:27:30 -0700 Subject: [PATCH] utils: adjust the Swift flags for building Foundation Ensure that we properly configure Foundation for building statically. We would previously build against a dynamic variant of the standard library and libclosure. The new flags correct this so that we correctly load the appropriate libraries. --- utils/build.ps1 | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index bc5fe7627f4be..823c07415b143 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -2481,18 +2481,40 @@ function Build-Foundation { Get-ProjectBinaryCache $Platform DynamicFoundation } + $InstallRoot = if ($Static) { + "$(Get-SwiftSDK $Platform.OS -Identifier "$($Platform.OS)Experimental")\usr" + } else { + "$(Get-SwiftSDK $Platform.OS)\usr" + } + + $SwiftFlags = if ($Static) { + # FIXME(compnerd) use `-Xfrontend -use-static-resource-dir` to workaround merge module job failure + # FIXME(compnerd) use `-Xcc -DSWIFT_STATIC_STDLIB` to workaround ClangImporter setup limitation + # FIXME(compnerd) we do not pass `-Xcc -static-libclosure` as we do nto build aganst a static libdispatch yet + @("-static-stdlib", "-Xfrontend", "-use-static-resource-dir", "-Xcc", "-DSWIFT_STATIC_STDLIB") + } else { + @() + } + + $SwiftSDK = if ($Static) { + Get-SwiftSDK $Platform.OS -Identifier "$($Platform.OS.ToString())Experimental" + } else { + Get-SwiftSDK $Platform.OS + } + Build-CMakeProject ` -Src $SourceCache\swift-corelibs-foundation ` -Bin $FoundationBinaryCache ` - -InstallTo $(if ($Static) { "$(Get-SwiftSDK $Platform.OS -Identifier "$($Platform.OS)Experimental")\usr" } else { "$(Get-SwiftSDK $Platform.OS)\usr" }) ` + -InstallTo $InstallRoot ` -Platform $Platform ` -UseBuiltCompilers ASM,C,CXX,Swift ` - -SwiftSDK (Get-SwiftSDK $Platform.OS) ` + -SwiftSDK $SwiftSDK ` -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"; + CMAKE_Swift_FLAGS = $SwiftFlags; ENABLE_TESTING = "NO"; FOUNDATION_BUILD_TOOLS = if ($Platform.OS -eq [OS]::Windows) { "YES" } else { "NO" }; CURL_DIR = "$BinaryCache\$($Platform.Triple)\usr\lib\cmake\CURL";