Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: bake a relocatable RUNPATH into the Linux llama.cpp source build (#12398)

Shubhankar Tripathyd97fe69016fa
diff --git a/studio/setup.sh b/studio/setup.sh
index c1c8ef225d8..e7f14c6f235 100755
--- a/studio/setup.sh
+++ b/studio/setup.sh
@@ -743,6 +743,15 @@ _resolve_cuda_archs() {
# above that: it must also cover MSVC and hipcc, older and far heavier CUDA
# toolkits (ggml-org/llama.cpp#17844 climbs past 16 GiB), and the link step.
# Erring high costs build time; erring low costs the machine.
+# The build dir is renamed into place, so CMake's build-tree RUNPATH dies at the mv (#12392):
+# $ORIGIN finds the sibling libllama*.so; USE_LINK_PATH keeps toolchain dirs (ROCm, CUDA, Nix).
+_llama_relocatable_rpath_args() {
+ case "$(uname -s 2>/dev/null)" in
+ Linux) printf '%s' '-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_INSTALL_RPATH=$ORIGIN -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON' ;;
+ *) printf '' ;;
+ esac
+}
+
_LLAMA_BUILD_RESERVE_MB=2048
_LLAMA_BUILD_MB_PER_JOB=2048
@@ -5149,7 +5158,7 @@ else
if [ "$BUILD_OK" = true ]; then
# Set Release explicitly (llama.cpp only defaults to it on non-MSVC/Xcode).
- CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_TESTS=OFF -DLLAMA_BUILD_EXAMPLES=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_NATIVE=ON"
+ CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_TESTS=OFF -DLLAMA_BUILD_EXAMPLES=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_NATIVE=ON $(_llama_relocatable_rpath_args)"
_TRY_METAL_CPU_FALLBACK=false
_HOST_SYSTEM="$(uname -s 2>/dev/null || true)"
_HOST_MACHINE="$(uname -m 2>/dev/null || true)"
diff --git a/tests/sh/test_llama_relocatable_rpath.sh b/tests/sh/test_llama_relocatable_rpath.sh
new file mode 100755
index 00000000000..9f5189f149a
--- /dev/null
+++ b/tests/sh/test_llama_relocatable_rpath.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+# _llama_relocatable_rpath_args() from studio/setup.sh (#12392): $ORIGIN RUNPATH on Linux only.
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+. "$SCRIPT_DIR/_harness.sh"
+SETUP_SH="$SCRIPT_DIR/../../studio/setup.sh"
+_FUNC_FILE=$(mktemp)
+sed -n '/^_llama_relocatable_rpath_args()/,/^}/p' "$SETUP_SH" > "$_FUNC_FILE"
+if [ ! -s "$_FUNC_FILE" ]; then
+ echo "FAIL: could not extract _llama_relocatable_rpath_args from setup.sh"
+ exit 1
+fi
+
+# $1 = what `uname -s` answers.
+run_args() {
+ UNAME_S="$1" bash -c ". '$_FUNC_FILE'; uname() { printf '%s' \"\$UNAME_S\"; }; _llama_relocatable_rpath_args"
+}
+
+echo "=== test_llama_relocatable_rpath ==="
+
+LINUX="$(run_args Linux)"
+# $ORIGIN must stay literal: the loader expands it, not the shell.
+assert_contains "Linux bakes an \$ORIGIN install RUNPATH" "$LINUX" '-DCMAKE_INSTALL_RPATH=$ORIGIN'
+assert_contains "Linux builds with the install RUNPATH" "$LINUX" '-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON'
+assert_contains "Linux keeps the link path" "$LINUX" '-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON'
+assert_not_contains "no build-tree path is named" "$LINUX" 'llama.cpp.build'
+
+# macOS gets @loader_path in the Metal branch instead.
+assert_eq "Darwin adds nothing" "" "$(run_args Darwin)"
+assert_eq "unknown host adds nothing" "" "$(run_args "")"
+
+# CPU_FALLBACK_CMAKE_ARGS must be copied after the base line to inherit the flags.
+BASE_LINE="$(grep -n 'CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release' "$SETUP_SH" | head -1)"
+assert_contains "configure line calls the helper" "$BASE_LINE" '$(_llama_relocatable_rpath_args)'
+FALLBACK_LINE="$(grep -n 'CPU_FALLBACK_CMAKE_ARGS="\$CMAKE_ARGS"' "$SETUP_SH" | head -1 | cut -d: -f1)"
+BASE_NO="$(echo "$BASE_LINE" | cut -d: -f1)"
+if [ -n "$FALLBACK_LINE" ] && [ "$FALLBACK_LINE" -gt "$BASE_NO" ]; then
+ ok "CPU fallback args are copied after the RUNPATH is set"
+else
+ bad "CPU fallback args are copied after the RUNPATH is set (base=$BASE_NO fallback=$FALLBACK_LINE)"
+fi
+
+rm -f "$_FUNC_FILE"
+summary