Commit 96eb41bc4 for llama.cpp

commit 96eb41bc4884855eacbd64077bc9a00e839a73eb
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date:   Tue Nov 24 17:34:34 2026 +0100

    ui: fix prebuilt UI download in shallow clones (#32952)

    In a shallow clone the git commit count is not the build number, so the build asked for a UI version that does not exist (b1 with --depth 1) and fell back to 'latest'. Use the release tag on HEAD when it was fetched, else 'latest'.

    Also check a downloaded archive right after extraction. If it does not have the files this checkout needs, drop it and build without an embedded UI instead of failing the build.

    Refs #32780

    Assisted-by: Claude (Fable 5.2)

diff --git a/scripts/ui-assets.cmake b/scripts/ui-assets.cmake
index 62f58e423..633b19a79 100644
--- a/scripts/ui-assets.cmake
+++ b/scripts/ui-assets.cmake
@@ -69,14 +69,8 @@ function(mime_from_ext name out_var)
     set(${out_var} "${m}" PARENT_SCOPE)
 endfunction()

-# Fail when a dist tree is present but is missing files the UI needs at
-# runtime; catches truncated/stale asset trees early with a useful message.
-function(ui_validate_assets files in_dir)
-    list(LENGTH files n_assets)
-    if(n_assets EQUAL 0)
-        return()
-    endif()
-
+# List the files the UI needs at runtime that are not in ${files}.
+function(ui_missing_assets files out_var)
     set(found_index FALSE)
     set(found_manifest FALSE)
     set(found_sw FALSE)
@@ -138,6 +132,18 @@ function(ui_validate_assets files in_dir)
         list(APPEND missing "_app/immutable/assets/[name][hash].css (or bundle[hash].css)")
     endif()

+    set(${out_var} "${missing}" PARENT_SCOPE)
+endfunction()
+
+# Fail when a dist tree is present but is missing files the UI needs at
+# runtime; catches truncated/stale asset trees early with a useful message.
+function(ui_validate_assets files in_dir)
+    list(LENGTH files n_assets)
+    if(n_assets EQUAL 0)
+        return()
+    endif()
+
+    ui_missing_assets("${files}" missing)
     if(missing)
         set(listing "")
         foreach(f ${files})
@@ -492,6 +498,7 @@ function(hf_download version out_var out_resolved)
         list(APPEND candidates "${version}")
     endif()
     list(APPEND candidates "latest")
+    list(REMOVE_DUPLICATES candidates)

     foreach(resolved ${candidates})
         set(base "https://huggingface.co/buckets/${HF_BUCKET}/resolve/${resolved}")
@@ -552,8 +559,13 @@ function(hf_download version out_var out_resolved)

         file(ARCHIVE_EXTRACT INPUT "${archive}" DESTINATION "${DIST_DIR}")

-        if(NOT EXISTS "${DIST_DIR}/index.html")
-            message(STATUS "UI: archive from ${resolved} is missing required assets")
+        # 'latest' can be from a newer build with a file layout this checkout does not know
+        file(GLOB_RECURSE extracted LIST_DIRECTORIES false RELATIVE "${DIST_DIR}" "${DIST_DIR}/*")
+        ui_missing_assets("${extracted}" missing)
+        if(missing)
+            string(REPLACE ";" ", " missing "${missing}")
+            message(STATUS "UI: archive from ${resolved} is missing required assets: ${missing}")
+            file(REMOVE_RECURSE "${DIST_DIR}")
             continue()
         endif()

diff --git a/ui/apps/chat/CMakeLists.txt b/ui/apps/chat/CMakeLists.txt
index 79ffe9fc1..61776f96d 100644
--- a/ui/apps/chat/CMakeLists.txt
+++ b/ui/apps/chat/CMakeLists.txt
@@ -25,6 +25,32 @@ elseif(DEFINED ENV{HF_UI_VERSION})
     set(HF_UI_VERSION "$ENV{HF_UI_VERSION}")
 elseif(DEFINED LLAMA_BUILD_NUMBER)
     set(HF_UI_VERSION "b${LLAMA_BUILD_NUMBER}")
+    # a shallow clone has no history, so the build number from git is wrong:
+    # use the release tag on HEAD if it was fetched, else 'latest'
+    if(Git_FOUND AND "${LLAMA_BUILD_NUMBER}" STREQUAL "${BUILD_NUMBER}")
+        execute_process(
+            COMMAND ${GIT_EXECUTABLE} rev-parse --is-shallow-repository
+            WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+            OUTPUT_VARIABLE UI_GIT_SHALLOW
+            OUTPUT_STRIP_TRAILING_WHITESPACE
+            ERROR_QUIET
+        )
+        if(UI_GIT_SHALLOW STREQUAL "true")
+            set(HF_UI_VERSION "latest")
+            execute_process(
+                COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match --match "b[0-9]*" HEAD
+                WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+                OUTPUT_VARIABLE UI_GIT_TAG
+                OUTPUT_STRIP_TRAILING_WHITESPACE
+                RESULT_VARIABLE UI_GIT_TAG_RES
+                ERROR_QUIET
+            )
+            if(UI_GIT_TAG_RES EQUAL 0 AND UI_GIT_TAG MATCHES "^b[0-9]+$")
+                set(HF_UI_VERSION "${UI_GIT_TAG}")
+            endif()
+            message(STATUS "UI: shallow clone, prebuilt UI version: ${HF_UI_VERSION}")
+        endif()
+    endif()
 else()
     set(HF_UI_VERSION "")
 endif()