Skip to content

Add vcpkg binary caching to Azure Pipelines - #33691

Open
eserscor wants to merge 5 commits into
mainfrom
eserscor-dev/erscor/2026/10/27-ado-vcpkg-caching
Open

eserscor wants to merge 5 commits into
mainfrom
eserscor-dev/erscor/2026/10/27-ado-vcpkg-caching

Conversation

@eserscor

@eserscor eserscor commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add a shared Cache@2 template for vcpkg binary archives and integrate it into the Azure Pipelines Windows, macOS, Linux, and Android jobs that use vcpkg. Forward the configured cache into Linux Docker builds without changing wrapper behavior when caching is not configured.

Cache keys separate pipeline/job/platform variants, hash the vcpkg dependency inputs, and include Build.SourceVersion so new commits can save additional ABI archives. Non-release branches can restore earlier snapshots via a prefix; refs/heads/rel-* branches have no fallback restoreKeys.

Use explicit keys for the Linux CUDA and TensorRT jobs: observed 1ES-expanded runs resolve System.JobName to __default for both jobs in the same stage, which otherwise causes cache-save collisions.

Warm versus cold build-step reductions were 6m 9s (x64) and 5m 58s (ARM64). Relative to the previous non-vcpkg sample, x64 was 1m 35s faster and ARM64 was essentially unchanged (3 seconds slower). Warm Azure restore tasks additionally took 17.3/34.7 seconds for x64/ARM64, plus about 1 second each for the post-job exact-hit check; these are outside the build-step table. Thus the results demonstrate effective binary reuse, but do not establish a several-minute net migration benefit over the previous non-vcpkg builds. These are single samples on different agents, not controlled performance trials. The cold run failed only the separate Web E2E task; the warm run had no failed tasks and elapsed 2h 37m 15s.

Local validation:

  • python -m pytest tools\ci_build\test_vcpkg_pipeline_cache.py -q — passed (7 tests, 45 subtests).
  • python -m ruff check tools\ci_build\test_vcpkg_pipeline_cache.py — passed.
  • python -m ruff format --check tools\ci_build\test_vcpkg_pipeline_cache.py — passed.
  • git --no-pager diff --check — passed before commit.

Two sequential Pipeline 2138 (Nuget - Packaging - CUDA13) runs on commit 32d1476238 completed: run 1 and run 2. Run 2 had Azure cache hits AND actual vcpkg binary restores in 11/12 cache-enabled jobs: 30 packages per Windows build, 27 per Linux C API build, 25 on macOS, and 29 per Android ABI.

Build step Run 1 Run 2 Reduction
Windows CPU x64 20m 50s 13m 39s 7m 11s
Windows CUDA 84m 55s 75m 52s 9m 3s
Windows TensorRT 83m 9s 76m 22s 6m 48s
Linux CPU x64 16m 11s 12m 20s 3m 51s
Linux CPU ARM64 21m 25s 15m 40s 5m 45s
macOS ARM64 16m 44s 10m 53s 5m 51s
Android (four ABIs) 56m 29s 39m 7s 17m 22s

These are full build-step durations, not isolated dependency time. Reported vcpkg installation time dropped from 6.4–6.8 minutes to 2.2–2.3 seconds on Windows CPU x64/CUDA/TensorRT; package archive restoration adds roughly 3–4 seconds. Warm Azure cache tasks took about 6–33 seconds. End-to-end pipeline elapsed was 2h 56m 8s vs 2h 49m 16s (6m 52s shorter). Different agents/scheduling and the single paired sample limit attribution. Both pipelines failed in the separate Web E2E package-consuming test; no cache task reported failure.

Enable vcpkg and its internal asset cache in the shared Windows Node.js packaging template, covering both x64 and ARM64 while retaining DirectML/WebGPU, LTO, cross-compilation, and packaging settings. Restore binary caches before building, with explicit stage/target/configuration keys independent of 1ES job-name rewriting.

Windows Node.js verification on 1003f5587b is complete: cold run 1511846 built and packaged both architectures successfully and explicitly saved both caches. Warm run 1512042 succeeded end-to-end, with exact same-commit cache hits and 31 vcpkg packages restored per architecture in 3.6 seconds. Reported subsequent installation was 2.1 seconds for x64 and 2.2 seconds for ARM64, versus 6.4 and 6.3 minutes cold. Both retained the intended x64/ARM64 target triplets, DirectML/WebGPU, LTO, and the x64-to-ARM64 tablegen artifact handoff. Neither Node.js post-job log contained Failed to cache item.

Windows Node.js native build step Previous non-vcpkg run 1511108 Cold vcpkg run 1511846 Warm vcpkg run 1512042
x64 29m 37s 34m 12s 28m 2s
ARM64 30m 21s 36m 23s 30m 25s

Verification of corrected commit d2f776368e is complete:

  • Run 1510925 confirmed Node.js restored 27 packages from the previous commit's cache through the fallback prefix. The corrected CUDA and TensorRT fingerprints were distinct, initially missed as expected, and each post-job log explicitly reported Cache item created.
  • Run 1511108 confirmed Azure cache hits AND actual binary restoration in all 12 cache-enabled jobs, including exact same-commit hits on the two newly separated GPU entries and Node.js. Each Linux CUDA/TensorRT/Node.js build restored 27 packages in 8.1 seconds; subsequent reported installation took 4.3/4.3/5 seconds respectively. The Azure restore tasks took 7.8/10.6/11.2 seconds respectively. Windows restored 30 packages per build, macOS 25, Linux CPU 27 per architecture, and Android 29 per ABI. All native build jobs succeeded; the only failed task was the separate Web E2E package-consuming test. Pipeline elapsed was 2h 10m 46s; this is additional functional evidence, not a controlled replacement for the paired timing comparison.

Cache service reliability caveat: run 1510925 also logged Failed to cache item for the Linux CPU ARM64 and Windows CPU ARM64 post-job saves despite green tasks. Those jobs successfully restored older snapshots, and run 1511108 successfully saved both missing same-commit entries plus Android's entry (the prior run skipped Android save after a separate GPG signing failure). No run 1511108 cache log contained Failed to cache item. Evidence points to intermittent cache artifact creation failures, not a demonstrated repository-side defect; directory cache task success alone is not proof of either save success or vcpkg package reuse.

Motivation and Context

Extend the vcpkg binary caching used in GitHub Actions (#32682, #32692, and #32933) to Azure Pipelines, reducing repeated dependency compilation while retaining vcpkg ABI validation and Azure's branch-isolated cache scopes.

eserscor and others added 3 commits October 28, 2026 14:45
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@eserscor
eserscor marked this pull request as ready for review October 30, 2026 15:33
Copilot AI balanced review requested due to automatic review settings October 30, 2026 15:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the Azure Pipelines vcpkg caching changes.

No open issues 🎉

What changed in this PR

Extends ONNX Runtime’s existing GitHub Actions vcpkg binary caching approach to Azure Pipelines, reducing repeated dependency compilation across native and Docker-based builds.

Changes:

  • Adds a shared cache template with dependency-aware, per-commit keys and fallback restores disabled for release branches.
  • Integrates caching across Windows, macOS, Linux, and Android jobs, forwarding configured cache paths into Docker.
  • Enables vcpkg for Windows Node.js packaging and adds regression tests for cache keys, restore ordering, and Docker forwarding.
File Description
tools/​ci_build/​test_vcpkg_pipeline_cache.py Tests cache configuration, job keys, build ordering, and Docker forwarding.
tools/​ci_build/​github/​linux/​run_python_dockerbuild.sh Conditionally mounts the binary cache for Python builds.
tools/​ci_build/​github/​linux/​build_webgpu_plugin_package.sh Conditionally forwards caching to WebGPU plugin builds.
tools/​ci_build/​github/​linux/​build_tensorrt_c_api_package.sh Conditionally forwards caching to TensorRT packaging.
tools/​ci_build/​github/​linux/​build_nodejs_package.sh Conditionally forwards caching to Node.js packaging.
tools/​ci_build/​github/​linux/​build_cuda_plugin_package.sh Conditionally forwards caching to CUDA plugin builds.
tools/​ci_build/​github/​linux/​build_cuda_c_api_package.sh Conditionally forwards caching to CUDA C API packaging.
tools/​ci_build/​github/​azure-pipelines/​templates/​win-ci.yml Adds cache setup to Windows CI builds.
tools/​ci_build/​github/​azure-pipelines/​templates/​setup-vcpkg-cache.yml Defines shared cache setup, keys, and release-branch restore policy.
tools/​ci_build/​github/​azure-pipelines/​templates/​py-win-cpu.yml Adds caching to Windows CPU Python builds.
tools/​ci_build/​github/​azure-pipelines/​templates/​py-macos.yml Adds caching to macOS Python builds.
tools/​ci_build/​github/​azure-pipelines/​templates/​py-linux.yml Adds cache setup before Linux Python builds.
tools/​ci_build/​github/​azure-pipelines/​templates/​mac-cpu-packaging-steps.yml Adds caching to macOS CPU packaging.
tools/​ci_build/​github/​azure-pipelines/​templates/​c-api-linux-cpu.yml Restores and mounts the cache for Linux CPU packaging.
tools/​ci_build/​github/​azure-pipelines/​templates/​android-java-api-aar.yml Restores and mounts the cache for Android AAR builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​py-win-gpu-unified-stage.yml Adds caching before unified Windows GPU wheel builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​py-win-gpu-stage.yml Adds caching to Windows GPU Python builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​py-linux-gpu-unified-stage.yml Adds caching to unified Linux GPU wheel builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​py-linux-gpu-stage.yml Adds caching to Linux GPU Python builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​plugin-win-webgpu-stage.yml Adds caching to Windows WebGPU plugin builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​plugin-win-cuda-stage.yml Adds caching to Windows CUDA plugin builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​plugin-mac-webgpu-stage.yml Adds caching to macOS WebGPU plugin builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​plugin-linux-webgpu-stage.yml Adds cache setup before Linux WebGPU plugin builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​plugin-linux-cuda-stage.yml Adds cache setup before Linux CUDA plugin builds.
tools/​ci_build/​github/​azure-pipelines/​stages/​nuget-linux-cuda-packaging-stage.yml Uses distinct CUDA and TensorRT cache keys to avoid collisions.
tools/​ci_build/​github/​azure-pipelines/​stages/​nodejs-win-packaging-stage.yml Enables vcpkg and asset caching with target-specific binary cache keys.
tools/​ci_build/​github/​azure-pipelines/​stages/​nodejs-linux-packaging-stage.yml Adds caching to Linux Node.js packaging.
tools/​ci_build/​github/​azure-pipelines/​stages/​nightly-webgpu-shader-validation-stage.yml Adds caching before shader-validation builds.
tools/​ci_build/​github/​azure-pipelines/​linux-gpu-tensorrt-cuda-minimal-ci-pipeline.yml Restores and mounts the cache for minimal TensorRT/CUDA CI.

Review effort: Balanced

@edgchen1 Edward Chen (edgchen1) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good with the changes, just had a comment about the new test file

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants