File PKGBUILD of Package llama.cpp-cuda-git
# Maintainer: Giovanni Santini <giovannisantini93@yahoo.it>
# Contributor: Bink
## Build parameters
# Whether to build an universal binary
aur_llamacpp_build_universal="${aur_llamacpp_build_universal:=false}"
# Custom CMake flags
aur_llamacpp_cmakeopts="${aur_llamacpp_cmakeopts:-}"
# Usual business
pkgname=llama.cpp-cuda-git
_pkgname="llama.cpp"
pkgver=b8140
pkgrel=1
_build_number=0
_commit_id=
pkgdesc="Port of Facebook's LLaMA model in C/C++ (with NVIDIA CUDA optimizations)"
arch=(x86_64 armv7h aarch64)
url='https://github.com/ggerganov/llama.cpp'
license=('MIT')
depends=(
cuda
curl
gcc-libs
glibc
nvidia-utils
)
makedepends=(
cmake
git
openssl
cudnn
)
optdepends=(
'python-numpy: needed for convert_hf_to_gguf.py'
'python-safetensors: needed for convert_hf_to_gguf.py'
'python-sentencepiece: needed for convert_hf_to_gguf.py'
'python-pytorch: needed for convert_hf_to_gguf.py'
'python-transformers: needed for convert_hf_to_gguf.py'
)
provides=("${_pkgname}")
conflicts=("${_pkgname}" libggml ggml)
source=(
"llama.cpp-${pkgver}.tar"
"llama.cpp.conf::https://aur.archlinux.org/cgit/aur.git/plain/llama.cpp.conf?h=llama.cpp-cuda-git"
"llama.cpp.service::https://aur.archlinux.org/cgit/aur.git/plain/llama.cpp.service?h=llama.cpp-cuda-git"
)
sha512sums=('SKIP'
'246ac2188dbc9b4f149c2cb388c23e6c371a4fb9517e297cca2228801048e57f64c442831f221aa4e7ef09e6a676b7a24af919aa604e68fc1b32055e3d544621'
'97bbfb2aab24e32a7b19f41ce5bcbeaa4bf0fa324b540df557213b273f31d0c719e9ee5c7286d100be2f5b832641eab5e2fa5e8555e0c9e30bdbeb4aedd9162a')
# Not needed, done from 'set_version'
# pkgver() {
# cd "${_pkgname}" || exit
# printf "%s" "$(git describe --tags | sed 's/\([^-]*-\)g/r\1/;s/-/./g')"
# }
prepare() {
cd "${_pkgname}-${pkgver}" || exit
# Get the latest commit hash
# TODO: Git metadata gets corructed ...
#_commit_id=$(git rev-parse HEAD)
#_build_number=$(git rev-list --count HEAD)
# so let's calculate from pkgver which comes correctly from "set_version"
_tag_number=$(echo $pkgver | cut -d. -f1 | sed 's,^b,,')
_offset_number=$(echo $pkgver | cut -d. -f2 | sed 's,^r,,')
_commit_id=$(cut -d. -f3 <<< $pkgver)
_build_number=$(($_tag_number + $_offset_number))
cd ..
#ln -sf "${_pkgname}-${pkgver}" llama.cpp
}
build() {
# This may not be set if the user's session
# has not restarted on a new 'cuda' install
if [[ -z "${NVCC_CCBIN}" ]]; then
source /etc/profile
fi
local _cmake_options=(
-B build
-S "${_pkgname}-${pkgver}"
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX='/usr'
-DBUILD_SHARED_LIBS=ON
-DLLAMA_BUILD_TESTS=OFF
-DLLAMA_USE_SYSTEM_GGML=OFF
-DGGML_ALL_WARNINGS=OFF
-DGGML_ALL_WARNINGS_3RD_PARTY=OFF
-DGGML_BUILD_EXAMPLES=OFF
-DGGML_BUILD_TESTS=OFF
-DGGML_OPENMP=ON
-DGGML_LTO=ON
-DGGML_RPC=ON
-DGGML_CUDA=ON
-DGGML_CUDA_FA_ALL_QUANTS=ON
-DGGML_CUDNN=ON
-DLLAMA_BUILD_SERVER=ON
-DLLAMA_BUILD_NUMBER="${_build_number}"
-DLLAMA_BUILD_COMMIT="${_commit_id}"
-DLLAMA_OPENSSL=ON
-Wno-dev
)
if [[ ${aur_llamacpp_build_universal} == true ]]; then
echo "Building universal binary [aur_llamacpp_build_universal == true]"
_cmake_options+=(
-DGGML_BACKEND_DL=ON
-DGGML_NATIVE=OFF
-DGGML_CPU_ALL_VARIANTS=ON
)
else
# we lose GGML_NATIVE_DEFAULT due to how makepkg includes
# $SOURCE_DATE_EPOCH in ENV
_cmake_options+=(
-DGGML_NATIVE=ON
)
fi
# Allow user-specified additional flags
if [[ -n "${aur_llamacpp_cmakeopts:-}" ]]; then
echo "Applying custom CMake options: ${aur_llamacpp_cmakeopts}"
# shellcheck disable=SC2206 # intentional word splitting
_cmake_options+=(${aur_llamacpp_cmakeopts})
fi
cmake "${_cmake_options[@]}"
cmake --build build
}
package() {
DESTDIR="${pkgdir}" cmake --install build
install -Dm644 "${_pkgname}-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
install -Dm644 "llama.cpp.conf" "${pkgdir}/etc/conf.d/llama.cpp"
install -Dm644 "llama.cpp.service" "${pkgdir}/usr/lib/systemd/system/llama.cpp.service"
}