gen_common.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # common logic accross linux and darwin
  2. init_vars() {
  3. LLAMACPP_DIR=gguf
  4. PATCHES="0001-Expose-callable-API-for-server.patch"
  5. CMAKE_DEFS="-DLLAMA_ACCELERATE=on"
  6. # TODO - LLAMA_K_QUANTS is stale and needs to be mapped to newer cmake settings
  7. CMAKE_TARGETS="--target ggml --target ggml_static --target llama --target build_info --target common --target ext_server --target llava_static"
  8. if echo "${CGO_CFLAGS}" | grep -- '-g' >/dev/null; then
  9. CMAKE_DEFS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=on -DLLAMA_GPROF=on -DLLAMA_SERVER_VERBOSE=on ${CMAKE_DEFS}"
  10. else
  11. # TODO - add additional optimization flags...
  12. CMAKE_DEFS="-DCMAKE_BUILD_TYPE=Release -DLLAMA_SERVER_VERBOSE=off ${CMAKE_DEFS}"
  13. fi
  14. }
  15. git_module_setup() {
  16. if [ -n "${OLLAMA_SKIP_PATCHING}" ]; then
  17. echo "Skipping submodule initialization"
  18. return
  19. fi
  20. git submodule init
  21. git submodule update --force gguf
  22. }
  23. apply_patches() {
  24. if [ -n "${OLLAMA_SKIP_PATCHING}" ]; then
  25. echo "Skipping submodule patching"
  26. return
  27. fi
  28. # Workaround git apply not handling creation well for iteration
  29. rm -f gguf/examples/server/server.h
  30. for patch in ${PATCHES}; do
  31. git -C gguf apply ../patches/${patch}
  32. done
  33. }
  34. build() {
  35. cmake -S ${LLAMACPP_DIR} -B ${BUILD_DIR} ${CMAKE_DEFS}
  36. cmake --build ${BUILD_DIR} ${CMAKE_TARGETS} -j8
  37. }