mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[build.ps1] don't use host Python any more (#76594)
* [build.ps1] don't use host Python any more * [build.ps1] fix compatibility with Windows Powershell * Try to address CI failure
This commit is contained in:
@@ -194,14 +194,6 @@ $WiXVersion = "4.0.5"
|
||||
# Avoid $env:ProgramFiles in case this script is running as x86
|
||||
$UnixToolsBinDir = "$env:SystemDrive\Program Files\Git\usr\bin"
|
||||
|
||||
$python = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Shared\Python39_64\python.exe"
|
||||
if (-not (Test-Path $python)) {
|
||||
$python = (where.exe python) | Select-Object -First 1
|
||||
if (-not (Test-Path $python)) {
|
||||
throw "Python.exe not found"
|
||||
}
|
||||
}
|
||||
|
||||
if ($Android -and ($AndroidSDKs.Length -eq 0)) {
|
||||
# Enable all android SDKs by default.
|
||||
$AndroidSDKs = @("aarch64","armv7","i686","x86_64")
|
||||
@@ -358,6 +350,10 @@ function Get-BisonExecutable {
|
||||
return Join-Path -Path $BinaryCache -ChildPath "win_flex_bison\win_bison.exe"
|
||||
}
|
||||
|
||||
function Get-PythonExecutable {
|
||||
return Join-Path -Path $BinaryCache -ChildPath "Python$($HostArch.CMakeName)-$PythonVersion\tools\python.exe"
|
||||
}
|
||||
|
||||
function Get-InstallDir($Arch) {
|
||||
if ($Arch -eq $HostArch) {
|
||||
$ProgramFilesName = "Program Files"
|
||||
@@ -747,10 +743,43 @@ function Fetch-Dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
function Ensure-PythonModules($Python) {
|
||||
# First ensure pip is installed, else bootstrap it
|
||||
try {
|
||||
Invoke-Program -OutNull $Python -m pip *> $null
|
||||
} catch {
|
||||
Write-Output "Installing pip ..."
|
||||
Invoke-Program -OutNull $Python '-I' -m ensurepip -U --default-pip
|
||||
}
|
||||
# 'packaging' is required for building LLVM 18+
|
||||
try {
|
||||
Invoke-Program -OutNull $Python -c 'import packaging' *> $null
|
||||
} catch {
|
||||
$WheelURL = "https://files.pythonhosted.org/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl"
|
||||
$WheelHash = "5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"
|
||||
DownloadAndVerify $WheelURL "$BinaryCache\python\packaging-24.1-py3-none-any.whl" $WheelHash
|
||||
Write-Output "Installing 'packaging-24.1-py3-none-any.whl' ..."
|
||||
Invoke-Program -OutNull $Python '-I' -m pip install "$BinaryCache\python\packaging-24.1-py3-none-any.whl" --disable-pip-version-check
|
||||
}
|
||||
# 'setuptools' provides 'distutils' module for Python 3.12+, required for SWIG support
|
||||
# https://github.com/swiftlang/llvm-project/issues/9289
|
||||
try {
|
||||
Invoke-Program -OutNull $Python -c 'import distutils' *> $null
|
||||
} catch {
|
||||
$WheelURL = "https://files.pythonhosted.org/packages/ff/ae/f19306b5a221f6a436d8f2238d5b80925004093fa3edea59835b514d9057/setuptools-75.1.0-py3-none-any.whl"
|
||||
$WheelHash = "35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2"
|
||||
DownloadAndVerify $WheelURL "$BinaryCache\python\setuptools-75.1.0-py3-none-any.whl" $WheelHash
|
||||
Write-Output "Installing 'setuptools-75.1.0-py3-none-any.whl' ..."
|
||||
Invoke-Program -OutNull $Python '-I' -m pip install "$BinaryCache\python\setuptools-75.1.0-py3-none-any.whl" --disable-pip-version-check
|
||||
}
|
||||
}
|
||||
|
||||
Download-Python $HostArchName
|
||||
if ($IsCrossCompiling) {
|
||||
Download-Python $BuildArchName
|
||||
}
|
||||
# Ensure Python modules that are required as host build tools
|
||||
Ensure-PythonModules "$(Get-PythonExecutable)"
|
||||
|
||||
if ($Android) {
|
||||
# Only a specific NDK version is supported right now.
|
||||
@@ -1456,6 +1485,9 @@ function Build-Compilers() {
|
||||
}
|
||||
}
|
||||
|
||||
$PythonRoot = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools"
|
||||
$PythonLibName = "python{0}{1}" -f ([System.Version]$PythonVersion).Major, ([System.Version]$PythonVersion).Minor
|
||||
|
||||
# The STL in VS 17.10 requires Clang 17 or higher, but Swift toolchains prior to version 6 include older versions
|
||||
# of Clang. If bootstrapping with an older toolchain, we need to relax to relax this requirement with
|
||||
# ALLOW_COMPILER_AND_STL_VERSION_MISMATCH.
|
||||
@@ -1487,10 +1519,10 @@ function Build-Compilers() {
|
||||
LLVM_NATIVE_TOOL_DIR = $BuildTools;
|
||||
LLVM_TABLEGEN = (Join-Path $BuildTools -ChildPath "llvm-tblgen.exe");
|
||||
LLVM_USE_HOST_TOOLS = "NO";
|
||||
Python3_EXECUTABLE = "$python";
|
||||
Python3_INCLUDE_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools\include";
|
||||
Python3_LIBRARY = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools\libs\python39.lib";
|
||||
Python3_ROOT_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools";
|
||||
Python3_EXECUTABLE = (Get-PythonExecutable);
|
||||
Python3_INCLUDE_DIR = "$PythonRoot\include";
|
||||
Python3_LIBRARY = "$PythonRoot\libs\$PythonLibName.lib";
|
||||
Python3_ROOT_DIR = $PythonRoot;
|
||||
SWIFT_BUILD_SWIFT_SYNTAX = "YES";
|
||||
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool);
|
||||
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
|
||||
@@ -1815,7 +1847,7 @@ function Build-Runtime([Platform]$Platform, $Arch) {
|
||||
})
|
||||
}
|
||||
|
||||
Invoke-Program $python -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'DEFAULT_USE_RUNTIME': 'MD' } }), encoding='utf-8'))" `
|
||||
Invoke-Program "$(Get-PythonExecutable)" -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'DEFAULT_USE_RUNTIME': 'MD' } }), encoding='utf-8'))" `
|
||||
-OutFile "$($Arch.SDKInstallRoot)\SDKSettings.plist"
|
||||
}
|
||||
|
||||
@@ -2046,7 +2078,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
|
||||
|
||||
function Write-PlatformInfoPlist($Arch) {
|
||||
$PList = Join-Path -Path $Arch.PlatformInstallRoot -ChildPath "Info.plist"
|
||||
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'))" `
|
||||
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'))" `
|
||||
-OutFile "$PList"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user