Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
ci(engine): address review on PR #8846
Akarshan Biswasa9a3d404b8a4
diff --git a/.github/actions/setup-engine-toolchain/action.yml b/.github/actions/setup-engine-toolchain/action.ymlindex 59125d858..bb49aa227 100644--- a/.github/actions/setup-engine-toolchain/action.yml+++ b/.github/actions/setup-engine-toolchain/action.yml@@ -15,8 +15,10 @@ inputs:required: trueccache-max:description: >- ccache size limit. 25G rather than the 5G default because CUDA objects are- large and a smaller cache thrashes instead of rolling over.+ ccache size limit on self-hosted runners. 25G rather than the 5G default+ because CUDA objects are large and a smaller cache thrashes instead of+ rolling over. GitHub-hosted runners are capped at 2G, the actions/cache+ upload budget for a Vulkan plus CPU-variant build.required: falsedefault: '25G'@@ -37,7 +39,11 @@ runs:elseecho "CCACHE_DIR=${HOME}/.ccache" >> "$GITHUB_ENV"fi- echo "CCACHE_MAXSIZE=${{ inputs.ccache-max }}" >> "$GITHUB_ENV"+ if [ "$RUNNER_ENVIRONMENT" = "github-hosted" ]; then+ echo "CCACHE_MAXSIZE=2G" >> "$GITHUB_ENV"+ else+ echo "CCACHE_MAXSIZE=${{ inputs.ccache-max }}" >> "$GITHUB_ENV"+ fiecho "CCACHE_NOHASHDIR=1" >> "$GITHUB_ENV"# GitHub-hosted images have no ccache and no persistent disk.@@ -55,17 +61,16 @@ runs:Windows) choco install ccache -y --no-progress ;;esac- # build.rs holds the llama.cpp pin and cmake flags; the sha suffix makes- # every run save, since actions/cache writes only on an exact-key miss.+ # build.rs holds the llama.cpp pin and cmake flags, so the cache is rebuilt+ # when they change and an exact hit saves nothing; a per-commit key would+ # upload on every run and churn the repo's 10 GB quota.- name: Restore the ccache directoryif: runner.environment == 'github-hosted'uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0with:path: ${{ env.CCACHE_DIR }}- key: ccache-${{ runner.os }}-${{ inputs.variant }}-${{ hashFiles('src-tauri/plugins/tauri-plugin-llamacpp/build.rs') }}-${{ github.sha }}- restore-keys: |- ccache-${{ runner.os }}-${{ inputs.variant }}-${{ hashFiles('src-tauri/plugins/tauri-plugin-llamacpp/build.rs') }}-- ccache-${{ runner.os }}-${{ inputs.variant }}-+ key: ccache-${{ runner.os }}-${{ inputs.variant }}-${{ hashFiles('src-tauri/plugins/tauri-plugin-llamacpp/build.rs') }}+ restore-keys: ccache-${{ runner.os }}-${{ inputs.variant }}-# No GitHub-hosted image ships a Vulkan shader compiler, and the desktop# templates default to the vulkan variant on one. Guarded on glslc ratherdiff --git a/.github/workflows/engine-build.yml b/.github/workflows/engine-build.ymlindex 54bd18710..9868b9e14 100644--- a/.github/workflows/engine-build.yml+++ b/.github/workflows/engine-build.yml@@ -84,17 +84,17 @@ jobs:steps:- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6- # The self-hosted CUDA images carry neither Git for Windows nor make, and- # every later step (dtolnay's included) is bash. No-op on hosted images.+ # The self-hosted CUDA images have Git for Windows off PATH (or absent) and+ # no make, and every later step (dtolnay's included) is bash.- name: Provision Git Bash and make on Windowsif: runner.os == 'Windows'shell: pwshrun: |if (-not (Test-Path 'C:\Program Files\Git\bin\bash.exe')) {choco install git -y --no-progress- Add-Content $env:GITHUB_PATH 'C:\Program Files\Git\cmd'- Add-Content $env:GITHUB_PATH 'C:\Program Files\Git\bin'}+ Add-Content $env:GITHUB_PATH 'C:\Program Files\Git\cmd'+ Add-Content $env:GITHUB_PATH 'C:\Program Files\Git\bin'if (-not (Get-Command make -ErrorAction SilentlyContinue)) {choco install make -y --no-progressAdd-Content $env:GITHUB_PATH 'C:\ProgramData\chocolatey\bin'diff --git a/.github/workflows/template-tauri-build-linux-x64.yml b/.github/workflows/template-tauri-build-linux-x64.ymlindex 862fa08fe..b5aa30a82 100644--- a/.github/workflows/template-tauri-build-linux-x64.yml+++ b/.github/workflows/template-tauri-build-linux-x64.yml@@ -112,6 +112,8 @@ jobs:- name: Install jquses: dcarbone/install-jq-action@b7ef57d46ece78760b4019dbc4080a1ba2a40b45 # v3.2.0+ - uses: dtolnay/rust-toolchain@stable+- name: Install ctomlrun: |cargo install ctomldiff --git a/.github/workflows/template-tauri-build-windows-x64.yml b/.github/workflows/template-tauri-build-windows-x64.ymlindex ce5fac5f2..2afa4041a 100644--- a/.github/workflows/template-tauri-build-windows-x64.yml+++ b/.github/workflows/template-tauri-build-windows-x64.yml@@ -97,17 +97,17 @@ jobs:with:ref: ${{ inputs.ref }}- # The self-hosted CUDA images carry neither Git for Windows nor make, and- # every later step (dtolnay's included) is bash. No-op on hosted images.+ # The self-hosted CUDA images have Git for Windows off PATH (or absent) and+ # no make, and every later step (dtolnay's included) is bash.- name: Provision Git Bash and make on Windowsif: runner.os == 'Windows'shell: pwshrun: |if (-not (Test-Path 'C:\Program Files\Git\bin\bash.exe')) {choco install git -y --no-progress- Add-Content $env:GITHUB_PATH 'C:\Program Files\Git\cmd'- Add-Content $env:GITHUB_PATH 'C:\Program Files\Git\bin'}+ Add-Content $env:GITHUB_PATH 'C:\Program Files\Git\cmd'+ Add-Content $env:GITHUB_PATH 'C:\Program Files\Git\bin'if (-not (Get-Command make -ErrorAction SilentlyContinue)) {choco install make -y --no-progressAdd-Content $env:GITHUB_PATH 'C:\ProgramData\chocolatey\bin'@@ -127,6 +127,8 @@ jobs:- name: Install jquses: dcarbone/install-jq-action@b7ef57d46ece78760b4019dbc4080a1ba2a40b45 # v3.2.0+ - uses: dtolnay/rust-toolchain@stable+- name: Install ctomlrun: |cargo install ctomldiff --git a/src-tauri/build-utils/sign-engine.sh b/src-tauri/build-utils/sign-engine.shindex 9b6870900..67790d82c 100755--- a/src-tauri/build-utils/sign-engine.sh+++ b/src-tauri/build-utils/sign-engine.sh@@ -60,6 +60,13 @@ MINGW* | MSYS* | CYGWIN*)signed=$((signed + 1))done[ "$signed" -gt 0 ] || give_up "no engine binaries in $DEST to sign."+ # The CUDA runtime ships under NVIDIA's own Authenticode signature; re-signing+ # would replace it, so it is verified rather than signed.+ for target in "$DEST"/cudart64_*.dll "$DEST"/cublas*.dll; do+ [ -f "$target" ] || continue+ status=$(powershell -NoProfile -Command "(Get-AuthenticodeSignature '$target').Status" | tr -d '\r')+ [ "$status" = "Valid" ] || give_up "$(basename "$target") has no valid Authenticode signature ($status)."+ doneecho "Signed $signed engine binaries";;esacdiff --git a/src-tauri/build-utils/stage-engine.sh b/src-tauri/build-utils/stage-engine.shindex 4e5baaa0d..3712c0b55 100755--- a/src-tauri/build-utils/stage-engine.sh+++ b/src-tauri/build-utils/stage-engine.sh@@ -106,68 +106,62 @@ echo "stage-engine: staged $staged ggml libraries ($modules backend modules) int[ -n "$cuda_module" ] || exit 0-# The runtime comes from the toolkit that compiled the module, so the major-# matches by construction.-cuda_root() {- local d nvcc- for d in "${CUDA_PATH:-}" "${CUDA_HOME:-}"; do- if [ -n "$d" ] && [ -d "$d" ]; then echo "$d"; return 0; fi- done- nvcc="$(command -v nvcc 2>/dev/null || true)"- [ -n "$nvcc" ] || return 1- (cd "$(dirname "$nvcc")/.." && pwd)-}--ROOT="$(cuda_root)" || {- echo "stage-engine: staged $(basename "$cuda_module") but found no CUDA toolkit" >&2- echo "stage-engine: set CUDA_PATH/CUDA_HOME or put nvcc on PATH" >&2- exit 1-}--# CUDA 13 moved the Windows DLLs to bin/x64. lib64 is a symlink to-# targets/<arch>/lib, so only the first directory holding cudart is used.+# The module's own import names say which runtime it needs and with which+# major; they are plain strings in the binary (ELF .dynstr, PE import table),+# so no objdump/dumpbin is needed. cublasLt is reached through cublas, hence+# the closure over what has been staged.if [ "$LIBEXT" = "dll" ]; then- candidates=("$ROOT/bin/x64" "$ROOT/bin")- runtime_globs=('cudart64_*.dll' 'cublas64_*.dll' 'cublasLt64_*.dll')+ import_re='(cudart|cublas|cublasLt)64_[0-9]+\.dll'+ libdirs_of() { echo "$1/bin/x64" "$1/bin"; }else- candidates=("$ROOT/lib64" "$ROOT"/targets/*/lib)- runtime_globs=('libcudart.so.[0-9]*' 'libcublas.so.[0-9]*' 'libcublasLt.so.[0-9]*')+ import_re='libcu(dart|blas|blasLt)\.so\.[0-9]+'+ libdirs_of() { echo "$1/lib64" "$1/lib" "$1"/targets/*/lib; }fi+imports_of() { tr -d '\0' < "$1" | grep -aoE "$import_re" | sort -u; }+needed="$(imports_of "$cuda_module")"+[ -n "$needed" ] || {+ echo "stage-engine: $(basename "$cuda_module") imports no CUDA runtime library" >&2+ exit 1+}++first="$(echo "$needed" | head -1)"LIBDIR=""-for d in "${candidates[@]}"; do- if compgen -G "$d/${runtime_globs[0]}" >/dev/null; then LIBDIR="$d"; break; fi+nvcc="$(command -v nvcc 2>/dev/null || true)"+for root in "${CUDA_PATH:-}" "${CUDA_HOME:-}" "${nvcc:+$(cd "$(dirname "$nvcc")/.." && pwd)}"; do+ [ -n "$root" ] && [ -d "$root" ] || continue+ for d in $(libdirs_of "$root"); do+ if [ -e "$d/$first" ] || [ -L "$d/$first" ]; then LIBDIR="$d"; break 2; fi+ donedone[ -n "$LIBDIR" ] || {- echo "stage-engine: no ${runtime_globs[0]} under $ROOT (looked in: ${candidates[*]})" >&2+ echo "stage-engine: $(basename "$cuda_module") needs $first, found in no CUDA toolkit" >&2+ echo "stage-engine: looked under CUDA_PATH, CUDA_HOME and nvcc's parent" >&2exit 1}runtime=0-for pat in "${runtime_globs[@]}"; do- matched=0- for src in "$LIBDIR"/$pat; do- [ -e "$src" ] || [ -L "$src" ] || continue- stage_lib "$src"- matched=$((matched + 1))+staged_names=""+queue="$needed"+while [ -n "$queue" ]; do+ next=""+ for name in $queue; do+ case " $staged_names " in *" $name "*) continue ;; esac+ matched=0+ for src in "$LIBDIR/$name"*; do+ [ -e "$src" ] || [ -L "$src" ] || continue+ stage_lib "$src"+ matched=$((matched + 1))+ done+ if [ "$matched" -eq 0 ]; then+ echo "stage-engine: $name is imported but missing from $LIBDIR" >&2+ exit 1+ fi+ runtime=$((runtime + matched))+ staged_names="$staged_names $name"+ next="$next $(imports_of "$DEST/$name")"done- if [ "$matched" -eq 0 ]; then- echo "stage-engine: $LIBDIR has no $pat; the CUDA module would not load without it" >&2- exit 1- fi- runtime=$((runtime + matched))+ queue="$next"done-# The globs are a guess at what the module wants; its NEEDED list is the fact.-if [ "$LIBEXT" = "so" ] && command -v objdump >/dev/null 2>&1; then- missing=""- while read -r needed; do- [ -e "$DEST/$needed" ] || missing="$missing $needed"- done < <(objdump -p "$cuda_module" | awk '/NEEDED/ && $2 ~ /^libcu(dart|blas)/ {print $2}')- if [ -n "$missing" ]; then- echo "stage-engine: $(basename "$cuda_module") needs$missing, not staged from $LIBDIR" >&2- exit 1- fi-fi-echo "stage-engine: staged $runtime CUDA runtime libraries from $LIBDIR"