Skip to content

Commit 3b0cc73

Browse files
feat: vcpkg and ccache for windows and some macos ci
1 parent 2f66878 commit 3b0cc73

14 files changed

Lines changed: 76 additions & 4 deletions

.github/actions/locate-vcvarsall-and-setup-env/action.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ inputs:
55
description: 'Target architecture (x64 or x86)'
66
required: true
77
default: 'x64'
8+
cache_key:
9+
description: 'a workflow & job qualified unique key to distinguish a cache. used as a suffix for subcaches.'
10+
required: true
811
outputs:
912
vcvarsall_path:
1013
description: "Path to vcvarsall.bat"
@@ -78,3 +81,38 @@ runs:
7881
7982
REM Call the Python script to update the GitHub Actions environment
8083
python ${{ github.action_path }}\update_environment.py
84+
85+
- name: Set cache dir env vars
86+
env:
87+
github_runner_temp: ${{ runner.temp }}
88+
shell: pwsh
89+
run: |
90+
echo "CCACHE_DIR=${env:github_runner_temp}/.ccache" >> "${env:GITHUB_ENV}"
91+
echo "VCPKG_DEFAULT_BINARY_CACHE=${env:github_runner_temp}/.vcpkg-cache" >> "${env:GITHUB_ENV}"
92+
93+
# vcpkg will error/exit if `VCPKG_DEFAULT_BINARY_CACHE` does not exist as a directory.
94+
# c.f. ccache happily creates the cache dir if it does not exist.
95+
# Don't create ccache's dir so that `action/cache` skips if ccache isn't populated.
96+
New-Item -ItemType Directory -Path "${env:github_runner_temp}/.vcpkg-cache" -Force
97+
98+
# HACK: `actions/cache` will somehow pick up `tar` from the git installation. This bin dir is not on the PATH.
99+
# `tar` tries to find `gzip` (which is right next to it), and fails b/c the git bin dir isn't on the PATH.
100+
# This breaks attempts to download/upload caches.
101+
# Add git's bin dir to the PATH so that `actions/cache`'s invoke of `tar` can find `gzip`.
102+
echo "PATH=${env:PATH};C:\\Program Files\\Git\\usr\\bin" >> "${env:GITHUB_ENV}"
103+
104+
# n.b. Caller is responsible for building w/ ccache enabled via `--use_cache`
105+
# We could set the env var `ORT_BUILD_WITH_CACHE` to indirectly enable it, but this hack seems deprecated.
106+
# Ideally ccache should be auto-enabled by the build system if ccache/sccache is detected on the PATH.
107+
- name: Setup CCache
108+
uses: actions/cache@v4
109+
with:
110+
# Fully qualify by `cache_key`. `actions/cache` does not isolate by workflow, unlike ADO cache actions.
111+
key: ccache | ${{ inputs.cache_key }}
112+
path: ${{ runner.temp }}/.ccache # ensure this is coordinated/matches w/ env-vars step above
113+
114+
- name: Setup VCPKG Cache
115+
uses: actions/cache@v4
116+
with:
117+
key: vcpkg-cache | ${{ inputs.cache_key }}
118+
path: ${{ runner.temp }}/.vcpkg-cache

.github/workflows/macos-ci-build-and-test-workflow.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ jobs:
5252
# see also: https://github.com/actions/runner-images/blob/main/README.md
5353
runs-on: ${{ matrix.machine == 'x86_64' && 'macos-13' || 'macos-15' }}
5454
env:
55-
build_flags: >
55+
CCACHE_DIR: ~/.cache/ccache # be explicit. must match `action/cache` below.
56+
build_flags: >-
5657
--build_dir ./build
5758
--skip_submodule_sync
5859
--parallel
@@ -66,7 +67,9 @@ jobs:
6667
${{ inputs.use_webgpu && '--use_webgpu' || '' }}
6768
${{ inputs.use_xnnpack && '--use_xnnpack' || '' }}
6869
${{ inputs.use_coreml && '--use_coreml --skip_onnx_tests' || '' }}
69-
--use_vcpkg --use_vcpkg_ms_internal_asset_cache
70+
--use_cache
71+
--use_vcpkg
72+
--use_vcpkg_ms_internal_asset_cache
7073
--config ${{ matrix.build_config }}
7174
--osx_arch ${{ matrix.target }}
7275
@@ -76,13 +79,15 @@ jobs:
7679
steps:
7780
- name: Checkout code
7881
uses: actions/checkout@v6
79-
- uses: microsoft/onnxruntime-github-actions/setup-build-tools@v0.0.9
82+
83+
- uses: microsoft/onnxruntime-github-actions/setup-build-tools@8bad63a3c05d448311dfa8e5f531171c97471aa1 # v0.0.12
8084
with:
85+
ccache-version: 4.13.1
86+
ccache-hash: d831cbd84ac1efb32441c5bfbc7cc662830c0c22e96c5b5b27a6ce4746c81d6076261cf61217fb67ff4585fbd6cbd91ea817aa4ed904b81fcba621bb60881f56
8187
vcpkg-version: '2025.08.27'
8288
vcpkg-hash: 9a4b32849792e13bee1d24726f073b3881acae4165206ddf1a6378e44a4ddd05b3ee93f55ff46d8e8873b3cbcd06606212989e248f0bd615a5bf365070074079
8389
cmake-version: '3.31.8'
8490
cmake-hash: 99cc9c63ae49f21253efb5921de2ba84ce136018abf08632c92c060ba91d552e0f6acc214e9ba8123dee0cf6d1cf089ca389e321879fd9d719a60d975bcffcc8
85-
add-cmake-to-path: 'true'
8691
disable-terrapin: 'true'
8792

8893
- name: macOS CI pipeline prepare steps
@@ -93,6 +98,18 @@ jobs:
9398
xcode_version: ${{ env.xcode_version }}
9499
use_cache: true
95100

101+
- name: Setup CCache
102+
uses: actions/cache@v4
103+
with:
104+
key: ccache | macos-ci-build-and-test-workflow.yml | build-and-test | ${{ matrix.machine }}-${{ matrix.target }}-${{ matrix.build_config }}
105+
path: ~/.cache/ccache
106+
107+
- name: Setup VCPKG Cache
108+
uses: actions/cache@v4
109+
with:
110+
key: vcpkg-cache | macos-ci-build-and-test-workflow.yml | build-and-test | ${{ matrix.machine }}-${{ matrix.target }} # build config doesn't matter, vcpkg builds both
111+
path: ~/.cache/vcpkg
112+
96113
- uses: actions/cache@v5
97114
id: onnx-node-tests-cache
98115
with:

.github/workflows/windows_build_x64_asan.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
uses: ./.github/actions/locate-vcvarsall-and-setup-env # Use the composite action
3838
with:
3939
architecture: x64
40+
cache_key: windows_build_x64_asan.yml | build_x64
4041

4142
- name: Build and Test (Combined)
4243
shell: cmd

.github/workflows/windows_cuda.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
uses: ./.github/actions/locate-vcvarsall-and-setup-env
4040
with:
4141
architecture: x64
42+
cache_key: windows_cuda.yml | build
4243

4344
- name: Install python modules
4445
run: python -m pip install -r .\tools\ci_build\github\windows\python\requirements.txt
@@ -190,6 +191,7 @@ jobs:
190191
uses: ./.github/actions/locate-vcvarsall-and-setup-env
191192
with:
192193
architecture: x64
194+
cache_key: windows_cuda.yml | build # reuse build's caches. we do not expect this stage to modify them.
193195

194196
- name: Install python modules
195197
run: python -m pip install -r .\tools\ci_build\github\windows\python\requirements.txt

.github/workflows/windows_dml.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
uses: ./.github/actions/locate-vcvarsall-and-setup-env
4646
with:
4747
architecture: x64
48+
cache_key: windows_dml.yml | build_x64_RelWithDebInfo
4849

4950
- name: Install python modules
5051
run: python -m pip install -r .\tools\ci_build\github\windows\python\requirements.txt

.github/workflows/windows_openvino.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
uses: ./.github/actions/locate-vcvarsall-and-setup-env
5151
with:
5252
architecture: x64
53+
cache_key: windows_openvino.yml | BUILD_OPENVINO_EP
5354

5455
- name: Download OpenVINO Toolkit v2025.4.1
5556
env:

.github/workflows/windows_qnn_x64.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
uses: ./.github/actions/locate-vcvarsall-and-setup-env
4848
with:
4949
architecture: x64
50+
cache_key: windows_qnn_x64.yml | build_test_qnn_ep_${{ matrix.QnnLibKind }}
5051

5152
- name: Download QNN SDK
5253
working-directory: ${{ runner.temp }}

.github/workflows/windows_tensorrt.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
uses: ./.github/actions/locate-vcvarsall-and-setup-env
4040
with:
4141
architecture: x64
42+
cache_key: windows_tensorrt.yml | build
4243

4344
- name: Install python modules
4445
run: python -m pip install -r .\tools\ci_build\github\windows\python\requirements.txt
@@ -196,6 +197,7 @@ jobs:
196197
uses: ./.github/actions/locate-vcvarsall-and-setup-env
197198
with:
198199
architecture: x64
200+
cache_key: windows_tensorrt.yml | build # re-use build's caches, we do not expect to modify/extend them.
199201

200202
- name: Install python modules
201203
run: python -m pip install -r .\tools\ci_build\github\windows\python\requirements.txt

.github/workflows/windows_webgpu.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
uses: ./.github/actions/locate-vcvarsall-and-setup-env
5454
with:
5555
architecture: x64
56+
cache_key: windows_webgpu.yml | webgpu_build_x64_RelWithDebInfo_${{ matrix.vcpkg_option }}_${{ matrix.wgsl_template }}
5657

5758
- name: Install python modules
5859
run: python -m pip install -r tools\ci_build\github\windows\python\requirements.txt
@@ -186,6 +187,7 @@ jobs:
186187
uses: ./.github/actions/locate-vcvarsall-and-setup-env
187188
with:
188189
architecture: x64
190+
cache_key: windows_webgpu.yml | webgpu_plugin_build_x64_RelWithDebInfo
189191

190192
- name: Install python modules
191193
run: python -m pip install -r tools\ci_build\github\windows\python\requirements.txt
@@ -259,6 +261,7 @@ jobs:
259261
uses: ./.github/actions/locate-vcvarsall-and-setup-env
260262
with:
261263
architecture: x64
264+
cache_key: windows_webgpu.yml | webgpu_external_dawn_build_x64_RelWithDebInfo
262265

263266
- name: Install python modules
264267
run: python -m pip install -r tools\ci_build\github\windows\python\requirements.txt
@@ -316,6 +319,7 @@ jobs:
316319
uses: ./.github/actions/locate-vcvarsall-and-setup-env
317320
with:
318321
architecture: x64
322+
cache_key: windows_webgpu.yml | webgpu_minimal_build_edge_build_x64_RelWithDebInfo
319323

320324
- name: Install python modules
321325
run: python -m pip install -r tools\ci_build\github\windows\python\requirements.txt

.github/workflows/windows_x64_debug_build_x64_debug.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
uses: ./.github/actions/locate-vcvarsall-and-setup-env # Use the composite action
3737
with:
3838
architecture: x64
39+
cache_key: windows_x64_debug_build_x64_debug.yml | build_x64_debug
3940

4041
- name: Install python modules
4142
shell: cmd

0 commit comments

Comments
 (0)