@@ -194,14 +194,6 @@ $WiXVersion = "4.0.5"
194
194
# Avoid $env:ProgramFiles in case this script is running as x86
195
195
$UnixToolsBinDir = " $env: SystemDrive \Program Files\Git\usr\bin"
196
196
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
-
205
197
if ($Android -and ($AndroidSDKs.Length -eq 0 )) {
206
198
# Enable all android SDKs by default.
207
199
$AndroidSDKs = @ (" aarch64" , " armv7" , " i686" , " x86_64" )
@@ -358,6 +350,10 @@ function Get-BisonExecutable {
358
350
return Join-Path - Path $BinaryCache - ChildPath " win_flex_bison\win_bison.exe"
359
351
}
360
352
353
+ function Get-PythonExecutable {
354
+ return Join-Path - Path $BinaryCache - ChildPath " Python$ ( $BuildArch.CMakeName ) -$PythonVersion \tools\python.exe"
355
+ }
356
+
361
357
function Get-InstallDir ($Arch ) {
362
358
if ($Arch -eq $HostArch ) {
363
359
$ProgramFilesName = " Program Files"
@@ -747,10 +743,43 @@ function Fetch-Dependencies {
747
743
}
748
744
}
749
745
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
+
750
777
Download- Python $HostArchName
751
778
if ($IsCrossCompiling ) {
752
779
Download- Python $BuildArchName
753
780
}
781
+ # Ensure Python modules that are required as host build tools
782
+ Ensure- PythonModules " $ ( Get-PythonExecutable ) "
754
783
755
784
if ($Android ) {
756
785
# Only a specific NDK version is supported right now.
@@ -959,7 +988,6 @@ function Build-CMakeProject {
959
988
}
960
989
961
990
TryAdd- KeyValue $Defines CMAKE_BUILD_TYPE Release
962
- TryAdd- KeyValue $Defines CMAKE_MT " mt"
963
991
964
992
$CFlags = @ ()
965
993
switch ($Platform ) {
@@ -1382,6 +1410,8 @@ function Build-BuildTools($Arch) {
1382
1410
- 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 `
1383
1411
- Defines @ {
1384
1412
CMAKE_CROSSCOMPILING = " NO" ;
1413
+ CLANG_ENABLE_LIBXML2 = " NO" ;
1414
+ LLDB_ENABLE_LIBXML2 = " NO" ;
1385
1415
LLDB_ENABLE_PYTHON = " NO" ;
1386
1416
LLDB_INCLUDE_TESTS = " NO" ;
1387
1417
LLDB_ENABLE_SWIFT_SUPPORT = " NO" ;
@@ -1456,6 +1486,9 @@ function Build-Compilers() {
1456
1486
}
1457
1487
}
1458
1488
1489
+ $PythonRoot = " $BinaryCache \Python$ ( $Arch.CMakeName ) -$PythonVersion \tools"
1490
+ $PythonLibName = " python{0}{1}" -f ([System.Version ]$PythonVersion ).Major, ([System.Version ]$PythonVersion ).Minor
1491
+
1459
1492
# The STL in VS 17.10 requires Clang 17 or higher, but Swift toolchains prior to version 6 include older versions
1460
1493
# of Clang. If bootstrapping with an older toolchain, we need to relax to relax this requirement with
1461
1494
# ALLOW_COMPILER_AND_STL_VERSION_MISMATCH.
@@ -1477,7 +1510,9 @@ function Build-Compilers() {
1477
1510
- Defines ($TestingDefines + @ {
1478
1511
CLANG_TABLEGEN = (Join-Path - Path $BuildTools - ChildPath " clang-tblgen.exe" );
1479
1512
CLANG_TIDY_CONFUSABLE_CHARS_GEN = (Join-Path - Path $BuildTools - ChildPath " clang-tidy-confusable-chars-gen.exe" );
1513
+ CMAKE_FIND_PACKAGE_PREFER_CONFIG = " YES" ;
1480
1514
CMAKE_Swift_FLAGS = $SwiftFlags ;
1515
+ LibXml2_DIR = " $LibraryRoot \libxml2-2.11.5\usr\lib\Windows\$ ( $Arch.LLVMName ) \cmake\libxml2-2.11.5" ;
1481
1516
LLDB_PYTHON_EXE_RELATIVE_PATH = " python.exe" ;
1482
1517
LLDB_PYTHON_EXT_SUFFIX = " .pyd" ;
1483
1518
LLDB_PYTHON_RELATIVE_PATH = " lib/site-packages" ;
@@ -1487,10 +1522,10 @@ function Build-Compilers() {
1487
1522
LLVM_NATIVE_TOOL_DIR = $BuildTools ;
1488
1523
LLVM_TABLEGEN = (Join-Path $BuildTools - ChildPath " llvm-tblgen.exe" );
1489
1524
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 ;
1494
1529
SWIFT_BUILD_SWIFT_SYNTAX = " YES" ;
1495
1530
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool );
1496
1531
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = " YES" ;
@@ -1521,47 +1556,52 @@ function Build-Mimalloc() {
1521
1556
[hashtable ]$Arch
1522
1557
)
1523
1558
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 ) {
1563
1560
throw " mimalloc is currently supported for X64 only"
1564
1561
}
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
+ }
1565
1605
}
1566
1606
1567
1607
function Build-LLVM ([Platform ]$Platform , $Arch ) {
@@ -1815,7 +1855,7 @@ function Build-Runtime([Platform]$Platform, $Arch) {
1815
1855
})
1816
1856
}
1817
1857
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'))" `
1819
1859
- OutFile " $ ( $Arch.SDKInstallRoot ) \SDKSettings.plist"
1820
1860
}
1821
1861
@@ -1900,14 +1940,9 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
1900
1940
- Defines (@ {
1901
1941
ENABLE_TESTING = " NO" ;
1902
1942
FOUNDATION_BUILD_TOOLS = if ($Platform -eq " Windows" ) { " YES" } else { " NO" };
1943
+ CMAKE_FIND_PACKAGE_PREFER_CONFIG = " YES" ;
1903
1944
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" ;
1911
1946
ZLIB_LIBRARY = if ($Platform -eq " Windows" ) {
1912
1947
" $LibraryRoot \zlib-1.3.1\usr\lib\$Platform \$ShortArch \zlibstatic.lib"
1913
1948
} else {
@@ -2046,7 +2081,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
2046
2081
2047
2082
function Write-PlatformInfoPlist ($Arch ) {
2048
2083
$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'))" `
2050
2085
- OutFile " $PList "
2051
2086
}
2052
2087
@@ -2746,13 +2781,15 @@ if (-not $SkipBuild) {
2746
2781
Invoke-BuildStep Build-CMark $BuildArch
2747
2782
Invoke-BuildStep Build-BuildTools $BuildArch
2748
2783
if ($IsCrossCompiling ) {
2784
+ Invoke-BuildStep Build-XML2 Windows $BuildArch
2749
2785
Invoke-BuildStep Build-Compilers - Build $BuildArch
2750
2786
}
2751
2787
if ($IncludeDS2 ) {
2752
2788
Invoke-BuildStep Build-RegsGen2 $BuildArch
2753
2789
}
2754
2790
2755
2791
Invoke-BuildStep Build-CMark $HostArch
2792
+ Invoke-BuildStep Build-XML2 Windows $HostArch
2756
2793
Invoke-BuildStep Build-Compilers $HostArch
2757
2794
}
2758
2795
0 commit comments