Skip to content

Commit fa7e118

Browse files
Merge pull request #85693 from charles-zablit/charles-zablit/windows/upgrade-python-to-3.10-to-release-6.2
🍒 [windows] add Embeddable Python 3.10.1 to build.ps1
2 parents a6aa30f + 783cd84 commit fa7e118

File tree

1 file changed

+60
-13
lines changed

1 file changed

+60
-13
lines changed

utils/build.ps1

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ param
139139
[ValidateSet("Asserts", "NoAsserts")]
140140
[string] $PinnedToolchainVariant = "Asserts",
141141
[ValidatePattern('^\d+(\.\d+)*$')]
142-
[string] $PythonVersion = "3.9.10",
142+
[string] $PythonVersion = "3.10.1",
143143
[ValidatePattern("^r(?:[1-9]|[1-9][0-9])(?:[a-z])?$")]
144144
[string] $AndroidNDKVersion = "r27c",
145145
[ValidatePattern("^\d+\.\d+\.\d+(?:-\w+)?")]
@@ -348,7 +348,25 @@ $KnownPythons = @{
348348
URL = "https://www.nuget.org/api/v2/package/pythonarm64/3.9.10";
349349
SHA256 = "429ada77e7f30e4bd8ff22953a1f35f98b2728e84c9b1d006712561785641f69";
350350
};
351-
}
351+
};
352+
"3.10.1" = @{
353+
AMD64 = @{
354+
URL = "https://www.nuget.org/api/v2/package/python/3.10.1";
355+
SHA256 = "987a0e446d68900f58297bc47dc7a235ee4640a49dace58bc9f573797d3a8b33";
356+
};
357+
AMD64_Embedded = @{
358+
URL = "https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-amd64.zip";
359+
SHA256 = "502670dcdff0083847abf6a33f30be666594e7e5201cd6fccd4a523b577403de";
360+
};
361+
ARM64 = @{
362+
URL = "https://www.nuget.org/api/v2/package/pythonarm64/3.10.1";
363+
SHA256 = "16becfccedf1269ff0b8695a13c64fac2102a524d66cecf69a8f9229a43b10d3";
364+
};
365+
ARM64_Embedded = @{
366+
URL = "https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-arm64.zip";
367+
SHA256 = "1f9e215fe4e8f22a8e8fba1859efb1426437044fb3103ce85794630e3b511bc2";
368+
};
369+
};
352370
}
353371

354372
$PythonWheels = @{
@@ -527,6 +545,10 @@ function Get-PythonPath([Hashtable] $Platform) {
527545
return [IO.Path]::Combine("$BinaryCache\", "Python$($Platform.Architecture.CMakeName)-$PythonVersion")
528546
}
529547

548+
function Get-EmbeddedPythonPath([Hashtable] $Platform) {
549+
return [IO.Path]::Combine("$BinaryCache\", "EmbeddedPython$($Platform.Architecture.CMakeName)-$PythonVersion")
550+
}
551+
530552
function Get-PythonExecutable {
531553
return [IO.Path]::Combine((Get-PythonPath $BuildPlatform), "tools", "python.exe")
532554
}
@@ -535,6 +557,10 @@ function Get-PythonScriptsPath {
535557
return [IO.Path]::Combine((Get-PythonPath $BuildPlatform), "tools", "Scripts")
536558
}
537559

560+
function Get-EmbeddedPythonInstallDir() {
561+
return [IO.Path]::Combine("$ImageRoot\", "Program Files", "Swift", "Python-$PythonVersion")
562+
}
563+
538564
function Get-InstallDir([Hashtable] $Platform) {
539565
if ($Platform -eq $HostPlatform) {
540566
return [IO.Path]::Combine("$ImageRoot\", "Program Files", "Swift")
@@ -852,6 +878,10 @@ function Invoke-VsDevShell([Hashtable] $Platform) {
852878
}
853879
}
854880

881+
function Get-PythonLibName() {
882+
return "python{0}{1}" -f ([System.Version]$PythonVersion).Major, ([System.Version]$PythonVersion).Minor
883+
}
884+
855885
function Get-Dependencies {
856886
Write-Host "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Fetch-Dependencies ..." -ForegroundColor Cyan
857887
$ProgressPreference = "SilentlyContinue"
@@ -967,18 +997,21 @@ function Get-Dependencies {
967997
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache\toolchains | Out-Null
968998
Export-Toolchain "$PinnedToolchain.exe" $BinaryCache $PinnedToolchain
969999

970-
function Get-KnownPython([string] $ArchName) {
1000+
function Get-KnownPython([string] $ArchName, [bool] $EmbeddedPython = $false) {
9711001
if (-not $KnownPythons.ContainsKey($PythonVersion)) {
9721002
throw "Unknown python version: $PythonVersion"
9731003
}
974-
return $KnownPythons[$PythonVersion].$ArchName
1004+
$Key = $(if ($EmbeddedPython) { "${ArchName}_Embedded" } else { $ArchName })
1005+
return $KnownPythons[$PythonVersion][$Key]
9751006
}
9761007

977-
function Install-Python([string] $ArchName) {
978-
$Python = Get-KnownPython $ArchName
979-
DownloadAndVerify $Python.URL "$BinaryCache\Python$ArchName-$PythonVersion.zip" $Python.SHA256
1008+
function Install-Python([string] $ArchName, [bool] $EmbeddedPython = $false) {
1009+
$Python = Get-KnownPython $ArchName $EmbeddedPython
1010+
$FileName = $(if ($EmbeddedPython) { "EmbeddedPython$ArchName-$PythonVersion" } else { "Python$ArchName-$PythonVersion" })
1011+
DownloadAndVerify $Python.URL "$BinaryCache\$FileName.zip" $Python.SHA256
9801012
if (-not $ToBatch) {
981-
Expand-ZipFile Python$ArchName-$PythonVersion.zip "$BinaryCache" Python$ArchName-$PythonVersion
1013+
Expand-ZipFile "$FileName.zip" "$BinaryCache" "$FileName"
1014+
Write-Output "$ArchName Python $PythonVersion installed."
9821015
}
9831016
}
9841017

@@ -1017,12 +1050,13 @@ function Get-Dependencies {
10171050
}
10181051
}
10191052

1053+
# Ensure Python modules that are required as host build tools
10201054
Install-Python $HostArchName
1055+
Install-Python $HostArchName $true
10211056
if ($IsCrossCompiling) {
10221057
Install-Python $BuildArchName
1058+
Install-Python $BuildArchName $true
10231059
}
1024-
1025-
# Ensure Python modules that are required as host build tools
10261060
Install-PythonModules
10271061

10281062
if ($Android) {
@@ -1706,7 +1740,7 @@ function Load-LitTestOverrides($Filename) {
17061740
function Get-CompilersDefines([Hashtable] $Platform, [switch] $Test) {
17071741
$BuildTools = [IO.Path]::Combine((Get-ProjectBinaryCache $BuildPlatform BuildTools), "bin")
17081742
$PythonRoot = [IO.Path]::Combine((Get-PythonPath $Platform), "tools")
1709-
$PythonLibName = "python{0}{1}" -f ([System.Version]$PythonVersion).Major, ([System.Version]$PythonVersion).Minor
1743+
$PythonLibName = Get-PythonLibName
17101744

17111745
$TestDefines = if ($Test) {
17121746
@{
@@ -1745,6 +1779,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [switch] $Test) {
17451779
LLDB_PYTHON_EXE_RELATIVE_PATH = "python.exe";
17461780
LLDB_PYTHON_EXT_SUFFIX = ".pyd";
17471781
LLDB_PYTHON_RELATIVE_PATH = "lib/site-packages";
1782+
LLDB_PYTHON_DLL_RELATIVE_PATH = "../../../../Python-$PythonVersion/usr/bin";
17481783
LLDB_TABLEGEN = (Join-Path -Path $BuildTools -ChildPath "lldb-tblgen.exe");
17491784
LLDB_TEST_MAKE = "$BinaryCache\GnuWin32Make-4.4.1\bin\make.exe";
17501785
LLVM_CONFIG_PATH = (Join-Path -Path $BuildTools -ChildPath "llvm-config.exe");
@@ -1758,6 +1793,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [switch] $Test) {
17581793
Python3_INCLUDE_DIR = "$PythonRoot\include";
17591794
Python3_LIBRARY = "$PythonRoot\libs\$PythonLibName.lib";
17601795
Python3_ROOT_DIR = $PythonRoot;
1796+
Python3_VERSION = $PythonVersion;
17611797
SWIFT_TOOLCHAIN_VERSION = "${ToolchainIdentifier}";
17621798
SWIFT_BUILD_SWIFT_SYNTAX = "YES";
17631799
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainToolsDir);
@@ -3072,8 +3108,18 @@ function Install-HostToolchain() {
30723108

30733109
# Switch to swift-driver
30743110
$SwiftDriver = ([IO.Path]::Combine((Get-ProjectBinaryCache $HostPlatform Driver), "bin", "swift-driver.exe"))
3075-
Copy-Item -Force $SwiftDriver "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swift.exe"
3076-
Copy-Item -Force $SwiftDriver "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swiftc.exe"
3111+
Copy-Item -Force `
3112+
-Path $SwiftDriver `
3113+
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swift.exe"
3114+
Copy-Item -Force `
3115+
-Path $SwiftDriver `
3116+
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swiftc.exe"
3117+
3118+
# Copy embeddable Python
3119+
New-Item -Type Directory -Path "$(Get-EmbeddedPythonInstallDir)" -ErrorAction Ignore | Out-Null
3120+
Copy-Item -Force -Recurse `
3121+
-Path "$(Get-EmbeddedPythonPath $HostPlatform)\*" `
3122+
-Destination "$(Get-EmbeddedPythonInstallDir)"
30773123
}
30783124

30793125
function Build-Inspect([Hashtable] $Platform) {
@@ -3146,6 +3192,7 @@ function Build-Installer([Hashtable] $Platform) {
31463192
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC;
31473193
SWIFT_DOCC_BUILD = "$(Get-ProjectBinaryCache $HostPlatform DocC)\release";
31483194
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact";
3195+
PythonVersion = $PythonVersion
31493196
}
31503197

31513198
Invoke-IsolatingEnvVars {

0 commit comments

Comments
 (0)