Skip to content

Commit 1fc553e

Browse files
[windows] upgrade to Python 3.10 embeddable
1 parent 14e5ba6 commit 1fc553e

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

utils/build.ps1

Lines changed: 57 additions & 1 deletion
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

@@ -597,6 +615,10 @@ function Get-PythonPath([Hashtable] $Platform) {
597615
return [IO.Path]::Combine("$BinaryCache\", "Python$($Platform.Architecture.CMakeName)-$PythonVersion")
598616
}
599617

618+
function Get-EmbeddedPythonPath([Hashtable] $Platform) {
619+
return [IO.Path]::Combine("$BinaryCache\", "EmbeddedPython$($Platform.Architecture.CMakeName)-$PythonVersion")
620+
}
621+
600622
function Get-PythonExecutable {
601623
return [IO.Path]::Combine((Get-PythonPath $BuildPlatform), "tools", "python.exe")
602624
}
@@ -605,6 +627,10 @@ function Get-PythonScriptsPath {
605627
return [IO.Path]::Combine((Get-PythonPath $BuildPlatform), "tools", "Scripts")
606628
}
607629

630+
function Get-EmbeddedPythonInstallDir() {
631+
return [IO.Path]::Combine("$ImageRoot\", "Program Files", "Swift", "Python-$PythonVersion")
632+
}
633+
608634
function Get-Syft {
609635
return $KnownSyft[$SyftVersion][$BuildArchName]
610636
}
@@ -1098,11 +1124,33 @@ function Get-Dependencies {
10981124
return $KnownPythons[$PythonVersion].$ArchName
10991125
}
11001126

1127+
function Get-KnownEmbeddedPython([string] $ArchName) {
1128+
if (-not $KnownPythons.ContainsKey($PythonVersion)) {
1129+
throw "Unknown python version: $PythonVersion"
1130+
}
1131+
if (-not $KnownPythons[$PythonVersion].ContainsKey("${ArchName}_Embedded")) {
1132+
return $null
1133+
}
1134+
return $KnownPythons[$PythonVersion]["${ArchName}_Embedded"]
1135+
}
1136+
11011137
function Install-Python([string] $ArchName) {
11021138
$Python = Get-KnownPython $ArchName
11031139
DownloadAndVerify $Python.URL "$BinaryCache\Python$ArchName-$PythonVersion.zip" $Python.SHA256
11041140
if (-not $ToBatch) {
1105-
Expand-ZipFile Python$ArchName-$PythonVersion.zip "$BinaryCache" Python$ArchName-$PythonVersion
1141+
Expand-ZipFile "Python$ArchName-$PythonVersion.zip" "$BinaryCache" "Python$ArchName-$PythonVersion"
1142+
}
1143+
}
1144+
1145+
function Install-EmbeddedPython([string] $ArchName) {
1146+
$Python = Get-KnownEmbeddedPython $ArchName
1147+
if ($Python -eq $null) {
1148+
Write-Output "Python $PythonVersion does not have an embeddable version."
1149+
return
1150+
}
1151+
DownloadAndVerify $Python.URL "$BinaryCache\EmbeddedPython$ArchName-$PythonVersion.zip" $Python.SHA256
1152+
if (-not $ToBatch) {
1153+
Expand-ZipFile "EmbeddedPython$ArchName-$PythonVersion.zip" "$BinaryCache" "EmbeddedPython$ArchName-$PythonVersion"
11061154
}
11071155
}
11081156

@@ -1153,6 +1201,7 @@ function Get-Dependencies {
11531201
}
11541202

11551203
Install-Python $HostArchName
1204+
Install-EmbeddedPython $HostArchName
11561205
if ($IsCrossCompiling) {
11571206
Install-Python $BuildArchName
11581207
}
@@ -3528,6 +3577,12 @@ function Install-HostToolchain() {
35283577
Copy-Item -Force `
35293578
-Path $SwiftDriver `
35303579
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swiftc.exe"
3580+
3581+
# Copy embeddable Python
3582+
New-Item -Type Directory -Path "$(Get-EmbeddedPythonInstallDir)" -ErrorAction Ignore | Out-Null
3583+
Copy-Item -Force -Recurse `
3584+
-Path "$(Get-EmbeddedPythonPath $HostPlatform)\*" `
3585+
-Destination "$(Get-EmbeddedPythonInstallDir)"
35313586
}
35323587

35333588
function Build-Inspect([Hashtable] $Platform) {
@@ -3598,6 +3653,7 @@ function Build-Installer([Hashtable] $Platform) {
35983653
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC;
35993654
SWIFT_DOCC_BUILD = "$(Get-ProjectBinaryCache $HostPlatform DocC)\release";
36003655
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact";
3656+
PythonRoot = "$(Get-EmbeddedPythonInstallDir)"
36013657
}
36023658

36033659
Invoke-IsolatingEnvVars {

0 commit comments

Comments
 (0)