-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathpackage-core-steps.yml
More file actions
256 lines (229 loc) · 11 KB
/
package-core-steps.yml
File metadata and controls
256 lines (229 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# Steps to collect per-platform FLC native binaries, organize into NuGet layout,
# pack + sign the NuGet package, and build Python wheels (wheel package name and
# platforms depend on the isWinML parameter). The parent job must download all
# platform artifacts and checkout neutron-server.
parameters:
- name: version
type: string
- name: isRelease
type: boolean
default: false
- name: isWinML
type: boolean
default: false
- name: prereleaseId
type: string
default: ''
- name: platforms
type: object # list of { name, artifactName }
steps:
- task: PowerShell@2
displayName: 'Set source paths'
inputs:
targetType: inline
script: |
$nsRoot = "$(Build.SourcesDirectory)"
Write-Host "##vso[task.setvariable variable=nsRoot]$nsRoot"
- task: PowerShell@2
displayName: 'Organize native binaries'
inputs:
targetType: inline
script: |
$unifiedPath = "$(Build.ArtifactStagingDirectory)/unified"
New-Item -ItemType Directory -Path $unifiedPath -Force | Out-Null
$platformsJson = @'
${{ convertToJson(parameters.platforms) }}
'@
$platforms = $platformsJson | ConvertFrom-Json
foreach ($p in $platforms) {
$srcDir = "$(Pipeline.Workspace)/$($p.artifactName)"
Write-Host "Looking for artifacts at: $srcDir"
if (-not (Test-Path $srcDir)) {
throw "Artifact directory $srcDir does not exist. All platform artifacts must be present to produce a complete NuGet package."
}
$destDir = "$unifiedPath/runtimes/$($p.name)/native"
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
# WinML artifacts include WindowsAppRuntime Bootstrapper DLLs in addition
# to Microsoft.AI.Foundry.Local.Core.*.
$isWinML = "${{ parameters.isWinML }}" -eq "True"
if ($isWinML) {
Get-ChildItem $srcDir -File |
Where-Object { $_.Name -like "Microsoft.AI.Foundry.Local.Core.*" -or $_.Name -eq "Microsoft.WindowsAppRuntime.Bootstrap.dll" } |
Copy-Item -Destination $destDir -Force
} else {
Get-ChildItem $srcDir -File | Where-Object { $_.Name -like "Microsoft.AI.Foundry.Local.Core.*" } |
Copy-Item -Destination $destDir -Force
}
Write-Host "Copied $($p.name) binaries to $destDir"
}
# Copy build integration files from neutron-server
$nsRoot = "$(nsRoot)"
foreach ($dir in @("build", "buildTransitive")) {
$src = "$nsRoot/src/FoundryLocalCore/Core/$dir"
if (Test-Path $src) {
Copy-Item -Path $src -Destination "$unifiedPath/$dir" -Recurse -Force
}
}
$license = "$nsRoot/src/FoundryLocalCore/Core/LICENSE.txt"
if (Test-Path $license) {
Copy-Item $license "$unifiedPath/LICENSE.txt" -Force
}
# Compute version
- task: PowerShell@2
displayName: 'Set FLC package version'
inputs:
targetType: inline
script: |
$v = "${{ parameters.version }}"
$preId = "${{ parameters.prereleaseId }}"
if ($preId -ne '' -and $preId -ne 'none') {
$v = "$v-$preId"
} elseif ("${{ parameters.isRelease }}" -ne "True") {
$ts = Get-Date -Format "yyyyMMddHHmm"
$commitId = "$(Build.SourceVersion)".Substring(0, 8)
$v = "$v-dev-$ts-$commitId"
}
Write-Host "##vso[task.setvariable variable=flcVersion]$v"
Write-Host "FLC version: $v"
# Pack NuGet
- task: PowerShell@2
displayName: 'Pack FLC NuGet'
inputs:
targetType: inline
script: |
$nsRoot = "$(nsRoot)"
[xml]$propsXml = Get-Content "$nsRoot/Directory.Packages.props"
$pg = $propsXml.Project.PropertyGroup
$outDir = "$(Build.ArtifactStagingDirectory)/flc-nuget"
New-Item -ItemType Directory -Path $outDir -Force | Out-Null
if ("${{ parameters.isWinML }}" -eq "True") {
$nuspec = "$nsRoot/src/FoundryLocalCore/Core/WinMLNuget.nuspec"
$id = "Microsoft.AI.Foundry.Local.Core.WinML"
$ortVer = $pg.OnnxRuntimeFoundryVersionForWinML
$genaiVer = $pg.OnnxRuntimeGenAIFoundryVersion
$winAppSdkVer = $pg.WinAppSdkVersion
$props = "id=$id;version=$(flcVersion);commitId=$(Build.SourceVersion);OnnxRuntimeFoundryVersionForWinML=$ortVer;OnnxRuntimeGenAIFoundryVersion=$genaiVer;WinAppSdkVersion=$winAppSdkVer"
} else {
$nuspec = "$nsRoot/src/FoundryLocalCore/Core/NativeNuget.nuspec"
$id = "Microsoft.AI.Foundry.Local.Core"
$ortVer = $pg.OnnxRuntimeFoundryVersion
$genaiVer = $pg.OnnxRuntimeGenAIFoundryVersion
$props = "id=$id;version=$(flcVersion);commitId=$(Build.SourceVersion);OnnxRuntimeFoundryVersion=$ortVer;OnnxRuntimeGenAIFoundryVersion=$genaiVer"
}
$nugetArgs = @(
'pack', $nuspec,
'-OutputDirectory', $outDir,
'-BasePath', "$(Build.ArtifactStagingDirectory)/unified",
'-Properties', $props,
'-Symbols', '-SymbolPackageFormat', 'snupkg'
)
Write-Host "Running: nuget $($nugetArgs -join ' ')"
& nuget $nugetArgs
if ($LASTEXITCODE -ne 0) { throw "NuGet pack failed" }
# Sign NuGet package
- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@5
displayName: 'Sign FLC NuGet package'
inputs:
ConnectedServiceName: 'OnnxrunTimeCodeSign_20240611'
UseMSIAuthentication: true
AppRegistrationClientId: '$(esrpClientId)'
AppRegistrationTenantId: '$(esrpTenantId)'
EsrpClientId: '$(esrpClientId)'
AuthAKVName: '$(esrpAkvName)'
AuthSignCertName: '$(esrpSignCertName)'
FolderPath: '$(Build.ArtifactStagingDirectory)/flc-nuget'
Pattern: '*.nupkg'
SessionTimeout: 90
ServiceEndpointUrl: 'https://api.esrp.microsoft.com/api/v2'
MaxConcurrency: 25
signConfigType: inlineSignParams
inlineOperation: |
[{"keyCode":"CP-401405","operationSetCode":"NuGetSign","parameters":[],"toolName":"sign","toolVersion":"6.2.9304.0"},{"keyCode":"CP-401405","operationSetCode":"NuGetVerify","parameters":[],"toolName":"sign","toolVersion":"6.2.9304.0"}]
# Build Python wheels from the NuGet package
- task: PowerShell@2
displayName: 'Build foundry_local_core Python Wheels'
inputs:
targetType: inline
script: |
$stagingDir = "$(Build.ArtifactStagingDirectory)/flc-wheels"
New-Item -ItemType Directory -Path $stagingDir -Force | Out-Null
$isWinML = "${{ parameters.isWinML }}" -eq "True"
# Find and extract the NuGet package (.nupkg is a zip archive)
$nupkgFilter = if ($isWinML) { "Microsoft.AI.Foundry.Local.Core.WinML*.nupkg" } else { "Microsoft.AI.Foundry.Local.Core*.nupkg" }
$nupkg = Get-ChildItem "$(Build.ArtifactStagingDirectory)/flc-nuget" -Filter $nupkgFilter | Where-Object { $_.Name -notlike "*.snupkg" } | Select-Object -First 1
if (-not $nupkg) { throw "No FLC .nupkg found matching $nupkgFilter" }
Write-Host "Found NuGet package: $($nupkg.Name)"
$extractDir = "$(Build.ArtifactStagingDirectory)/flc-extracted"
$nupkgZip = [System.IO.Path]::ChangeExtension($nupkg.FullName, ".zip")
Copy-Item -Path $nupkg.FullName -Destination $nupkgZip -Force
Expand-Archive -Path $nupkgZip -DestinationPath $extractDir -Force
# Convert NuGet version to PEP 440
# NuGet: 1.0.0-dev-202603271723-bb400310 → PEP 440: 1.0.0.dev202603271723
# The commit hash is dropped because .devN requires N to be a pure integer.
$nupkgVersion = $nupkg.BaseName -replace '^Microsoft\.AI\.Foundry\.Local\.Core(\.WinML)?\.', ''
$parts = $nupkgVersion -split '-'
$pyVersion = if ($parts.Count -ge 3 -and $parts[1] -eq 'dev') { "$($parts[0]).dev$($parts[2])" }
elseif ($parts.Count -eq 2) { "$($parts[0])$($parts[1])" }
else { $parts[0] }
Write-Host "Python package version: $pyVersion"
$packageName = if ($isWinML) { "foundry_local_core_winml" } else { "foundry_local_core" }
if ($isWinML) {
$platforms = @(
@{rid="win-x64"; pyKey="bin"; tag="win_amd64"},
@{rid="win-arm64"; pyKey="bin"; tag="win_arm64"}
)
} else {
$platforms = @(
@{rid="win-x64"; pyKey="bin"; tag="win_amd64"},
@{rid="win-arm64"; pyKey="bin"; tag="win_arm64"},
@{rid="linux-x64"; pyKey="bin"; tag="manylinux_2_28_x86_64"},
@{rid="osx-arm64"; pyKey="bin"; tag="macosx_11_0_arm64"}
)
}
foreach ($p in $platforms) {
$nativeSrc = "$extractDir/runtimes/$($p.rid)/native"
if (-not (Test-Path $nativeSrc)) {
Write-Warning "No native binaries found for $($p.rid) — skipping."
continue
}
$wheelRoot = "$(Build.ArtifactStagingDirectory)/wheels-build/flc_wheel_$($p.tag)"
$pkgDir = "$wheelRoot/$packageName"
New-Item -ItemType Directory -Path "$pkgDir/$($p.pyKey)" -Force | Out-Null
"" | Set-Content -Encoding ascii "$pkgDir/__init__.py"
Get-ChildItem $nativeSrc -File | Copy-Item -Destination "$pkgDir/$($p.pyKey)"
$normalizedName = $packageName.Replace('_', '-')
$wheelTag = "py3-none-$($p.tag)"
$distInfoName = "$packageName-$pyVersion"
$wheelName = "$distInfoName-$wheelTag.whl"
$distInfoDir = "$wheelRoot/$distInfoName.dist-info"
New-Item -ItemType Directory -Path $distInfoDir -Force | Out-Null
$utf8NoBom = [System.Text.UTF8Encoding]::new($false)
[System.IO.File]::WriteAllText("$distInfoDir/WHEEL",
"Wheel-Version: 1.0`nGenerator: custom`nRoot-Is-Purelib: false`nTag: $wheelTag`n", $utf8NoBom)
[System.IO.File]::WriteAllText("$distInfoDir/METADATA",
"Metadata-Version: 2.1`nName: $normalizedName`nVersion: $pyVersion`n", $utf8NoBom)
$recordLines = Get-ChildItem $wheelRoot -Recurse -File | ForEach-Object {
$rel = $_.FullName.Substring($wheelRoot.Length + 1).Replace('\', '/')
$raw = (Get-FileHash $_.FullName -Algorithm SHA256).Hash
$bytes = [byte[]]::new($raw.Length / 2)
for ($i = 0; $i -lt $raw.Length; $i += 2) { $bytes[$i/2] = [Convert]::ToByte($raw.Substring($i, 2), 16) }
$b64 = [Convert]::ToBase64String($bytes) -replace '\+','-' -replace '/','_' -replace '=',''
"$rel,sha256=$b64,$($_.Length)"
}
$recordContent = ($recordLines + "$distInfoName.dist-info/RECORD,,") -join "`n"
[System.IO.File]::WriteAllText("$distInfoDir/RECORD", $recordContent, $utf8NoBom)
$wheelPath = "$stagingDir/$wheelName"
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zip = [System.IO.Compression.ZipFile]::Open($wheelPath, 'Create')
try {
Get-ChildItem $wheelRoot -Recurse -File | ForEach-Object {
$rel = $_.FullName.Substring($wheelRoot.Length + 1).Replace('\', '/')
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $_.FullName, $rel) | Out-Null
}
} finally {
$zip.Dispose()
}
Write-Host "Created wheel: $wheelName"
}
Write-Host "`nAll wheels:"
Get-ChildItem $stagingDir -Filter "*.whl" | ForEach-Object { Write-Host " $($_.Name)" }