@@ -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$ ( $HostArch.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.
@@ -1456,6 +1485,9 @@ function Build-Compilers() {
1456
1485
}
1457
1486
}
1458
1487
1488
+ $PythonRoot = " $BinaryCache \Python$ ( $Arch.CMakeName ) -$PythonVersion \tools"
1489
+ $PythonLibName = " python{0}{1}" -f ([System.Version ]$PythonVersion ).Major, ([System.Version ]$PythonVersion ).Minor
1490
+
1459
1491
# The STL in VS 17.10 requires Clang 17 or higher, but Swift toolchains prior to version 6 include older versions
1460
1492
# of Clang. If bootstrapping with an older toolchain, we need to relax to relax this requirement with
1461
1493
# ALLOW_COMPILER_AND_STL_VERSION_MISMATCH.
@@ -1487,10 +1519,10 @@ function Build-Compilers() {
1487
1519
LLVM_NATIVE_TOOL_DIR = $BuildTools ;
1488
1520
LLVM_TABLEGEN = (Join-Path $BuildTools - ChildPath " llvm-tblgen.exe" );
1489
1521
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 " ;
1522
+ Python3_EXECUTABLE = ( Get-PythonExecutable ) ;
1523
+ Python3_INCLUDE_DIR = " $PythonRoot \include" ;
1524
+ Python3_LIBRARY = " $PythonRoot \ libs\$PythonLibName .lib" ;
1525
+ Python3_ROOT_DIR = $PythonRoot ;
1494
1526
SWIFT_BUILD_SWIFT_SYNTAX = " YES" ;
1495
1527
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool );
1496
1528
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = " YES" ;
@@ -1815,7 +1847,7 @@ function Build-Runtime([Platform]$Platform, $Arch) {
1815
1847
})
1816
1848
}
1817
1849
1818
- Invoke-Program $python - c " import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'DEFAULT_USE_RUNTIME': 'MD' } }), encoding='utf-8'))" `
1850
+ Invoke-Program " $ ( Get-PythonExecutable ) " - c " import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'DEFAULT_USE_RUNTIME': 'MD' } }), encoding='utf-8'))" `
1819
1851
- OutFile " $ ( $Arch.SDKInstallRoot ) \SDKSettings.plist"
1820
1852
}
1821
1853
@@ -2046,7 +2078,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
2046
2078
2047
2079
function Write-PlatformInfoPlist ($Arch ) {
2048
2080
$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'))" `
2081
+ 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
2082
- OutFile " $PList "
2051
2083
}
2052
2084
0 commit comments