@@ -194,14 +194,6 @@ $WiXVersion = "4.0.5"
194194# Avoid $env:ProgramFiles in case this script is running as x86
195195$UnixToolsBinDir = " $env: SystemDrive \Program Files\Git\usr\bin"
196196
197- $python = " ${env: ProgramFiles(x86)} \Microsoft Visual Studio\Shared\Python39_64\python.exe"
198- if (-not (Test-Path $python )) {
199- $python = (where.exe python) | Select-Object - First 1
200- if (-not (Test-Path $python )) {
201- throw " Python.exe not found"
202- }
203- }
204-
205197if ($Android -and ($AndroidSDKs.Length -eq 0 )) {
206198 # Enable all android SDKs by default.
207199 $AndroidSDKs = @ (" aarch64" , " armv7" , " i686" , " x86_64" )
@@ -358,6 +350,10 @@ function Get-BisonExecutable {
358350 return Join-Path - Path $BinaryCache - ChildPath " win_flex_bison\win_bison.exe"
359351}
360352
353+ function Get-PythonExecutable {
354+ return Join-Path - Path $BinaryCache - ChildPath " Python$ ( $BuildArch.CMakeName ) -$PythonVersion \tools\python.exe"
355+ }
356+
361357function Get-InstallDir ($Arch ) {
362358 if ($Arch -eq $HostArch ) {
363359 $ProgramFilesName = " Program Files"
@@ -747,10 +743,43 @@ function Fetch-Dependencies {
747743 }
748744 }
749745
746+ function Ensure-PythonModules ($Python ) {
747+ # First ensure pip is installed, else bootstrap it
748+ try {
749+ Invoke-Program - OutNull $Python - m pip * > $null
750+ } catch {
751+ Write-Output " Installing pip ..."
752+ Invoke-Program - OutNull $Python ' -I' - m ensurepip - U -- default- pip
753+ }
754+ # 'packaging' is required for building LLVM 18+
755+ try {
756+ Invoke-Program - OutNull $Python - c ' import packaging' * > $null
757+ } catch {
758+ $WheelURL = " https://files.pythonhosted.org/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl"
759+ $WheelHash = " 5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"
760+ DownloadAndVerify $WheelURL " $BinaryCache \python\packaging-24.1-py3-none-any.whl" $WheelHash
761+ Write-Output " Installing 'packaging-24.1-py3-none-any.whl' ..."
762+ Invoke-Program - OutNull $Python ' -I' - m pip install " $BinaryCache \python\packaging-24.1-py3-none-any.whl" -- disable-pip - version- check
763+ }
764+ # 'setuptools' provides 'distutils' module for Python 3.12+, required for SWIG support
765+ # https://github.com/swiftlang/llvm-project/issues/9289
766+ try {
767+ Invoke-Program - OutNull $Python - c ' import distutils' * > $null
768+ } catch {
769+ $WheelURL = " https://files.pythonhosted.org/packages/ff/ae/f19306b5a221f6a436d8f2238d5b80925004093fa3edea59835b514d9057/setuptools-75.1.0-py3-none-any.whl"
770+ $WheelHash = " 35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2"
771+ DownloadAndVerify $WheelURL " $BinaryCache \python\setuptools-75.1.0-py3-none-any.whl" $WheelHash
772+ Write-Output " Installing 'setuptools-75.1.0-py3-none-any.whl' ..."
773+ Invoke-Program - OutNull $Python ' -I' - m pip install " $BinaryCache \python\setuptools-75.1.0-py3-none-any.whl" -- disable-pip - version- check
774+ }
775+ }
776+
750777 Download- Python $HostArchName
751778 if ($IsCrossCompiling ) {
752779 Download- Python $BuildArchName
753780 }
781+ # Ensure Python modules that are required as host build tools
782+ Ensure- PythonModules " $ ( Get-PythonExecutable ) "
754783
755784 if ($Android ) {
756785 # Only a specific NDK version is supported right now.
@@ -959,7 +988,6 @@ function Build-CMakeProject {
959988 }
960989
961990 TryAdd- KeyValue $Defines CMAKE_BUILD_TYPE Release
962- TryAdd- KeyValue $Defines CMAKE_MT " mt"
963991
964992 $CFlags = @ ()
965993 switch ($Platform ) {
@@ -1382,6 +1410,8 @@ function Build-BuildTools($Arch) {
13821410 - BuildTargets llvm- tblgen, clang- tblgen, clang- pseudo- gen, clang- tidy- confusable- chars- gen, lldb- tblgen, llvm- config, swift- def- to- strings- converter, swift- serialize- diagnostics, swift- compatibility- symbols `
13831411 - Defines @ {
13841412 CMAKE_CROSSCOMPILING = " NO" ;
1413+ CLANG_ENABLE_LIBXML2 = " NO" ;
1414+ LLDB_ENABLE_LIBXML2 = " NO" ;
13851415 LLDB_ENABLE_PYTHON = " NO" ;
13861416 LLDB_INCLUDE_TESTS = " NO" ;
13871417 LLDB_ENABLE_SWIFT_SUPPORT = " NO" ;
@@ -1456,6 +1486,9 @@ function Build-Compilers() {
14561486 }
14571487 }
14581488
1489+ $PythonRoot = " $BinaryCache \Python$ ( $Arch.CMakeName ) -$PythonVersion \tools"
1490+ $PythonLibName = " python{0}{1}" -f ([System.Version ]$PythonVersion ).Major, ([System.Version ]$PythonVersion ).Minor
1491+
14591492 # The STL in VS 17.10 requires Clang 17 or higher, but Swift toolchains prior to version 6 include older versions
14601493 # of Clang. If bootstrapping with an older toolchain, we need to relax to relax this requirement with
14611494 # ALLOW_COMPILER_AND_STL_VERSION_MISMATCH.
@@ -1477,7 +1510,9 @@ function Build-Compilers() {
14771510 - Defines ($TestingDefines + @ {
14781511 CLANG_TABLEGEN = (Join-Path - Path $BuildTools - ChildPath " clang-tblgen.exe" );
14791512 CLANG_TIDY_CONFUSABLE_CHARS_GEN = (Join-Path - Path $BuildTools - ChildPath " clang-tidy-confusable-chars-gen.exe" );
1513+ CMAKE_FIND_PACKAGE_PREFER_CONFIG = " YES" ;
14801514 CMAKE_Swift_FLAGS = $SwiftFlags ;
1515+ LibXml2_DIR = " $LibraryRoot \libxml2-2.11.5\usr\lib\Windows\$ ( $Arch.LLVMName ) \cmake\libxml2-2.11.5" ;
14811516 LLDB_PYTHON_EXE_RELATIVE_PATH = " python.exe" ;
14821517 LLDB_PYTHON_EXT_SUFFIX = " .pyd" ;
14831518 LLDB_PYTHON_RELATIVE_PATH = " lib/site-packages" ;
@@ -1487,10 +1522,10 @@ function Build-Compilers() {
14871522 LLVM_NATIVE_TOOL_DIR = $BuildTools ;
14881523 LLVM_TABLEGEN = (Join-Path $BuildTools - ChildPath " llvm-tblgen.exe" );
14891524 LLVM_USE_HOST_TOOLS = " NO" ;
1490- Python3_EXECUTABLE = " $python " ;
1491- Python3_INCLUDE_DIR = " $BinaryCache \Python $ ( $Arch .CMakeName ) - $PythonVersion \tools \include" ;
1492- Python3_LIBRARY = " $BinaryCache \Python $ ( $Arch .CMakeName ) - $PythonVersion \tools\ libs\python39 .lib" ;
1493- Python3_ROOT_DIR = " $BinaryCache \Python $ ( $Arch .CMakeName ) - $PythonVersion \tools " ;
1525+ Python3_EXECUTABLE = ( Get-PythonExecutable ) ;
1526+ Python3_INCLUDE_DIR = " $PythonRoot \include" ;
1527+ Python3_LIBRARY = " $PythonRoot \ libs\$PythonLibName .lib" ;
1528+ Python3_ROOT_DIR = $PythonRoot ;
14941529 SWIFT_BUILD_SWIFT_SYNTAX = " YES" ;
14951530 SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool );
14961531 SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = " YES" ;
@@ -1521,47 +1556,52 @@ function Build-Mimalloc() {
15211556 [hashtable ]$Arch
15221557 )
15231558
1524- if ($Arch -eq $ArchX64 ) {
1525- $Args = @ ()
1526- Isolate- EnvVars {
1527- Invoke-VsDevShell $Arch
1528- # Avoid hard-coding the VC tools version number
1529- $VCRedistDir = (Get-ChildItem " ${env: VCToolsRedistDir} \$ ( $HostArch.ShortName ) " - Filter " Microsoft.VC*.CRT" ).FullName
1530- if ($VCRedistDir ) {
1531- $Args += " -p:VCRedistDir=$VCRedistDir \"
1532- }
1533- }
1534- $Args += " $SourceCache \mimalloc\ide\vs2022\mimalloc.sln"
1535- $Args += " -p:Configuration=Release"
1536- $Args += " -p:ProductArchitecture=$ ( $Arch.VSName ) "
1537- Invoke-Program $msbuild @Args
1538- $Dest = " $ ( $Arch.ToolchainInstallRoot ) \usr\bin"
1539- Copy-Item - Path " $SourceCache \mimalloc\out\msvc-$ ( $Arch.ShortName ) \Release\mimalloc-override.dll" `
1540- - Destination " $Dest "
1541- Copy-Item - Path " $SourceCache \mimalloc\out\msvc-$ ( $Arch.ShortName ) \Release\mimalloc-redirect.dll" `
1542- - Destination " $Dest "
1543- $MimallocExecutables = @ (" swift.exe" , " swiftc.exe" , " swift-driver.exe" , " swift-frontend.exe" )
1544- $MimallocExecutables += @ (" clang.exe" , " clang++.exe" , " clang-cl.exe" )
1545- $MimallocExecutables += @ (" lld.exe" , " lld-link.exe" , " ld.lld.exe" , " ld64.lld.exe" )
1546- foreach ($Exe in $MimallocExecutables ) {
1547- $ExePath = [IO.Path ]::Combine($Dest , $Exe )
1548- # Binary-patch in place
1549- $Args = @ ()
1550- $Args += " -f"
1551- $Args += " -i"
1552- $Args += " -v"
1553- $Args += $ExePath
1554- Invoke-Program " $SourceCache \mimalloc\bin\minject" @Args
1555- # Log the import table
1556- $Args = @ ()
1557- $Args += " -l"
1558- $Args += $ExePath
1559- Invoke-Program " $SourceCache \mimalloc\bin\minject" @Args
1560- dir " $ExePath "
1561- }
1562- } else {
1559+ if ($Arch -ne $ArchX64 ) {
15631560 throw " mimalloc is currently supported for X64 only"
15641561 }
1562+
1563+ $MSBuildArgs = @ (" $SourceCache \mimalloc\ide\vs2022\mimalloc.sln" )
1564+ $MSBuildArgs += " -noLogo"
1565+ $MSBuildArgs += " -maxCpuCount"
1566+ $MSBuildArgs += " -p:Configuration=Release"
1567+ $MSBuildArgs += " -p:ProductArchitecture=$ ( $Arch.VSName ) "
1568+
1569+ Isolate- EnvVars {
1570+ Invoke-VsDevShell $Arch
1571+ # Avoid hard-coding the VC tools version number
1572+ $VCRedistDir = (Get-ChildItem " ${env: VCToolsRedistDir} \$ ( $HostArch.ShortName ) " - Filter " Microsoft.VC*.CRT" ).FullName
1573+ if ($VCRedistDir ) {
1574+ $MSBuildArgs += " -p:VCRedistDir=$VCRedistDir \"
1575+ }
1576+ }
1577+
1578+ Invoke-Program $msbuild @MSBuildArgs
1579+
1580+ $Products = @ ( " mimalloc-override.dll" , " mimalloc-redirect.dll" )
1581+ foreach ($Product in $Products ) {
1582+ Copy-Item - Path " $SourceCache \mimalloc\out\msvc-$ ( $Arch.ShortName ) \Release\$Product " - Destination " $ ( Arch.ToolchainInstallRoot) \usr\bin"
1583+ }
1584+
1585+ $Tools = @ (
1586+ " swift.exe" ,
1587+ " swiftc.exe" ,
1588+ " swift-driver.exe" ,
1589+ " swift-frontend.exe" ,
1590+ " clang.exe" ,
1591+ " clang++.exe" ,
1592+ " clang-cl.exe" ,
1593+ " lld.exe" ,
1594+ " lld-link.exe" ,
1595+ " ld.lld.exe" ,
1596+ " ld64.lld.exe"
1597+ )
1598+ foreach ($Tool in $Tools ) {
1599+ $Binary = [IO.Path ]::Combine($Dest , $Tool )
1600+ # Binary-patch in place
1601+ Invoke-Program " $SourceCache \mimalloc\bin\minject" @ (" -f" , " -i" , " -v" , $Binary )
1602+ # Log the import table
1603+ Invoke-Program " $SourceCache \mimalloc\bin\minject" @ (" -l" , $Binary )
1604+ }
15651605}
15661606
15671607function Build-LLVM ([Platform ]$Platform , $Arch ) {
@@ -1815,7 +1855,7 @@ function Build-Runtime([Platform]$Platform, $Arch) {
18151855 })
18161856 }
18171857
1818- Invoke-Program $python - c " import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'DEFAULT_USE_RUNTIME': 'MD' } }), encoding='utf-8'))" `
1858+ Invoke-Program " $ ( Get-PythonExecutable ) " - c " import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'DEFAULT_USE_RUNTIME': 'MD' } }), encoding='utf-8'))" `
18191859 - OutFile " $ ( $Arch.SDKInstallRoot ) \SDKSettings.plist"
18201860}
18211861
@@ -1900,14 +1940,9 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
19001940 - Defines (@ {
19011941 ENABLE_TESTING = " NO" ;
19021942 FOUNDATION_BUILD_TOOLS = if ($Platform -eq " Windows" ) { " YES" } else { " NO" };
1943+ CMAKE_FIND_PACKAGE_PREFER_CONFIG = " YES" ;
19031944 CURL_DIR = " $LibraryRoot \curl-8.9.1\usr\lib\$Platform \$ShortArch \cmake\CURL" ;
1904- LIBXML2_LIBRARY = if ($Platform -eq " Windows" ) {
1905- " $LibraryRoot \libxml2-2.11.5\usr\lib\$Platform \$ShortArch \libxml2s.lib" ;
1906- } else {
1907- " $LibraryRoot \libxml2-2.11.5\usr\lib\$Platform \$ShortArch \libxml2.a" ;
1908- };
1909- LIBXML2_INCLUDE_DIR = " $LibraryRoot \libxml2-2.11.5\usr\include\libxml2" ;
1910- LIBXML2_DEFINITIONS = " -DLIBXML_STATIC" ;
1945+ LibXml2_DIR = " $LibraryRoot \libxml2-2.11.5\usr\lib\$Platform \$ShortArch \cmake\libxml2-2.11.5" ;
19111946 ZLIB_LIBRARY = if ($Platform -eq " Windows" ) {
19121947 " $LibraryRoot \zlib-1.3.1\usr\lib\$Platform \$ShortArch \zlibstatic.lib"
19131948 } else {
@@ -2046,7 +2081,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
20462081
20472082function Write-PlatformInfoPlist ($Arch ) {
20482083 $PList = Join-Path - Path $Arch.PlatformInstallRoot - ChildPath " Info.plist"
2049- Invoke-Program $python - c " import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'XCTEST_VERSION': 'development', 'SWIFT_TESTING_VERSION': 'development', 'SWIFTC_FLAGS': ['-use-ld=lld'] } }), encoding='utf-8'))" `
2084+ Invoke-Program " $ ( Get-PythonExecutable ) " - c " import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'XCTEST_VERSION': 'development', 'SWIFT_TESTING_VERSION': 'development', 'SWIFTC_FLAGS': ['-use-ld=lld'] } }), encoding='utf-8'))" `
20502085 - OutFile " $PList "
20512086}
20522087
@@ -2746,13 +2781,15 @@ if (-not $SkipBuild) {
27462781 Invoke-BuildStep Build-CMark $BuildArch
27472782 Invoke-BuildStep Build-BuildTools $BuildArch
27482783 if ($IsCrossCompiling ) {
2784+ Invoke-BuildStep Build-XML2 Windows $BuildArch
27492785 Invoke-BuildStep Build-Compilers - Build $BuildArch
27502786 }
27512787 if ($IncludeDS2 ) {
27522788 Invoke-BuildStep Build-RegsGen2 $BuildArch
27532789 }
27542790
27552791 Invoke-BuildStep Build-CMark $HostArch
2792+ Invoke-BuildStep Build-XML2 Windows $HostArch
27562793 Invoke-BuildStep Build-Compilers $HostArch
27572794}
27582795
0 commit comments