@@ -419,10 +419,18 @@ $KnownPythons = @{
419419 URL = " https://www.nuget.org/api/v2/package/python/3.10.1" ;
420420 SHA256 = " 987a0e446d68900f58297bc47dc7a235ee4640a49dace58bc9f573797d3a8b33" ;
421421 };
422+ AMD64_Embedded = @ {
423+ URL = " https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-amd64.zip" ;
424+ SHA256 = " 502670dcdff0083847abf6a33f30be666594e7e5201cd6fccd4a523b577403de" ;
425+ };
422426 ARM64 = @ {
423427 URL = " https://www.nuget.org/api/v2/package/pythonarm64/3.10.1" ;
424428 SHA256 = " 16becfccedf1269ff0b8695a13c64fac2102a524d66cecf69a8f9229a43b10d3" ;
425429 };
430+ ARM64_Embedded = @ {
431+ URL = " https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-arm64.zip" ;
432+ SHA256 = " 1f9e215fe4e8f22a8e8fba1859efb1426437044fb3103ce85794630e3b511bc2" ;
433+ };
426434 };
427435}
428436
@@ -751,6 +759,10 @@ function Get-PythonPath([Hashtable] $Platform) {
751759 return [IO.Path ]::Combine(" $BinaryCache \" , " Python$ ( $Platform.Architecture.CMakeName ) -$PythonVersion " )
752760}
753761
762+ function Get-EmbeddedPythonPath ([Hashtable ] $Platform ) {
763+ return [IO.Path ]::Combine(" $BinaryCache \" , " EmbeddedPython$ ( $Platform.Architecture.CMakeName ) -$PythonVersion " )
764+ }
765+
754766function Get-PythonExecutable {
755767 return [IO.Path ]::Combine((Get-PythonPath $BuildPlatform ), " tools" , " python.exe" )
756768}
@@ -759,6 +771,10 @@ function Get-PythonScriptsPath {
759771 return [IO.Path ]::Combine((Get-PythonPath $BuildPlatform ), " tools" , " Scripts" )
760772}
761773
774+ function Get-EmbeddedPythonInstallDir () {
775+ return [IO.Path ]::Combine(" $ImageRoot \" , " Program Files" , " Swift" , " Python-$PythonVersion " )
776+ }
777+
762778function Get-Syft {
763779 return $KnownSyft [$SyftVersion ][$BuildArchName ]
764780}
@@ -1129,6 +1145,10 @@ function Invoke-VsDevShell([Hashtable] $Platform) {
11291145 }
11301146}
11311147
1148+ function Get-PythonLibName () {
1149+ return " python{0}{1}" -f ([System.Version ]$PythonVersion ).Major, ([System.Version ]$PythonVersion ).Minor
1150+ }
1151+
11321152function Get-Dependencies {
11331153 Record- OperationTime $BuildPlatform " Get-Dependencies" {
11341154 function Write-Success ([string ] $Description ) {
@@ -1262,18 +1282,20 @@ function Get-Dependencies {
12621282 Write-Success " syft $SyftVersion "
12631283 }
12641284
1265- function Get-KnownPython ([string ] $ArchName ) {
1285+ function Get-KnownPython ([string ] $ArchName , [ bool ] $EmbeddedPython = $false ) {
12661286 if (-not $KnownPythons.ContainsKey ($PythonVersion )) {
12671287 throw " Unknown python version: $PythonVersion "
12681288 }
1269- return $KnownPythons [$PythonVersion ].$ArchName
1289+ $Key = $ (if ($EmbeddedPython ) { " ${ArchName} _Embedded" } else { $ArchName })
1290+ return $KnownPythons [$PythonVersion ][$Key ]
12701291 }
12711292
1272- function Install-Python ([string ] $ArchName ) {
1273- $Python = Get-KnownPython $ArchName
1274- DownloadAndVerify $Python.URL " $BinaryCache \Python$ArchName -$PythonVersion .zip" $Python.SHA256
1293+ function Install-Python ([string ] $ArchName , [bool ] $EmbeddedPython = $false ) {
1294+ $Python = Get-KnownPython $ArchName $EmbeddedPython
1295+ $FileName = $ (if ($EmbeddedPython ) { " EmbeddedPython$ArchName -$PythonVersion " } else { " Python$ArchName -$PythonVersion " })
1296+ DownloadAndVerify $Python.URL " $BinaryCache \$FileName .zip" $Python.SHA256
12751297 if (-not $ToBatch ) {
1276- Expand-ZipFile Python $ArchName - $PythonVersion .zip " $BinaryCache " Python $ArchName - $PythonVersion
1298+ Expand-ZipFile " $FileName .zip" " $BinaryCache " " $FileName "
12771299 Write-Success " $ArchName Python $PythonVersion "
12781300 }
12791301 }
@@ -1328,8 +1350,10 @@ function Get-Dependencies {
13281350
13291351 # Ensure Python modules that are required as host build tools
13301352 Install-Python $HostArchName
1353+ Install-Python $HostArchName $true
13311354 if ($IsCrossCompiling ) {
13321355 Install-Python $BuildArchName
1356+ Install-Python $BuildArchName $true
13331357 }
13341358 Install-PythonModules
13351359
@@ -2209,7 +2233,7 @@ function Build-CDispatch([Hashtable] $Platform, [switch] $Static = $false) {
22092233function Get-CompilersDefines ([Hashtable ] $Platform , [string ] $Variant , [switch ] $Test ) {
22102234 $BuildTools = [IO.Path ]::Combine((Get-ProjectBinaryCache $BuildPlatform BuildTools), " bin" )
22112235 $PythonRoot = [IO.Path ]::Combine((Get-PythonPath $Platform ), " tools" )
2212- $PythonLibName = " python{0}{1} " -f ([ System.Version ] $PythonVersion ).Major , ([ System.Version ] $PythonVersion ).Minor
2236+ $PythonLibName = Get-PythonLibName
22132237
22142238 $TestDefines = if ($Test ) {
22152239 @ {
@@ -2253,6 +2277,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [string] $Variant, [switch]
22532277 LLDB_PYTHON_EXE_RELATIVE_PATH = " python.exe" ;
22542278 LLDB_PYTHON_EXT_SUFFIX = " .pyd" ;
22552279 LLDB_PYTHON_RELATIVE_PATH = " lib/site-packages" ;
2280+ LLDB_PYTHON_DLL_RELATIVE_PATH = " ../../../../Python-$PythonVersion /usr/bin" ;
22562281 LLDB_TABLEGEN = (Join-Path - Path $BuildTools - ChildPath " lldb-tblgen.exe" );
22572282 LLDB_TEST_MAKE = " $BinaryCache \GnuWin32Make-4.4.1\bin\make.exe" ;
22582283 LLVM_CONFIG_PATH = (Join-Path - Path $BuildTools - ChildPath " llvm-config.exe" );
@@ -2277,6 +2302,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [string] $Variant, [switch]
22772302 Python3_INCLUDE_DIR = " $PythonRoot \include" ;
22782303 Python3_LIBRARY = " $PythonRoot \libs\$PythonLibName .lib" ;
22792304 Python3_ROOT_DIR = $PythonRoot ;
2305+ Python3_VERSION = $PythonVersion ;
22802306 SWIFT_TOOLCHAIN_VERSION = " ${ToolchainIdentifier} " ;
22812307 SWIFT_BUILD_SWIFT_SYNTAX = " YES" ;
22822308 SWIFT_CLANG_LOCATION = (Get-PinnedToolchainToolsDir );
@@ -4002,6 +4028,12 @@ function Install-HostToolchain() {
40024028 Copy-Item - Force `
40034029 - Path $SwiftDriver `
40044030 - Destination " $ ( $HostPlatform.ToolchainInstallRoot ) \usr\bin\swiftc.exe"
4031+
4032+ # Copy embeddable Python
4033+ New-Item - Type Directory - Path " $ ( Get-EmbeddedPythonInstallDir ) " - ErrorAction Ignore | Out-Null
4034+ Copy-Item - Force - Recurse `
4035+ - Path " $ ( Get-EmbeddedPythonPath $HostPlatform ) \*" `
4036+ - Destination " $ ( Get-EmbeddedPythonInstallDir ) "
40054037}
40064038
40074039function Build-Inspect ([Hashtable ] $Platform ) {
@@ -4100,6 +4132,7 @@ function Build-Installer([Hashtable] $Platform) {
41004132 INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC ;
41014133 SWIFT_DOCC_BUILD = " $ ( Get-ProjectBinaryCache $HostPlatform DocC) \release" ;
41024134 SWIFT_DOCC_RENDER_ARTIFACT_ROOT = " ${SourceCache} \swift-docc-render-artifact" ;
4135+ PythonVersion = $PythonVersion
41034136 }
41044137
41054138 Invoke-IsolatingEnvVars {
0 commit comments