Fix llama-server: build in-tree, fix path resolution, add LD_LIBRARY_PATH

This commit is contained in:
Roland Tannous 2026-02-24 18:19:29 +04:00
commit 08aeeaee4b
3 changed files with 42 additions and 26 deletions

View file

@ -207,10 +207,10 @@ else
fi
# ── 8. Build llama-server for GGUF inference ──
# Builds in an isolated temp directory to avoid conflicts with unsloth-zoo's
# own llama.cpp management (used for GGUF export). Only the llama-server
# binary is extracted to $REPO/bin/.
LLAMA_SERVER_BIN="$SCRIPT_DIR/bin/llama-server"
# Builds in-tree at $REPO/llama.cpp/. This directory is shared with
# unsloth-zoo's GGUF export pipeline — if converter/quantize are missing,
# unsloth-zoo will rebuild them on first export. We only build llama-server here.
LLAMA_SERVER_BIN="$SCRIPT_DIR/llama.cpp/build/bin/llama-server"
if [ -f "$LLAMA_SERVER_BIN" ]; then
echo ""
echo "✅ llama-server already exists at $LLAMA_SERVER_BIN"
@ -226,10 +226,17 @@ else
else
echo ""
echo "Building llama-server for GGUF inference..."
LLAMA_BUILD_TMP=$(mktemp -d)
LLAMA_CPP_DIR="$SCRIPT_DIR/llama.cpp"
BUILD_OK=true
run_quiet "clone llama.cpp" git clone --depth 1 https://github.com/ggml-org/llama.cpp.git "$LLAMA_BUILD_TMP/llama.cpp" || BUILD_OK=false
if [ -d "$LLAMA_CPP_DIR/.git" ]; then
echo " llama.cpp repo already cloned, pulling latest..."
run_quiet "pull llama.cpp" git -C "$LLAMA_CPP_DIR" pull || true
else
# Remove any non-git llama.cpp directory (stale build artifacts)
rm -rf "$LLAMA_CPP_DIR"
run_quiet "clone llama.cpp" git clone --depth 1 https://github.com/ggml-org/llama.cpp.git "$LLAMA_CPP_DIR" || BUILD_OK=false
fi
if [ "$BUILD_OK" = true ]; then
CMAKE_ARGS=""
@ -258,27 +265,22 @@ else
NCPU=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
run_quiet "cmake llama.cpp" cmake -S "$LLAMA_BUILD_TMP/llama.cpp" -B "$LLAMA_BUILD_TMP/llama.cpp/build" $CMAKE_ARGS || BUILD_OK=false
run_quiet "cmake llama.cpp" cmake -S "$LLAMA_CPP_DIR" -B "$LLAMA_CPP_DIR/build" $CMAKE_ARGS || BUILD_OK=false
fi
if [ "$BUILD_OK" = true ]; then
run_quiet "build llama-server" cmake --build "$LLAMA_BUILD_TMP/llama.cpp/build" --config Release --target llama-server -j"$NCPU" || BUILD_OK=false
run_quiet "build llama-server" cmake --build "$LLAMA_CPP_DIR/build" --config Release --target llama-server -j"$NCPU" || BUILD_OK=false
fi
if [ "$BUILD_OK" = true ]; then
mkdir -p "$SCRIPT_DIR/bin"
if [ -f "$LLAMA_BUILD_TMP/llama.cpp/build/bin/llama-server" ]; then
cp "$LLAMA_BUILD_TMP/llama.cpp/build/bin/llama-server" "$LLAMA_SERVER_BIN"
echo "✅ llama-server built and installed to $LLAMA_SERVER_BIN"
if [ -f "$LLAMA_SERVER_BIN" ]; then
echo "✅ llama-server built at $LLAMA_SERVER_BIN"
else
echo "⚠️ llama-server binary not found after build — GGUF inference won't be available"
fi
else
echo "⚠️ llama-server build failed — GGUF inference won't be available, but everything else works"
fi
# Clean up temp build directory
rm -rf "$LLAMA_BUILD_TMP"
fi
fi