@@ -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,20 +1282,32 @@ 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 }
1301+ if (-not $EmbeddedPython ) {
1302+ return
1303+ }
1304+ $PythonPTHPath = " $BinaryCache /$FileName /$ ( Get-PythonLibName ) ._pth"
1305+ $PythonPTHContent = [System.IO.File ]::ReadAllText($PythonPTHPath ).Replace(" #import site" , " import site" )
1306+ [System.IO.File ]::WriteAllText($PythonPTHPath , $PythonPTHContent )
1307+ $GetPipURL = " https://bootstrap.pypa.io/get-pip.py"
1308+ $GetPipPath = " $BinaryCache /$FileName /get-pip.py"
1309+ $WebClient.DownloadFile ($GetPipURL , $GetPipPath )
1310+ & " $BinaryCache /$FileName /python.exe" $GetPipPath
12791311 }
12801312
12811313 function Install-PIPIfNeeded {
@@ -1328,8 +1360,10 @@ function Get-Dependencies {
13281360
13291361 # Ensure Python modules that are required as host build tools
13301362 Install-Python $HostArchName
1363+ Install-Python $HostArchName $true
13311364 if ($IsCrossCompiling ) {
13321365 Install-Python $BuildArchName
1366+ Install-Python $BuildArchName $true
13331367 }
13341368 Install-PythonModules
13351369
@@ -2209,7 +2243,7 @@ function Build-CDispatch([Hashtable] $Platform, [switch] $Static = $false) {
22092243function Get-CompilersDefines ([Hashtable ] $Platform , [string ] $Variant , [switch ] $Test ) {
22102244 $BuildTools = [IO.Path ]::Combine((Get-ProjectBinaryCache $BuildPlatform BuildTools), " bin" )
22112245 $PythonRoot = [IO.Path ]::Combine((Get-PythonPath $Platform ), " tools" )
2212- $PythonLibName = " python{0}{1} " -f ([ System.Version ] $PythonVersion ).Major , ([ System.Version ] $PythonVersion ).Minor
2246+ $PythonLibName = Get-PythonLibName
22132247
22142248 $TestDefines = if ($Test ) {
22152249 @ {
@@ -2253,6 +2287,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [string] $Variant, [switch]
22532287 LLDB_PYTHON_EXE_RELATIVE_PATH = " python.exe" ;
22542288 LLDB_PYTHON_EXT_SUFFIX = " .pyd" ;
22552289 LLDB_PYTHON_RELATIVE_PATH = " lib/site-packages" ;
2290+ LLDB_PYTHON_DLL_RELATIVE_PATH = " ../../../../Python-$PythonVersion " ;
22562291 LLDB_TABLEGEN = (Join-Path - Path $BuildTools - ChildPath " lldb-tblgen.exe" );
22572292 LLDB_TEST_MAKE = " $BinaryCache \GnuWin32Make-4.4.1\bin\make.exe" ;
22582293 LLVM_CONFIG_PATH = (Join-Path - Path $BuildTools - ChildPath " llvm-config.exe" );
@@ -2277,6 +2312,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [string] $Variant, [switch]
22772312 Python3_INCLUDE_DIR = " $PythonRoot \include" ;
22782313 Python3_LIBRARY = " $PythonRoot \libs\$PythonLibName .lib" ;
22792314 Python3_ROOT_DIR = $PythonRoot ;
2315+ Python3_VERSION = $PythonVersion ;
22802316 SWIFT_TOOLCHAIN_VERSION = " ${ToolchainIdentifier} " ;
22812317 SWIFT_BUILD_SWIFT_SYNTAX = " YES" ;
22822318 SWIFT_CLANG_LOCATION = (Get-PinnedToolchainToolsDir );
@@ -4002,6 +4038,12 @@ function Install-HostToolchain() {
40024038 Copy-Item - Force `
40034039 - Path $SwiftDriver `
40044040 - Destination " $ ( $HostPlatform.ToolchainInstallRoot ) \usr\bin\swiftc.exe"
4041+
4042+ # Copy embeddable Python
4043+ New-Item - Type Directory - Path " $ ( Get-EmbeddedPythonInstallDir ) " - ErrorAction Ignore | Out-Null
4044+ Copy-Item - Force - Recurse `
4045+ - Path " $ ( Get-EmbeddedPythonPath $HostPlatform ) \*" `
4046+ - Destination " $ ( Get-EmbeddedPythonInstallDir ) "
40054047}
40064048
40074049function Build-Inspect ([Hashtable ] $Platform ) {
@@ -4100,6 +4142,7 @@ function Build-Installer([Hashtable] $Platform) {
41004142 INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC ;
41014143 SWIFT_DOCC_BUILD = " $ ( Get-ProjectBinaryCache $HostPlatform DocC) \release" ;
41024144 SWIFT_DOCC_RENDER_ARTIFACT_ROOT = " ${SourceCache} \swift-docc-render-artifact" ;
4145+ PythonVersion = $PythonVersion
41034146 }
41044147
41054148 Invoke-IsolatingEnvVars {
0 commit comments