@@ -69,32 +69,57 @@ rustup run $rustToolchain cargo --version
6969$cargoArguments = @ (' build' , ' --release' , ' --locked' )
7070$binaryPath = Join-Path $WORKER ' target\release\r2p2.exe'
7171if ($rustTarget ) {
72- if ($PythonVersion -notmatch ' ^(?<base>\d+\.\d+\.\d+)-(?<level>a|b|rc)\.?(?<serial>\d+)$' -and
73- $PythonVersion -notmatch ' ^(?<base>\d+\.\d+\.\d+)$' ) {
74- throw " Unsupported Python version format for the CPython download: $PythonVersion "
75- }
76- $baseVersion = $Matches.base
77- $artifactVersion = if ($Matches.level ) {
78- " $baseVersion $ ( $Matches.level ) $ ( $Matches.serial ) "
72+ if ($PythonVersion -match ' ^(?<major>\d+)\.(?<minor>\d+)$' ) {
73+ $requestedMajorMinor = " $ ( $Matches.major ) .$ ( $Matches.minor ) "
74+ $selectedPythonVersions = python - c ' import sys; v = sys.version_info; suffix = "" if v.releaselevel == "final" else {"alpha": "a", "beta": "b", "candidate": "rc"}[v.releaselevel] + str(v.serial); print(f"{v.major}.{v.minor}.{v.micro}|{v.major}.{v.minor}.{v.micro}{suffix}")'
75+ if ($LASTEXITCODE -ne 0 ) {
76+ throw ' Unable to determine the selected Python interpreter version.'
77+ }
78+ $resolvedVersions = $selectedPythonVersions.Trim () -split ' \|' , 2
79+ if ($resolvedVersions.Count -ne 2 ) {
80+ throw " Unexpected selected Python version: $selectedPythonVersions "
81+ }
82+ $baseVersion = $resolvedVersions [0 ]
83+ $artifactVersion = $resolvedVersions [1 ]
84+ if ($baseVersion -notmatch ' ^(?<major>\d+)\.(?<minor>\d+)\.\d+$' -or
85+ " $ ( $Matches.major ) .$ ( $Matches.minor ) " -ne $requestedMajorMinor ) {
86+ throw " Python $PythonVersion was requested, but the selected interpreter is $baseVersion ."
87+ }
88+ } elseif ($PythonVersion -match ' ^(?<base>\d+\.\d+\.\d+)-(?<level>a|b|rc)\.?(?<serial>\d+)$' ) {
89+ $baseVersion = $Matches.base
90+ $artifactVersion = " $baseVersion $ ( $Matches.level ) $ ( $Matches.serial ) "
91+ } elseif ($PythonVersion -match ' ^(?<base>\d+\.\d+\.\d+)$' ) {
92+ $baseVersion = $Matches.base
93+ $artifactVersion = $baseVersion
7994 } else {
80- $baseVersion
95+ throw " Unsupported Python version format for the CPython download: $PythonVersion "
8196 }
8297 if ($baseVersion -notmatch ' ^(?<major>\d+)\.(?<minor>\d+)' ) {
8398 throw " Unable to determine the Python major/minor version from $PythonVersion "
8499 }
85100 $pythonMajorMinor = " $ ( $Matches.major ) .$ ( $Matches.minor ) "
86101 $pythonLibrary = " python$ ( $Matches.major ) $ ( $Matches.minor ) .lib"
87102 $pythonSdk = Join-Path $env: AGENT_TEMPDIRECTORY " cpython-$artifactVersion -arm64"
88- $pythonArchive = Join-Path $env: AGENT_TEMPDIRECTORY " python-$artifactVersion -arm64.zip"
89- $pythonUrl = " https://www.python.org/ftp/python/$baseVersion /python-$artifactVersion -arm64.zip"
103+ $pythonArchive = $env: CPYTHON_ARM64_ARCHIVE
104+ if (-not $pythonArchive ) {
105+ throw " CPYTHON_ARM64_ARCHIVE must point to a pipeline-staged CPython $artifactVersion ARM64 SDK archive."
106+ }
107+ if (-not (Test-Path $pythonArchive - PathType Leaf)) {
108+ throw " The pipeline-staged CPython archive does not exist: $pythonArchive "
109+ }
90110
91- Invoke-WebRequest $pythonUrl - OutFile $pythonArchive
92111 Expand-Archive $pythonArchive - DestinationPath $pythonSdk - Force
93112 $pythonHeader = Join-Path $pythonSdk ' include\Python.h'
94113 $pythonImportLibrary = Join-Path $pythonSdk " libs\$pythonLibrary "
95114 if (-not (Test-Path $pythonHeader ) -or -not (Test-Path $pythonImportLibrary )) {
96115 throw " The ARM64 CPython SDK is missing $pythonHeader or $pythonImportLibrary ."
97116 }
117+ $patchLevelHeader = Join-Path $pythonSdk ' include\patchlevel.h'
118+ $versionMatch = Select-String - Path $patchLevelHeader - Pattern ' ^#define PY_VERSION\s+"([^"]+)"$'
119+ $sourcePythonVersion = $versionMatch.Matches.Groups [1 ].Value
120+ if ($sourcePythonVersion -ne $artifactVersion ) {
121+ throw " Expected CPython $artifactVersion SDK; archive contains $ ( if ($sourcePythonVersion ) { $sourcePythonVersion } else { ' an unknown version' }) ."
122+ }
98123
99124 $vswhere = Join-Path ${env: ProgramFiles(x86)} ' Microsoft Visual Studio\Installer\vswhere.exe'
100125 $vsInstall = & $vswhere - latest - products * `
@@ -127,7 +152,10 @@ rustup run $rustToolchain cargo @cargoArguments
127152Pop-Location
128153
129154# --- v2 + v1 runtimes + app SDK into the deps tree ------------------------
130- python - m pip install ./ runtimes/ v2 ./ runtimes/ v1 azure- functions `
155+ python - m pip install `
156+ azure- functions- runtime== 1.2 .1 `
157+ azure- functions- runtime- v1== 1.1 .0 `
158+ azure- functions `
131159 -- no- compile -- target $DEPS
132160
133161# --- Stage the runtime worker-directory layout ----------------------------
0 commit comments