|
6 | 6 | # SPDX-License-Identifier: MIT |
7 | 7 |
|
8 | 8 | mkdir -p build |
9 | | -cmake -Bbuild $@ || exit 1 |
10 | | -cmake --build build --config Release -j$(nproc) || exit 1 |
| 9 | + |
| 10 | +# Build parallelism. Defaults to all cores; RAM-limited CI runners (notably GitHub's |
| 11 | +# ~7 GB macOS arm64) export BUILD_JOBS lower (e.g. 2) so the large httplib.cpp + the 134 |
| 12 | +# llama.cpp model TUs do not exhaust memory and get the runner OOM-killed mid-compile |
| 13 | +# (which surfaces as a SIGTERM / "runner received a shutdown signal", not a clean timeout). |
| 14 | +JOBS="${BUILD_JOBS:-}" |
| 15 | +if [ -z "$JOBS" ]; then |
| 16 | + JOBS="$( { command -v nproc >/dev/null 2>&1 && nproc; } || sysctl -n hw.ncpu 2>/dev/null || echo 4 )" |
| 17 | +fi |
| 18 | + |
| 19 | +# Fetch sccache when caching is requested but the runner/container doesn't ship it — the |
| 20 | +# dockcross cross-compile containers (manylinux/Android) and Linux hosts have no sccache, |
| 21 | +# while macOS installs it via brew in the workflow. Best-effort and inert-safe: any failure |
| 22 | +# leaves sccache absent, so the build just proceeds uncached. The static musl binary runs in |
| 23 | +# any x86_64 Linux container (the cross-compile host is always x86_64). |
| 24 | +if [ "${USE_CACHE:-true}" = "true" ] && [ -n "${SCCACHE_WEBDAV_TOKEN:-}${SCCACHE_GHA_ENABLED:-}" ] \ |
| 25 | + && ! command -v sccache >/dev/null 2>&1 \ |
| 26 | + && [ "$(uname -s)" = "Linux" ] && [ "$(uname -m)" = "x86_64" ]; then |
| 27 | + SCCACHE_REL="sccache-v0.8.2-x86_64-unknown-linux-musl" |
| 28 | + echo "build.sh: fetching ${SCCACHE_REL} (no sccache on PATH)..." |
| 29 | + if curl -fsSL --proto =https --proto-redir =https \ |
| 30 | + "https://github.com/mozilla/sccache/releases/download/v0.8.2/${SCCACHE_REL}.tar.gz" \ |
| 31 | + -o /tmp/sccache.tgz && tar -xzf /tmp/sccache.tgz -C /tmp; then |
| 32 | + export PATH="/tmp/${SCCACHE_REL}:$PATH" |
| 33 | + echo "build.sh: sccache -> $(command -v sccache || echo 'still missing')" |
| 34 | + else |
| 35 | + echo "build.sh: sccache fetch failed; continuing without cache" |
| 36 | + fi |
| 37 | +fi |
| 38 | + |
| 39 | +# Optional shared compiler cache: sccache fronting Depot Cache (WebDAV). Enabled only when |
| 40 | +# USE_CACHE is true AND sccache + a cache token are present, so it stays inert before the |
| 41 | +# DEPOT_TOKEN secret is configured and on fork PRs (secrets hidden) — those just compile |
| 42 | +# normally. sccache is content-addressed, so a cache hit is bit-identical to a fresh -O3 |
| 43 | +# compile (release-safe), and it degrades to direct compilation if the cache is unreachable. |
| 44 | +LAUNCH="" |
| 45 | +if [ "${USE_CACHE:-true}" = "true" ] && command -v sccache >/dev/null 2>&1 \ |
| 46 | + && [ -n "${SCCACHE_WEBDAV_TOKEN:-}${SCCACHE_GHA_ENABLED:-}" ]; then |
| 47 | + LAUNCH="-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache" |
| 48 | + echo "build.sh: sccache ON (endpoint=${SCCACHE_WEBDAV_ENDPOINT:-default}), building with -j${JOBS}" |
| 49 | +else |
| 50 | + echo "build.sh: sccache OFF, building with -j${JOBS}" |
| 51 | +fi |
| 52 | + |
| 53 | +cmake -Bbuild $LAUNCH $@ || exit 1 |
| 54 | +cmake --build build --config Release -j"${JOBS}" || exit 1 |
| 55 | + |
| 56 | +if command -v sccache >/dev/null 2>&1; then |
| 57 | + sccache --show-stats || true |
| 58 | +fi |
0 commit comments