Skip to content

Commit f258ce6

Browse files
[windows] upgrade to Python 3.10 embeddable
1 parent 016e55b commit f258ce6

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

utils/build.ps1

Lines changed: 61 additions & 5 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

@@ -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
}
@@ -1093,11 +1119,33 @@ function Get-Dependencies {
10931119
return $KnownPythons[$PythonVersion].$ArchName
10941120
}
10951121

1122+
function Get-KnownEmbeddedPython([string] $ArchName) {
1123+
if (-not $KnownPythons.ContainsKey($PythonVersion)) {
1124+
throw "Unknown python version: $PythonVersion"
1125+
}
1126+
if (-not $KnownPythons[$PythonVersion].ContainsKey("${ArchName}_Embedded")) {
1127+
return $null
1128+
}
1129+
return $KnownPythons[$PythonVersion]["${ArchName}_Embedded"]
1130+
}
1131+
10961132
function Install-Python([string] $ArchName) {
10971133
$Python = Get-KnownPython $ArchName
10981134
DownloadAndVerify $Python.URL "$BinaryCache\Python$ArchName-$PythonVersion.zip" $Python.SHA256
10991135
if (-not $ToBatch) {
1100-
Expand-ZipFile Python$ArchName-$PythonVersion.zip "$BinaryCache" Python$ArchName-$PythonVersion
1136+
Expand-ZipFile "Python$ArchName-$PythonVersion.zip" "$BinaryCache" "Python$ArchName-$PythonVersion"
1137+
}
1138+
}
1139+
1140+
function Install-EmbeddedPython([string] $ArchName) {
1141+
$Python = Get-KnownEmbeddedPython $ArchName
1142+
if ($Python -eq $null) {
1143+
Write-Output "Python $PythonVersion does not have an embeddable version."
1144+
return
1145+
}
1146+
DownloadAndVerify $Python.URL "$BinaryCache\EmbeddedPython$ArchName-$PythonVersion.zip" $Python.SHA256
1147+
if (-not $ToBatch) {
1148+
Expand-ZipFile "EmbeddedPython$ArchName-$PythonVersion.zip" "$BinaryCache" "EmbeddedPython$ArchName-$PythonVersion"
11011149
}
11021150
}
11031151

@@ -1148,6 +1196,7 @@ function Get-Dependencies {
11481196
}
11491197

11501198
Install-Python $HostArchName
1199+
Install-EmbeddedPython $HostArchName
11511200
if ($IsCrossCompiling) {
11521201
Install-Python $BuildArchName
11531202
}
@@ -3470,16 +3519,22 @@ function Install-HostToolchain() {
34703519

34713520
# Restructure _InternalSwiftScan (keep the original one for the installer)
34723521
Copy-Item -Force `
3473-
"$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\_InternalSwiftScan" `
3474-
"$($HostPlatform.ToolchainInstallRoot)\usr\include"
3522+
-Path "$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\_InternalSwiftScan" `
3523+
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\include"
34753524
Copy-Item -Force `
3476-
"$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\windows\_InternalSwiftScan.lib" `
3477-
"$($HostPlatform.ToolchainInstallRoot)\usr\lib"
3525+
-Path "$($HostPlatform.ToolchainInstallRoot)\usr\lib\swift\windows\_InternalSwiftScan.lib" `
3526+
-Destination "$($HostPlatform.ToolchainInstallRoot)\usr\lib"
34783527

34793528
# Switch to swift-driver
34803529
$SwiftDriver = ([IO.Path]::Combine((Get-ProjectBinaryCache $HostPlatform Driver), "bin", "swift-driver.exe"))
34813530
Copy-Item -Force $SwiftDriver "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swift.exe"
34823531
Copy-Item -Force $SwiftDriver "$($HostPlatform.ToolchainInstallRoot)\usr\bin\swiftc.exe"
3532+
3533+
# Copy embeddable Python
3534+
New-Item -Type Directory -Path "$(Get-EmbeddedPythonInstallDir)" -ErrorAction Ignore | Out-Null
3535+
Copy-Item -Force -Recurse `
3536+
-Path "$(Get-EmbeddedPythonPath $HostPlatform)\*" `
3537+
-Destination "$(Get-EmbeddedPythonInstallDir)"
34833538
}
34843539

34853540
function Build-Inspect([Hashtable] $Platform) {
@@ -3550,6 +3605,7 @@ function Build-Installer([Hashtable] $Platform) {
35503605
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC;
35513606
SWIFT_DOCC_BUILD = "$(Get-ProjectBinaryCache $HostPlatform DocC)\release";
35523607
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact";
3608+
PythonRoot = "$(Get-EmbeddedPythonInstallDir)"
35533609
}
35543610

35553611
Invoke-IsolatingEnvVars {

0 commit comments

Comments
 (0)