Skip to content

Commit bd4476a

Browse files
[windows] upgrade to Python 3.10 embeddable
1 parent 330326a commit bd4476a

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
@@ -332,6 +332,24 @@ $KnownPythons = @{
332332
URL = "https://www.nuget.org/api/v2/package/pythonarm64/3.9.10";
333333
SHA256 = "429ada77e7f30e4bd8ff22953a1f35f98b2728e84c9b1d006712561785641f69";
334334
};
335+
};
336+
"3.10.1" = @{
337+
AMD64 = @{
338+
URL = "https://www.nuget.org/api/v2/package/python/3.10.1";
339+
SHA256 = "987a0e446d68900f58297bc47dc7a235ee4640a49dace58bc9f573797d3a8b33";
340+
};
341+
AMD64_Embedded = @{
342+
URL = "https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-amd64.zip";
343+
SHA256 = "502670dcdff0083847abf6a33f30be666594e7e5201cd6fccd4a523b577403de";
344+
};
345+
ARM64 = @{
346+
URL = "https://www.nuget.org/api/v2/package/pythonarm64/3.10.1";
347+
SHA256 = "16becfccedf1269ff0b8695a13c64fac2102a524d66cecf69a8f9229a43b10d3";
348+
};
349+
ARM64_Embedded = @{
350+
URL = "https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-arm64.zip";
351+
SHA256 = "1f9e215fe4e8f22a8e8fba1859efb1426437044fb3103ce85794630e3b511bc2";
352+
};
335353
}
336354
}
337355

@@ -351,11 +369,6 @@ $PythonModules = @{
351369
SHA256 = "353815f59a7f64cdaca1c0307ee13558a0512f6db064e92fe833784f08539c7a";
352370
Dependencies = @();
353371
};
354-
"unittest2" = @{
355-
Version = "1.1.0";
356-
SHA256 = "22882a0e418c284e1f718a822b3b022944d53d2d908e1690b319a9d3eb2c0579";
357-
Dependencies = @("argparse", "six", "traceback2", "linecache2");
358-
};
359372
"argparse" = @{
360373
Version = "1.4.0";
361374
SHA256 = "c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314";
@@ -602,6 +615,10 @@ function Get-PythonPath([Hashtable] $Platform) {
602615
return [IO.Path]::Combine("$BinaryCache\", "Python$($Platform.Architecture.CMakeName)-$PythonVersion")
603616
}
604617

618+
function Get-EmbeddedPythonPath([Hashtable] $Platform) {
619+
return [IO.Path]::Combine("$BinaryCache\", "EmbeddedPython$($Platform.Architecture.CMakeName)-$PythonVersion")
620+
}
621+
605622
function Get-PythonExecutable {
606623
return [IO.Path]::Combine((Get-PythonPath $BuildPlatform), "tools", "python.exe")
607624
}
@@ -610,6 +627,10 @@ function Get-PythonScriptsPath {
610627
return [IO.Path]::Combine((Get-PythonPath $BuildPlatform), "tools", "Scripts")
611628
}
612629

630+
function Get-EmbeddedPythonInstallDir() {
631+
return [IO.Path]::Combine("$ImageRoot\", "Program Files", "Swift", "Python")
632+
}
633+
613634
function Get-Syft {
614635
return $KnownSyft[$SyftVersion][$BuildArchName]
615636
}
@@ -1097,11 +1118,33 @@ function Get-Dependencies {
10971118
return $KnownPythons[$PythonVersion].$ArchName
10981119
}
10991120

1121+
function Get-KnownEmbeddedPython([string] $ArchName) {
1122+
if (-not $KnownPythons.ContainsKey($PythonVersion)) {
1123+
throw "Unknown python version: $PythonVersion"
1124+
}
1125+
if (-not $KnownPythons[$PythonVersion].ContainsKey("${ArchName}_Embedded")) {
1126+
return $null
1127+
}
1128+
return $KnownPythons[$PythonVersion]["${ArchName}_Embedded"]
1129+
}
1130+
11001131
function Install-Python([string] $ArchName) {
11011132
$Python = Get-KnownPython $ArchName
11021133
DownloadAndVerify $Python.URL "$BinaryCache\Python$ArchName-$PythonVersion.zip" $Python.SHA256
11031134
if (-not $ToBatch) {
1104-
Expand-ZipFile Python$ArchName-$PythonVersion.zip "$BinaryCache" Python$ArchName-$PythonVersion
1135+
Expand-ZipFile "Python$ArchName-$PythonVersion.zip" "$BinaryCache" "Python$ArchName-$PythonVersion"
1136+
}
1137+
}
1138+
1139+
function Install-EmbeddedPython([string] $ArchName) {
1140+
$Python = Get-KnownEmbeddedPython $ArchName
1141+
if ($Python -eq $null) {
1142+
Write-Output "Python $PythonVersion does not have an embeddable version."
1143+
return
1144+
}
1145+
DownloadAndVerify $Python.URL "$BinaryCache\EmbeddedPython$ArchName-$PythonVersion.zip" $Python.SHA256
1146+
if (-not $ToBatch) {
1147+
Expand-ZipFile "EmbeddedPython$ArchName-$PythonVersion.zip" "$BinaryCache" "EmbeddedPython$ArchName-$PythonVersion"
11051148
}
11061149
}
11071150

@@ -1149,11 +1192,11 @@ function Get-Dependencies {
11491192
if ($Test -contains "lldb") {
11501193
Install-PythonModule "psutil" # Required for testing LLDB
11511194
$env:Path = "$(Get-PythonScriptsPath);$env:Path" # For unit.exe
1152-
Install-PythonModule "unittest2" # Required for testing LLDB
11531195
}
11541196
}
11551197

11561198
Install-Python $HostArchName
1199+
Install-EmbeddedPython $HostArchName
11571200
if ($IsCrossCompiling) {
11581201
Install-Python $BuildArchName
11591202
}
@@ -3450,16 +3493,24 @@ function Install-HostToolchain() {
34503493

34513494
# Restructure _InternalSwiftScan (keep the original one for the installer)
34523495
Copy-Item -Force `
3453-
"$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\_InternalSwiftScan" `
3454-
"$($HostPlatform.ToolchainInstallRoot)\usr\include"
3496+
-Path "$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\_InternalSwiftScan" `
3497+
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\include"
34553498
Copy-Item -Force `
3456-
"$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\windows\_InternalSwiftScan.lib" `
3457-
"$($HostPlatform.ToolchainInstallRoot)\usr\lib"
3499+
-Path "$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\windows\_InternalSwiftScan.lib" `
3500+
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\lib"
34583501

34593502
# Switch to swift-driver
34603503
$SwiftDriver = ([IO.Path]::Combine((Get-ProjectBinaryCache $HostPlatform Driver), "bin", "swift-driver.exe"))
34613504
Copy-Item -Force $SwiftDriver "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swift.exe"
34623505
Copy-Item -Force $SwiftDriver "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swiftc.exe"
3506+
3507+
# Copy embeddable Python
3508+
New-Item -Type Directory -Path "$(Get-EmbeddedPythonInstallDir)" -ErrorAction Ignore | Out-Null
3509+
Write-Output "$(Get-EmbeddedPythonInstallDir)"
3510+
Copy-Item -Force `
3511+
-Path "$(Get-EmbeddedPythonPath $HostPlatform)\*" `
3512+
-Destination "$(Get-EmbeddedPythonInstallDir)" `
3513+
-Recurse
34633514
}
34643515

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

0 commit comments

Comments
 (0)