2023-11-14 01:20:34 +00:00
|
|
|
# common logic accross linux and darwin
|
|
|
|
|
|
|
|
init_vars() {
|
2023-11-29 19:00:37 +00:00
|
|
|
LLAMACPP_DIR=gguf
|
2023-11-14 01:20:34 +00:00
|
|
|
PATCHES="0001-Expose-callable-API-for-server.patch"
|
|
|
|
CMAKE_DEFS="-DLLAMA_ACCELERATE=on"
|
|
|
|
# TODO - LLAMA_K_QUANTS is stale and needs to be mapped to newer cmake settings
|
2023-11-29 19:00:37 +00:00
|
|
|
CMAKE_TARGETS="--target ggml --target ggml_static --target llama --target build_info --target common --target ext_server --target llava_static"
|
2023-11-14 01:20:34 +00:00
|
|
|
if echo "${CGO_CFLAGS}" | grep -- '-g' > /dev/null ; then
|
|
|
|
CMAKE_DEFS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=on -DLLAMA_GPROF=on ${CMAKE_DEFS}"
|
|
|
|
else
|
|
|
|
# TODO - add additional optimization flags...
|
|
|
|
CMAKE_DEFS="-DCMAKE_BUILD_TYPE=Release ${CMAKE_DEFS}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
git_module_setup() {
|
2023-12-18 20:05:59 +00:00
|
|
|
if [ -n "${OLLAMA_SKIP_PATCHING}" ] ; then
|
|
|
|
echo "Skipping submodule initialization"
|
|
|
|
return
|
|
|
|
fi
|
2023-11-14 01:20:34 +00:00
|
|
|
git submodule init
|
|
|
|
git submodule update --force gguf
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
apply_patches() {
|
2023-12-18 20:05:59 +00:00
|
|
|
if [ -n "${OLLAMA_SKIP_PATCHING}" ] ; then
|
|
|
|
echo "Skipping submodule patching"
|
|
|
|
return
|
|
|
|
fi
|
2023-11-14 01:20:34 +00:00
|
|
|
# Workaround git apply not handling creation well for iteration
|
|
|
|
rm -f gguf/examples/server/server.h
|
|
|
|
for patch in ${PATCHES} ; do
|
|
|
|
git -C gguf apply ../patches/${patch}
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
build() {
|
2023-11-29 19:00:37 +00:00
|
|
|
cmake -S ${LLAMACPP_DIR} -B ${BUILD_DIR} ${CMAKE_DEFS}
|
|
|
|
cmake --build ${BUILD_DIR} ${CMAKE_TARGETS} -j8
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|