-
Notifications
You must be signed in to change notification settings - Fork 1k
296 lines (269 loc) · 12.6 KB
/
Copy path_build-sdk.yml
File metadata and controls
296 lines (269 loc) · 12.6 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
name: Build SDK
on:
workflow_call:
inputs:
version_tag:
description: "Explicit version tag (e.g. v1.2.3-rc.1). Passed to the version action."
required: false
type: string
default: ""
upload_artifact:
description: "Whether to upload SDK artifact"
required: false
type: boolean
default: false
extra_cmake_flags:
description: "Additional CMake flags"
required: false
type: string
default: ""
permissions:
contents: read
packages: read
# Derived toolchain images (matrix.container_image) are built by
# _build-toolchain-docker.yml; bumping the pinned tag there is the
# single upgrade point for Rust toolchain / apt layers.
jobs:
build:
name: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
include:
- platform: windows-arm64
runner: windows-11-arm
preset: arm64-windows-snapdragon-release
- platform: linux-arm64
runner: ubuntu-latest
preset: arm64-linux-snapdragon-release
container_image: docker.io/qualcomm/geniex-toolchain-linux:v0.1.0
- platform: android-arm64
runner: ubuntu-latest
preset: arm64-android-snapdragon-release
container_image: docker.io/qualcomm/geniex-toolchain-android:v0.1.0
runs-on: ${{ matrix.runner }}
timeout-minutes: 120
steps:
- name: Configure Windows Git
if: matrix.platform == 'windows-arm64'
shell: cmd
run: |
echo C:\Program Files\Git\bin>>%GITHUB_PATH%
git config --global core.longpaths true
git config --global core.protectNTFS false
git config --global core.fscache true
git config --global core.preloadindex true
# The geniex-qairt-plugin submodule pins a nested submodule (geniex-proc)
# by SSH URL (git@github.com:...). CI authenticates over HTTPS with a PAT,
# so rewrite SSH → HTTPS globally before checkout recurses into it.
- name: Rewrite SSH submodule URLs to HTTPS
shell: bash
run: git config --global url."https://github.com/".insteadOf "git@github.com:"
- name: Checkout source
uses: actions/checkout@v7
with:
fetch-depth: 1
submodules: recursive
- name: Detect build version
id: version
uses: ./.github/actions/version
with:
version_tag: ${{ inputs.version_tag }}
- name: Restore ccache
uses: actions/cache@v6
with:
path: ${{ github.workspace }}/.ccache
key: ccache-sdk-${{ matrix.platform }}-${{ github.sha }}
restore-keys: ccache-sdk-${{ matrix.platform }}-
# Cargo target dir lives under the workspace so it's reachable both
# from the Windows runner and from the Linux/Android container
# (mounted at /workspace). The key includes the Rust sources, not just
# Cargo.lock/Cargo.toml: actions/cache restores files with a uniform
# mtime, so cargo's mtime-based fingerprinting would otherwise reuse a
# stale libgeniex_model.a after a source-only change (e.g. a new FFI
# symbol), producing downstream undefined-reference link failures.
# No restore-keys — a source change forces a clean rebuild instead of a
# fuzzy restore that would re-trigger the staleness.
- name: Restore cargo target
uses: actions/cache@v6
with:
path: |
sdk/model-manager/target
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: cargo-sdk-${{ matrix.platform }}-${{ hashFiles('sdk/model-manager/Cargo.lock', 'sdk/model-manager/**/Cargo.toml', 'sdk/model-manager/crates/**/*.rs') }}
# Toolchain identifier baked into the cmake-build cache key so a
# runner-image / container-image bump (MSVC patch, clang/apt layer)
# mints a fresh entry instead of reusing PCH/objects compiled
# against the old toolchain.
- name: Compute toolchain tag for cache key
id: tc
shell: bash
env:
CONTAINER_IMAGE: ${{ matrix.container_image }}
run: |
set -eu
case "${{ matrix.platform }}" in
windows-arm64) tag="winarm64-img-${ImageVersion:-unknown}" ;;
*) tag="container-${CONTAINER_IMAGE##*:}" ;;
esac
echo "tag=$tag" >>"$GITHUB_OUTPUT"
echo "Toolchain tag for cache: $tag"
# Cache the CMake build tree so ninja deps, ExternalProject stamps,
# and link products survive across runs. hashFiles covers the
# configure-time inputs; a change there mints a new entry, while
# restore-keys lets unchanged-config runs reuse the previous tree.
- name: Restore CMake build dir
uses: actions/cache@v6
with:
path: sdk/build-${{ matrix.preset }}
key: cmake-build-${{ matrix.platform }}-${{ steps.tc.outputs.tag }}-${{ hashFiles('sdk/CMakeLists.txt', 'sdk/**/CMakeLists.txt', 'sdk/CMakePresets.json', 'sdk/cmake/**', 'sdk/patches/**', '.gitmodules', 'third-party/**/CMakeLists.txt', 'third-party/**/*.cmake', 'third-party/**/cmake/**') }}-${{ github.sha }}
restore-keys: cmake-build-${{ matrix.platform }}-${{ steps.tc.outputs.tag }}-${{ hashFiles('sdk/CMakeLists.txt', 'sdk/**/CMakeLists.txt', 'sdk/CMakePresets.json', 'sdk/cmake/**', 'sdk/patches/**', '.gitmodules', 'third-party/**/CMakeLists.txt', 'third-party/**/*.cmake', 'third-party/**/cmake/**') }}-
# Restored cmake-build-* dirs carry FetchContent populate stamps
# that point at source paths actions/checkout (clean: true) just
# wiped from submodules — most notably sentencepiece's in-tree
# third_party/abseil-cpp clone. Drop those stamps so cmake
# re-populates instead of verifying a now-missing .git.
- name: Purge stale FetchContent populate stamps
shell: bash
run: |
set -eu
dir="sdk/build-${{ matrix.preset }}"
if [ -d "$dir" ]; then
find "$dir" -type d -name "*-subbuild" -prune -print -exec rm -rf {} +
fi
# Linux/Android ccache lives in the toolchain container; host just
# owns the dir so actions/cache can persist it.
- name: Prepare ccache dir (Linux/Android)
if: matrix.platform == 'linux-arm64' || matrix.platform == 'android-arm64'
shell: bash
run: mkdir -p "${{ github.workspace }}/.ccache"
- name: Install and configure ccache (Windows)
if: matrix.platform == 'windows-arm64'
shell: powershell
run: |
if (-not (Get-Command ccache -ErrorAction SilentlyContinue)) {
choco install ccache --no-progress -y
}
# $GITHUB_ENV only applies to later steps — set in-process too
# so `ccache --max-size` below edits the workspace config.
$env:CCACHE_DIR = "${{ github.workspace }}/.ccache"
Add-Content $env:GITHUB_ENV "CCACHE_DIR=$env:CCACHE_DIR"
# SLOPPINESS tolerates __DATE__/__TIME__ and mtime jitter that
# llama.cpp / ggml sources trip over. CCACHE_BASEDIR is *not*
# set: workspace paths on the self-hosted Windows runner are
# stable, and changing it would invalidate every existing
# entry (different hash input).
Add-Content $env:GITHUB_ENV "CCACHE_SLOPPINESS=time_macros,include_file_mtime,include_file_ctime"
ccache --max-size=5G
- name: Setup Snapdragon SDKs
if: matrix.platform == 'windows-arm64'
uses: ./.github/actions/setup-snapdragon-sdks
- name: Configure HTP signing cert
if: matrix.platform == 'windows-arm64'
shell: powershell
env:
HEXAGON_HTP_CERT_PFX: ${{ secrets.HEXAGON_HTP_CERT_PFX }}
run: |
$ErrorActionPreference = "Stop"
if (-not $env:HEXAGON_HTP_CERT_PFX) {
Write-Warning "HEXAGON_HTP_CERT_PFX secret is unavailable (expected on fork PRs); building unsigned HTP skels."
exit 0
}
$dst = "$env:RUNNER_TEMP\ggml-htp-v1.pfx"
[IO.File]::WriteAllBytes($dst, [Convert]::FromBase64String($env:HEXAGON_HTP_CERT_PFX))
Add-Content -Path $env:GITHUB_ENV -Value "HEXAGON_HTP_CERT=$dst"
Write-Host "HEXAGON_HTP_CERT=$dst"
- name: Build SDK (cross-compile in toolchain container)
if: matrix.platform != 'windows-arm64'
shell: bash
env:
GENIEX_VERSION: ${{ steps.version.outputs.version }}
EXTRA_CMAKE_FLAGS: ${{ inputs.extra_cmake_flags }}
PRESET: ${{ matrix.preset }}
CONTAINER_IMAGE: ${{ matrix.container_image }}
run: |
set -euo pipefail
# Runs as root because the image's rust/apt layers were built
# as root; chown back to the runner UID so upload-artifact /
# cache can read the tree.
uid="$(id -u)"
gid="$(id -g)"
docker run --rm \
-v "${{ github.workspace }}:/workspace" \
-w /workspace \
-e GENIEX_VERSION \
-e EXTRA_CMAKE_FLAGS \
-e PRESET \
-e CCACHE_DIR=/workspace/.ccache \
-e CCACHE_SLOPPINESS=time_macros,include_file_mtime,include_file_ctime \
-e HOST_UID="$uid" \
-e HOST_GID="$gid" \
--platform linux/amd64 \
"$CONTAINER_IMAGE" \
bash -eux -c '
git config --global --add safe.directory "*"
cmake -S sdk --preset "$PRESET" \
-DGENIEX_VERSION="$GENIEX_VERSION" \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
$EXTRA_CMAKE_FLAGS
cmake --build "sdk/build-$PRESET" -j "$(nproc)"
cmake --install "sdk/build-$PRESET" --prefix sdk/pkg-geniex
ccache -s -v || true
chown -R "$HOST_UID:$HOST_GID" sdk .ccache || true
'
- name: Setup VS toolchain (Windows)
if: matrix.platform == 'windows-arm64'
uses: ./.github/actions/setup-vcvars
- name: Build SDK (Windows)
if: matrix.platform == 'windows-arm64'
shell: powershell
env:
GENIEX_VERSION: ${{ steps.version.outputs.version }}
PRESET: ${{ matrix.preset }}
run: |
$ErrorActionPreference = "Stop"
$BuildDir = "sdk/build-$env:PRESET"
# Source vcvars into this process so cmake's child processes
# (clang, ninja, inf2cat.exe) inherit PATH/INCLUDE/LIB for the
# Windows SDK — same semantics as `call vcvars && cmake`.
$envDump = cmd /c "`"$env:VCVARS_BAT`" $env:VCVARS_ARGS && set"
foreach ($line in $envDump) {
if ($line -match "^(.+?)=(.*)$") {
[Environment]::SetEnvironmentVariable($matches[1], $matches[2], "Process")
}
}
$env:PATH = "$env:LLVM_BIN;$env:PATH"
# Pass the cert path explicitly: GGML_HEXAGON_HTP_CERT is a cached
# PATH, so a restored build dir keeps a prior run's value and an
# empty env alone won't clear it — on a fork PR (no secret) that
# leaves signing on and signtool fails on the missing .pfx.
cmake -S sdk --preset $env:PRESET -B $BuildDir --log-level=VERBOSE `
"-DGENIEX_VERSION=$env:GENIEX_VERSION" `
"-DGGML_HEXAGON_HTP_CERT=$env:HEXAGON_HTP_CERT" `
-DCMAKE_C_COMPILER_LAUNCHER=ccache `
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
if ($LASTEXITCODE -ne 0) { throw "cmake configure failed: $LASTEXITCODE" }
cmake --build $BuildDir -j $([Environment]::ProcessorCount)
if ($LASTEXITCODE -ne 0) { throw "cmake --build failed: $LASTEXITCODE" }
cmake --install $BuildDir --prefix sdk/pkg-geniex
if ($LASTEXITCODE -ne 0) { throw "cmake install failed: $LASTEXITCODE" }
# On Linux/Android ccache runs inside the container; only the on-disk
# size is visible from the host. Never fail the job on a stats read.
- name: ccache stats (Linux/Android)
if: matrix.platform == 'linux-arm64' || matrix.platform == 'android-arm64'
shell: bash
run: du -sh "${{ github.workspace }}/.ccache" 2>/dev/null || true
- name: ccache stats (Windows)
if: matrix.platform == 'windows-arm64'
shell: powershell
run: ccache --show-stats --verbose; $true
- name: Upload SDK artifact
if: inputs.upload_artifact
uses: actions/upload-artifact@v7
with:
name: sdk-${{ matrix.platform }}
path: sdk/pkg-geniex/
retention-days: 1