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"
|
2024-01-04 00:22:15 +00:00
|
|
|
CMAKE_DEFS=""
|
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-12-20 18:36:01 +00:00
|
|
|
if echo "${CGO_CFLAGS}" | grep -- '-g' >/dev/null; then
|
2024-01-04 00:22:15 +00:00
|
|
|
CMAKE_DEFS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=on -DLLAMA_GPROF=on -DLLAMA_SERVER_VERBOSE=on"
|
2023-11-14 01:20:34 +00:00
|
|
|
else
|
|
|
|
# TODO - add additional optimization flags...
|
2024-01-04 00:22:15 +00:00
|
|
|
CMAKE_DEFS="-DCMAKE_BUILD_TYPE=Release -DLLAMA_SERVER_VERBOSE=off"
|
2023-11-14 01:20:34 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
git_module_setup() {
|
2023-12-20 18:36:01 +00:00
|
|
|
if [ -n "${OLLAMA_SKIP_PATCHING}" ]; then
|
2023-12-18 20:05:59 +00:00
|
|
|
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-22 17:51:53 +00:00
|
|
|
# Wire up our CMakefile
|
2023-12-24 22:12:21 +00:00
|
|
|
if ! grep ollama gguf/examples/server/CMakeLists.txt; then
|
|
|
|
echo 'include (../../../CMakeLists.txt) # ollama' >>gguf/examples/server/CMakeLists.txt
|
2023-12-18 20:05:59 +00:00
|
|
|
fi
|
2023-12-22 17:51:53 +00:00
|
|
|
# Avoid duplicate main symbols when we link into the cgo binary
|
|
|
|
sed -e 's/int main(/int __main(/g' <./gguf/examples/server/server.cpp >./gguf/examples/server/server.cpp.tmp &&
|
|
|
|
mv ./gguf/examples/server/server.cpp.tmp ./gguf/examples/server/server.cpp
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-12-20 18:36:01 +00:00
|
|
|
}
|
2023-12-22 17:51:53 +00:00
|
|
|
|
2023-12-23 19:35:44 +00:00
|
|
|
install() {
|
|
|
|
rm -rf ${BUILD_DIR}/lib
|
|
|
|
mkdir -p ${BUILD_DIR}/lib
|
|
|
|
cp ${BUILD_DIR}/examples/server/libext_server.a ${BUILD_DIR}/lib
|
|
|
|
cp ${BUILD_DIR}/common/libcommon.a ${BUILD_DIR}/lib
|
|
|
|
cp ${BUILD_DIR}/libllama.a ${BUILD_DIR}/lib
|
|
|
|
cp ${BUILD_DIR}/libggml_static.a ${BUILD_DIR}/lib
|
|
|
|
}
|
|
|
|
|
2023-12-22 17:51:53 +00:00
|
|
|
# Keep the local tree clean after we're done with the build
|
|
|
|
cleanup() {
|
|
|
|
(cd gguf/examples/server/ && git checkout CMakeLists.txt server.cpp)
|
|
|
|
}
|