Skip to content

Commit bc91500

Browse files
[windows] upgrade to Python 3.10 embeddable
1 parent 37ae8a2 commit bc91500

File tree

1 file changed

+62
-11
lines changed

1 file changed

+62
-11
lines changed

utils/build.ps1

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,24 @@ $KnownPythons = @{
330330
URL = "https://www.nuget.org/api/v2/package/pythonarm64/3.9.10";
331331
SHA256 = "429ada77e7f30e4bd8ff22953a1f35f98b2728e84c9b1d006712561785641f69";
332332
};
333+
};
334+
"3.10.1" = @{
335+
AMD64 = @{
336+
URL = "https://www.nuget.org/api/v2/package/python/3.10.1";
337+
SHA256 = "987a0e446d68900f58297bc47dc7a235ee4640a49dace58bc9f573797d3a8b33";
338+
};
339+
AMD64_Embedded = @{
340+
URL = "https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-amd64.zip";
341+
SHA256 = "502670dcdff0083847abf6a33f30be666594e7e5201cd6fccd4a523b577403de";
342+
};
343+
ARM64 = @{
344+
URL = "https://www.nuget.org/api/v2/package/pythonarm64/3.10.1";
345+
SHA256 = "16becfccedf1269ff0b8695a13c64fac2102a524d66cecf69a8f9229a43b10d3";
346+
};
347+
ARM64_Embedded = @{
348+
URL = "https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-arm64.zip";
349+
SHA256 = "1f9e215fe4e8f22a8e8fba1859efb1426437044fb3103ce85794630e3b511bc2";
350+
};
333351
}
334352
}
335353

@@ -349,11 +367,6 @@ $PythonModules = @{
349367
SHA256 = "353815f59a7f64cdaca1c0307ee13558a0512f6db064e92fe833784f08539c7a";
350368
Dependencies = @();
351369
};
352-
"unittest2" = @{
353-
Version = "1.1.0";
354-
SHA256 = "22882a0e418c284e1f718a822b3b022944d53d2d908e1690b319a9d3eb2c0579";
355-
Dependencies = @("argparse", "six", "traceback2", "linecache2");
356-
};
357370
"argparse" = @{
358371
Version = "1.4.0";
359372
SHA256 = "c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314";
@@ -590,6 +603,10 @@ function Get-PythonPath([Hashtable] $Platform) {
590603
return [IO.Path]::Combine("$BinaryCache\", "Python$($Platform.Architecture.CMakeName)-$PythonVersion")
591604
}
592605

606+
function Get-EmbeddedPythonPath([Hashtable] $Platform) {
607+
return [IO.Path]::Combine("$BinaryCache\", "EmbeddedPython$($Platform.Architecture.CMakeName)-$PythonVersion")
608+
}
609+
593610
function Get-PythonExecutable {
594611
return [IO.Path]::Combine((Get-PythonPath $BuildPlatform), "tools", "python.exe")
595612
}
@@ -598,6 +615,10 @@ function Get-PythonScriptsPath {
598615
return [IO.Path]::Combine((Get-PythonPath $BuildPlatform), "tools", "Scripts")
599616
}
600617

618+
function Get-EmbeddedPythonInstallDir() {
619+
return [IO.Path]::Combine("$ImageRoot\", "Program Files", "Swift", "Python")
620+
}
621+
601622
function Get-InstallDir([Hashtable] $Platform) {
602623
if ($Platform -eq $HostPlatform) {
603624
return [IO.Path]::Combine("$ImageRoot\", "Program Files", "Swift")
@@ -1067,11 +1088,33 @@ function Get-Dependencies {
10671088
return $KnownPythons[$PythonVersion].$ArchName
10681089
}
10691090

1091+
function Get-KnownEmbeddedPython([string] $ArchName) {
1092+
if (-not $KnownPythons.ContainsKey($PythonVersion)) {
1093+
throw "Unknown python version: $PythonVersion"
1094+
}
1095+
if (-not $KnownPythons[$PythonVersion].ContainsKey("${ArchName}_Embedded")) {
1096+
return $null
1097+
}
1098+
return $KnownPythons[$PythonVersion]["${ArchName}_Embedded"]
1099+
}
1100+
10701101
function Install-Python([string] $ArchName) {
10711102
$Python = Get-KnownPython $ArchName
10721103
DownloadAndVerify $Python.URL "$BinaryCache\Python$ArchName-$PythonVersion.zip" $Python.SHA256
10731104
if (-not $ToBatch) {
1074-
Expand-ZipFile Python$ArchName-$PythonVersion.zip "$BinaryCache" Python$ArchName-$PythonVersion
1105+
Expand-ZipFile "Python$ArchName-$PythonVersion.zip" "$BinaryCache" "Python$ArchName-$PythonVersion"
1106+
}
1107+
}
1108+
1109+
function Install-EmbeddedPython([string] $ArchName) {
1110+
$Python = Get-KnownEmbeddedPython $ArchName
1111+
if ($Python -eq $null) {
1112+
Write-Output "Python $PythonVersion does not have an embeddable version."
1113+
return
1114+
}
1115+
DownloadAndVerify $Python.URL "$BinaryCache\EmbeddedPython$ArchName-$PythonVersion.zip" $Python.SHA256
1116+
if (-not $ToBatch) {
1117+
Expand-ZipFile "EmbeddedPython$ArchName-$PythonVersion.zip" "$BinaryCache" "EmbeddedPython$ArchName-$PythonVersion"
10751118
}
10761119
}
10771120

@@ -1119,11 +1162,11 @@ function Get-Dependencies {
11191162
if ($Test -contains "lldb") {
11201163
Install-PythonModule "psutil" # Required for testing LLDB
11211164
$env:Path = "$(Get-PythonScriptsPath);$env:Path" # For unit.exe
1122-
Install-PythonModule "unittest2" # Required for testing LLDB
11231165
}
11241166
}
11251167

11261168
Install-Python $HostArchName
1169+
Install-EmbeddedPython $HostArchName
11271170
if ($IsCrossCompiling) {
11281171
Install-Python $BuildArchName
11291172
}
@@ -3442,16 +3485,24 @@ function Install-HostToolchain() {
34423485

34433486
# Restructure _InternalSwiftScan (keep the original one for the installer)
34443487
Copy-Item -Force `
3445-
"$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\_InternalSwiftScan" `
3446-
"$($HostPlatform.ToolchainInstallRoot)\usr\include"
3488+
-Path "$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\_InternalSwiftScan" `
3489+
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\include"
34473490
Copy-Item -Force `
3448-
"$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\windows\_InternalSwiftScan.lib" `
3449-
"$($HostPlatform.ToolchainInstallRoot)\usr\lib"
3491+
-Path "$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\windows\_InternalSwiftScan.lib" `
3492+
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\lib"
34503493

34513494
# Switch to swift-driver
34523495
$SwiftDriver = ([IO.Path]::Combine((Get-ProjectBinaryCache $HostPlatform Driver), "bin", "swift-driver.exe"))
34533496
Copy-Item -Force $SwiftDriver "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swift.exe"
34543497
Copy-Item -Force $SwiftDriver "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swiftc.exe"
3498+
3499+
# Copy embeddable Python
3500+
New-Item -Type Directory -Path "$(Get-EmbeddedPythonInstallDir)" -ErrorAction Ignore | Out-Null
3501+
Write-Output "$(Get-EmbeddedPythonInstallDir)"
3502+
Copy-Item -Force `
3503+
-Path "$(Get-EmbeddedPythonPath $HostPlatform)\*" `
3504+
-Destination "$(Get-EmbeddedPythonInstallDir)" `
3505+
-Recurse
34553506
}
34563507

34573508
function Build-Inspect([Hashtable] $Platform) {

0 commit comments

Comments
 (0)