@@ -413,11 +413,19 @@ $KnownPythons = @{
413413 URL = " https://www.nuget.org/api/v2/package/python/3.10.1" ;
414414 SHA256 = " 987a0e446d68900f58297bc47dc7a235ee4640a49dace58bc9f573797d3a8b33" ;
415415 };
416+ AMD64_Embedded = @ {
417+ URL = " https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-amd64.zip" ;
418+ SHA256 = " 502670dcdff0083847abf6a33f30be666594e7e5201cd6fccd4a523b577403de" ;
419+ };
416420 ARM64 = @ {
417421 URL = " https://www.nuget.org/api/v2/package/pythonarm64/3.10.1" ;
418422 SHA256 = " 16becfccedf1269ff0b8695a13c64fac2102a524d66cecf69a8f9229a43b10d3" ;
419423 };
420- };
424+ ARM64_Embedded = @ {
425+ URL = " https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-arm64.zip" ;
426+ SHA256 = " 1f9e215fe4e8f22a8e8fba1859efb1426437044fb3103ce85794630e3b511bc2" ;
427+ };
428+ }
421429}
422430
423431$PythonModules = @ {
@@ -741,6 +749,10 @@ function Get-PythonPath([Hashtable] $Platform) {
741749 return [IO.Path ]::Combine(" $BinaryCache \" , " Python$ ( $Platform.Architecture.CMakeName ) -$PythonVersion " )
742750}
743751
752+ function Get-EmbeddedPythonPath ([Hashtable ] $Platform ) {
753+ return [IO.Path ]::Combine(" $BinaryCache \" , " EmbeddedPython$ ( $Platform.Architecture.CMakeName ) -$PythonVersion " )
754+ }
755+
744756function Get-PythonExecutable {
745757 return [IO.Path ]::Combine((Get-PythonPath $BuildPlatform ), " tools" , " python.exe" )
746758}
@@ -749,6 +761,10 @@ function Get-PythonScriptsPath {
749761 return [IO.Path ]::Combine((Get-PythonPath $BuildPlatform ), " tools" , " Scripts" )
750762}
751763
764+ function Get-EmbeddedPythonInstallDir () {
765+ return [IO.Path ]::Combine(" $ImageRoot \" , " Program Files" , " Swift" , " Python-$PythonVersion " )
766+ }
767+
752768function Get-Syft {
753769 return $KnownSyft [$SyftVersion ][$BuildArchName ]
754770}
@@ -1243,18 +1259,20 @@ function Get-Dependencies {
12431259 New-Item - ItemType Directory - ErrorAction Ignore $BinaryCache \toolchains | Out-Null
12441260 Extract- Toolchain " $PinnedToolchain .exe" $BinaryCache $PinnedToolchain.TrimStart (" swift-" ).TrimEnd(" -a-windows10" )
12451261
1246- function Get-KnownPython ([string ] $ArchName ) {
1262+ function Get-KnownPython ([string ] $ArchName , [ bool ] $EmbeddedPython = $false ) {
12471263 if (-not $KnownPythons.ContainsKey ($PythonVersion )) {
12481264 throw " Unknown python version: $PythonVersion "
12491265 }
1250- return $KnownPythons [$PythonVersion ].$ArchName
1266+ $Key = $ (if ($EmbeddedPython ) { " ${ArchName} _Embedded" } else { $ArchName })
1267+ return $KnownPythons [$PythonVersion ][$Key ]
12511268 }
12521269
1253- function Install-Python ([string ] $ArchName ) {
1254- $Python = Get-KnownPython $ArchName
1255- DownloadAndVerify $Python.URL " $BinaryCache \Python$ArchName -$PythonVersion .zip" $Python.SHA256
1270+ function Install-Python ([string ] $ArchName , [bool ] $EmbeddedPython = $false ) {
1271+ $Python = Get-KnownPython $ArchName $EmbeddedPython
1272+ $FileName = $ (if ($EmbeddedPython ) { " EmbeddedPython$ArchName -$PythonVersion " } else { " Python$ArchName -$PythonVersion " })
1273+ DownloadAndVerify $Python.URL " $BinaryCache \$FileName .zip" $Python.SHA256
12561274 if (-not $ToBatch ) {
1257- Expand-ZipFile Python $ArchName - $PythonVersion .zip " $BinaryCache " Python $ArchName - $PythonVersion
1275+ Expand-ZipFile " $FileName .zip" " $BinaryCache " " $FileName "
12581276 }
12591277 }
12601278
@@ -1305,8 +1323,10 @@ function Get-Dependencies {
13051323 }
13061324
13071325 Install-Python $HostArchName
1326+ Install-Python $HostArchName $true
13081327 if ($IsCrossCompiling ) {
13091328 Install-Python $BuildArchName
1329+ Install-Python $BuildArchName $true
13101330 }
13111331
13121332 # Ensure Python modules that are required as host build tools
@@ -2163,6 +2183,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [string] $Variant, [switch]
21632183 LLDB_PYTHON_EXE_RELATIVE_PATH = " python.exe" ;
21642184 LLDB_PYTHON_EXT_SUFFIX = " .pyd" ;
21652185 LLDB_PYTHON_RELATIVE_PATH = " lib/site-packages" ;
2186+ LLDB_PYTHON_DLL_RELATIVE_PATH = " ../../../../Python-$PythonVersion " ;
21662187 LLDB_TABLEGEN = (Join-Path - Path $BuildTools - ChildPath " lldb-tblgen.exe" );
21672188 LLDB_TEST_MAKE = " $BinaryCache \GnuWin32Make-4.4.1\bin\make.exe" ;
21682189 LLVM_CONFIG_PATH = (Join-Path - Path $BuildTools - ChildPath " llvm-config.exe" );
@@ -2187,6 +2208,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [string] $Variant, [switch]
21872208 Python3_INCLUDE_DIR = " $PythonRoot \include" ;
21882209 Python3_LIBRARY = " $PythonRoot \libs\$PythonLibName .lib" ;
21892210 Python3_ROOT_DIR = $PythonRoot ;
2211+ Python3_VERSION = $PythonVersion ;
21902212 SWIFT_TOOLCHAIN_VERSION = " ${ToolchainIdentifier} " ;
21912213 SWIFT_BUILD_SWIFT_SYNTAX = " YES" ;
21922214 SWIFT_CLANG_LOCATION = (Get-PinnedToolchainToolsDir );
@@ -3831,6 +3853,12 @@ function Install-HostToolchain() {
38313853 Copy-Item - Force `
38323854 - Path $SwiftDriver `
38333855 - Destination " $ ( $HostPlatform.ToolchainInstallRoot ) \usr\bin\swiftc.exe"
3856+
3857+ # Copy embeddable Python
3858+ New-Item - Type Directory - Path " $ ( Get-EmbeddedPythonInstallDir ) " - ErrorAction Ignore | Out-Null
3859+ Copy-Item - Force - Recurse `
3860+ - Path " $ ( Get-EmbeddedPythonPath $HostPlatform ) \*" `
3861+ - Destination " $ ( Get-EmbeddedPythonInstallDir ) "
38343862}
38353863
38363864function Build-Inspect ([Hashtable ] $Platform ) {
@@ -3903,6 +3931,7 @@ function Build-Installer([Hashtable] $Platform) {
39033931 INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC ;
39043932 SWIFT_DOCC_BUILD = " $ ( Get-ProjectBinaryCache $HostPlatform DocC) \release" ;
39053933 SWIFT_DOCC_RENDER_ARTIFACT_ROOT = " ${SourceCache} \swift-docc-render-artifact" ;
3934+ PythonVersion = $PythonVersion
39063935 }
39073936
39083937 Invoke-IsolatingEnvVars {
0 commit comments