Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 142 additions & 1 deletion .pipelines/foundry-local-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# Produces artifacts: flc-nuget, flc-nuget-winml, flc-wheels, flc-wheels-winml,
# cs-sdk, cs-sdk-winml, js-sdk, js-sdk-winml, python-sdk, python-sdk-winml,
# rust-sdk, rust-sdk-winml
# rust-sdk, rust-sdk-winml, cpp-sdk, cpp-sdk-winml

pr:
- main
Expand Down Expand Up @@ -643,6 +643,46 @@ extends:
# depsVersionsDir: '$(Pipeline.Workspace)/deps-versions-winml'
# outputDir: '$(Build.ArtifactStagingDirectory)/rust-sdk-winml'

# ── Build C++ SDK ──
- stage: build_cpp
displayName: 'Build C++ SDK'
dependsOn:
- build_core
jobs:
- job: cpp_sdk
displayName: 'Build'
pool:
name: onnxruntime-Win-CPU-2022
os: windows
templateContext:
inputs:
- input: pipelineArtifact
artifactName: 'version-info'
targetPath: '$(Pipeline.Workspace)/version-info'
- input: pipelineArtifact
artifactName: 'flc-nuget'
targetPath: '$(Pipeline.Workspace)/flc-nuget'
- input: pipelineArtifact
artifactName: 'deps-versions-standard'
targetPath: '$(Pipeline.Workspace)/deps-versions-standard'
outputs:
- output: pipelineArtifact
artifactName: 'cpp-sdk'
targetPath: '$(Build.ArtifactStagingDirectory)/cpp-sdk'
steps:
- checkout: self
- template: .pipelines/templates/checkout-steps.yml@self
parameters:
repoName: test-data-shared
- template: .pipelines/templates/build-cpp-steps.yml@self
parameters:
version: ${{ parameters.version }}
isRelease: ${{ parameters.isRelease }}
prereleaseId: ${{ parameters.prereleaseId }}
isWinML: false
flcNugetDir: '$(Pipeline.Workspace)/flc-nuget'
depsVersionsDir: '$(Pipeline.Workspace)/deps-versions-standard'

# ── Test C# SDK ──
- stage: test_cs
displayName: 'Test C#'
Expand Down Expand Up @@ -1003,6 +1043,36 @@ extends:
flcNugetDir: '$(Pipeline.Workspace)/flc-nuget'
depsVersionsDir: '$(Pipeline.Workspace)/deps-versions-standard'

# ── Test C++ SDK ──
- stage: test_cpp
displayName: 'Test C++'
dependsOn: build_cpp
jobs:
- job: test_cpp_win_x64
displayName: 'win-x64'
pool:
name: onnxruntime-Win-CPU-2022
os: windows
templateContext:
inputs:
- input: pipelineArtifact
artifactName: 'flc-nuget'
targetPath: '$(Pipeline.Workspace)/flc-nuget'
- input: pipelineArtifact
artifactName: 'deps-versions-standard'
targetPath: '$(Pipeline.Workspace)/deps-versions-standard'
steps:
- checkout: self
clean: true
- template: .pipelines/templates/checkout-steps.yml@self
parameters:
repoName: test-data-shared
- template: .pipelines/templates/test-cpp-steps.yml@self
parameters:
isWinML: false
flcNugetDir: '$(Pipeline.Workspace)/flc-nuget'
depsVersionsDir: '$(Pipeline.Workspace)/deps-versions-standard'

# ── Build FLC (WinML) ──
- stage: build_core_winml
displayName: 'Build Core (WinML)'
Expand Down Expand Up @@ -1283,6 +1353,47 @@ extends:
depsVersionsDir: '$(Pipeline.Workspace)/deps-versions-winml'
outputDir: '$(Build.ArtifactStagingDirectory)/python-sdk-winml'

# ── Build C++ SDK (WinML) ──
- stage: build_cpp_winml
displayName: 'Build C++ SDK (WinML)'
dependsOn:
- build_core_winml
jobs:
- job: cpp_sdk_winml
displayName: 'Build'
pool:
name: onnxruntime-Win-CPU-2022
os: windows
templateContext:
inputs:
- input: pipelineArtifact
artifactName: 'version-info'
targetPath: '$(Pipeline.Workspace)/version-info'
- input: pipelineArtifact
artifactName: 'flc-nuget-winml'
targetPath: '$(Pipeline.Workspace)/flc-nuget-winml'
- input: pipelineArtifact
artifactName: 'deps-versions-winml'
targetPath: '$(Pipeline.Workspace)/deps-versions-winml'
outputs:
- output: pipelineArtifact
artifactName: 'cpp-sdk-winml'
targetPath: '$(Build.ArtifactStagingDirectory)/cpp-sdk-winml'
steps:
- checkout: self
- template: .pipelines/templates/checkout-steps.yml@self
parameters:
repoName: test-data-shared
- template: .pipelines/templates/build-cpp-steps.yml@self
parameters:
version: ${{ parameters.version }}
isRelease: ${{ parameters.isRelease }}
prereleaseId: ${{ parameters.prereleaseId }}
isWinML: true
flcNugetDir: '$(Pipeline.Workspace)/flc-nuget-winml'
depsVersionsDir: '$(Pipeline.Workspace)/deps-versions-winml'
outputDir: '$(Build.ArtifactStagingDirectory)/cpp-sdk-winml'

# ── Test C# SDK (WinML) ──
- stage: test_cs_winml
displayName: 'Test C# (WinML)'
Expand Down Expand Up @@ -1377,3 +1488,33 @@ extends:
flcWheelsDir: '$(Pipeline.Workspace)/flc-wheels-winml'
sdkWheelsDir: '$(Pipeline.Workspace)/python-sdk-winml'
depsVersionsDir: '$(Pipeline.Workspace)/deps-versions-winml'

# ── Test C++ SDK (WinML) ──
- stage: test_cpp_winml
displayName: 'Test C++ (WinML)'
dependsOn: build_cpp_winml
jobs:
- job: test_cpp_winml_win_x64
displayName: 'win-x64'
pool:
name: onnxruntime-Win-CPU-2022
os: windows
templateContext:
inputs:
- input: pipelineArtifact
artifactName: 'flc-nuget-winml'
targetPath: '$(Pipeline.Workspace)/flc-nuget-winml'
- input: pipelineArtifact
artifactName: 'deps-versions-winml'
targetPath: '$(Pipeline.Workspace)/deps-versions-winml'
steps:
- checkout: self
clean: true
- template: .pipelines/templates/checkout-steps.yml@self
parameters:
repoName: test-data-shared
- template: .pipelines/templates/test-cpp-steps.yml@self
parameters:
isWinML: true
flcNugetDir: '$(Pipeline.Workspace)/flc-nuget-winml'
depsVersionsDir: '$(Pipeline.Workspace)/deps-versions-winml'
194 changes: 194 additions & 0 deletions .pipelines/templates/build-cpp-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# Steps to build and package the C++ SDK.
# When test-data-shared is checked out alongside self, ADO places repos under
# $(Build.SourcesDirectory)/<repo-name>. The self repo is 'Foundry-Local'.
parameters:
- name: version
type: string
- name: isRelease
type: boolean
default: false
- name: prereleaseId
type: string
default: ''
- name: isWinML
type: boolean
default: false
- name: flcNugetDir
type: string
displayName: 'Path to directory containing the FLC .nupkg'
- name: outputDir
type: string
default: '$(Build.ArtifactStagingDirectory)/cpp-sdk'
displayName: 'Path to directory for the packaged SDK'
- name: depsVersionsDir
type: string
default: ''
displayName: 'Path to deps-versions artifact directory'
steps:
# Set paths for multi-repo checkout
- task: PowerShell@2
displayName: 'Set source paths'
inputs:
targetType: inline
script: |
$multiCheckout = "$(Build.SourcesDirectory)/Foundry-Local"
if (Test-Path $multiCheckout) {
$repoRoot = $multiCheckout
} else {
$repoRoot = "$(Build.SourcesDirectory)"
}
$testDataDir = "$(Build.SourcesDirectory)/test-data-shared"
Write-Host "##vso[task.setvariable variable=repoRoot]$repoRoot"
Write-Host "##vso[task.setvariable variable=testDataDir]$testDataDir"

# Read version from the version-info artifact produced by compute_version stage.
- task: PowerShell@2
displayName: 'Set SDK version'
inputs:
targetType: inline
script: |
$v = (Get-Content "$(Pipeline.Workspace)/version-info/sdkVersion.txt" -Raw).Trim()
Write-Host "C++ SDK version: $v"

# Patch vcpkg.json version-string
$vcpkgPath = "$(repoRoot)/sdk/cpp/vcpkg.json"
$content = Get-Content $vcpkgPath -Raw
$content = $content -replace '"version-string"\s*:\s*"[^"]+"', "`"version-string`": `"$v`""
Set-Content -Path $vcpkgPath -Value $content
Write-Host "Patched vcpkg.json with version $v"

# Patch CMakeLists.txt project version
$cmakePath = "$(repoRoot)/sdk/cpp/CMakeLists.txt"
$content = Get-Content $cmakePath -Raw
$content = $content -replace 'project\(CppSdk\s+VERSION\s+[^\s]+', "project(CppSdk VERSION $v"
Set-Content -Path $cmakePath -Value $content
Write-Host "Patched CMakeLists.txt with version $v"

Write-Host "##vso[task.setvariable variable=cppSdkVersion]$v"

# List downloaded FLC artifact for debugging
- task: PowerShell@2
displayName: 'List downloaded FLC artifact'
inputs:
targetType: inline
script: |
Write-Host "Contents of ${{ parameters.flcNugetDir }}:"
Get-ChildItem "${{ parameters.flcNugetDir }}" -Recurse | ForEach-Object { Write-Host $_.FullName }

# Load dependency versions from deps_versions.json
- template: update-deps-versions-steps.yml
parameters:
repoRoot: $(repoRoot)
artifactDir: ${{ parameters.depsVersionsDir }}
isWinML: ${{ parameters.isWinML }}

# Extract FLC native binaries from the pipeline-built .nupkg so that
# the E2E tests can find the Core DLL next to the test binary.
- task: PowerShell@2
displayName: 'Extract FLC native binaries'
inputs:
targetType: inline
script: |
$nupkg = Get-ChildItem "${{ parameters.flcNugetDir }}" -Recurse -Filter "Microsoft.AI.Foundry.Local.Core*.nupkg" -Exclude "*.snupkg" | Select-Object -First 1
if (-not $nupkg) { throw "No FLC .nupkg found in ${{ parameters.flcNugetDir }}" }
Write-Host "Found NuGet package: $($nupkg.FullName)"

$extractDir = "$(Build.ArtifactStagingDirectory)/flc-extract-cpp"
$zip = [System.IO.Path]::ChangeExtension($nupkg.FullName, ".zip")
Copy-Item $nupkg.FullName $zip -Force
Expand-Archive -Path $zip -DestinationPath $extractDir -Force

# Determine RID for this agent
$arch = if ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq 'Arm64') { 'arm64' } else { 'x64' }
$rid = "win-$arch"

$nativeDir = "$extractDir/runtimes/$rid/native"
if (-not (Test-Path $nativeDir)) { throw "No native binaries found at $nativeDir for RID $rid" }

$flcNativeDir = "$(Build.ArtifactStagingDirectory)/flc-native-cpp"
New-Item -ItemType Directory -Path $flcNativeDir -Force | Out-Null
Get-ChildItem $nativeDir -File | Copy-Item -Destination $flcNativeDir -Force
Write-Host "##vso[task.setvariable variable=FOUNDRY_NATIVE_OVERRIDE_DIR]$flcNativeDir"
Write-Host "Extracted FLC native binaries to $flcNativeDir`:"
Get-ChildItem $flcNativeDir | ForEach-Object { Write-Host " $($_.Name)" }

# Ensure vcpkg is available
- task: PowerShell@2
displayName: 'Bootstrap vcpkg'
inputs:
targetType: inline
script: |
if ($env:VCPKG_ROOT -and (Test-Path "$env:VCPKG_ROOT/vcpkg.exe")) {
Write-Host "vcpkg already available at $env:VCPKG_ROOT"
} else {
$vcpkgDir = "$(Build.ArtifactStagingDirectory)/vcpkg"
git clone https://github.com/microsoft/vcpkg.git $vcpkgDir --depth 1
& "$vcpkgDir/bootstrap-vcpkg.bat" -disableMetrics
Write-Host "##vso[task.setvariable variable=VCPKG_ROOT]$vcpkgDir"
Write-Host "##vso[task.prependpath]$vcpkgDir"
Write-Host "Bootstrapped vcpkg at $vcpkgDir"
}

# Configure
- task: PowerShell@2
displayName: 'CMake configure'
inputs:
targetType: inline
script: |
Set-Location "$(repoRoot)/sdk/cpp"

$buildDir = "$(Build.ArtifactStagingDirectory)/cpp-build"
$installDir = "$(Build.ArtifactStagingDirectory)/cpp-install"

cmake -G Ninja `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_C_COMPILER=cl.exe `
-DCMAKE_CXX_COMPILER=cl.exe `
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" `
-DVCPKG_OVERLAY_TRIPLETS="$(repoRoot)/sdk/cpp/triplets" `
-DVCPKG_TARGET_TRIPLET=x64-windows-static-md `
-DCMAKE_INSTALL_PREFIX="$installDir" `
-DBUILD_TESTING=OFF `
-B "$buildDir" `
-S "$(repoRoot)/sdk/cpp"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

# Build
- task: PowerShell@2
displayName: 'CMake build'
inputs:
targetType: inline
script: |
$buildDir = "$(Build.ArtifactStagingDirectory)/cpp-build"
cmake --build $buildDir --config Release
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

# Install
- task: PowerShell@2
displayName: 'CMake install'
inputs:
targetType: inline
script: |
$buildDir = "$(Build.ArtifactStagingDirectory)/cpp-build"
cmake --install $buildDir
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

$installDir = "$(Build.ArtifactStagingDirectory)/cpp-install"
Write-Host "Installed SDK contents:"
Get-ChildItem $installDir -Recurse | ForEach-Object { Write-Host $_.FullName }

# Stage artifact — archive the install tree for GitHub Releases / direct download
- task: PowerShell@2
displayName: 'Stage SDK artifact'
inputs:
targetType: inline
script: |
$destDir = "${{ parameters.outputDir }}"
New-Item -ItemType Directory -Path $destDir -Force | Out-Null

$installDir = "$(Build.ArtifactStagingDirectory)/cpp-install"

# Create zip archive of installed SDK (headers + lib + CMake config)
$zipPath = "$destDir/foundry-local-cpp-sdk-$(cppSdkVersion)-win-x64.zip"
Compress-Archive -Path "$installDir/*" -DestinationPath $zipPath -Force
Write-Host "Packaged SDK archive: $zipPath"
Loading
Loading