gen_common.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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=""
  6. CMAKE_TARGETS="--target ggml --target ggml_static --target llama --target build_info --target common --target ext_server --target llava_static"
  7. if echo "${CGO_CFLAGS}" | grep -- '-g' >/dev/null; then
  8. CMAKE_DEFS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=on -DLLAMA_GPROF=on -DLLAMA_SERVER_VERBOSE=on"
  9. else
  10. # TODO - add additional optimization flags...
  11. CMAKE_DEFS="-DCMAKE_BUILD_TYPE=Release -DLLAMA_SERVER_VERBOSE=off"
  12. fi
  13. }
  14. git_module_setup() {
  15. if [ -n "${OLLAMA_SKIP_PATCHING}" ]; then
  16. echo "Skipping submodule initialization"
  17. return
  18. fi
  19. git submodule init
  20. git submodule update --force gguf
  21. }
  22. apply_patches() {
  23. # Wire up our CMakefile
  24. if ! grep ollama gguf/examples/server/CMakeLists.txt; then
  25. echo 'include (../../../CMakeLists.txt) # ollama' >>gguf/examples/server/CMakeLists.txt
  26. fi
  27. # Avoid duplicate main symbols when we link into the cgo binary
  28. sed -e 's/int main(/int __main(/g' <./gguf/examples/server/server.cpp >./gguf/examples/server/server.cpp.tmp &&
  29. mv ./gguf/examples/server/server.cpp.tmp ./gguf/examples/server/server.cpp
  30. }
  31. build() {
  32. cmake -S ${LLAMACPP_DIR} -B ${BUILD_DIR} ${CMAKE_DEFS}
  33. cmake --build ${BUILD_DIR} ${CMAKE_TARGETS} -j8
  34. }
  35. install() {
  36. rm -rf ${BUILD_DIR}/lib
  37. mkdir -p ${BUILD_DIR}/lib
  38. cp ${BUILD_DIR}/examples/server/libext_server.a ${BUILD_DIR}/lib
  39. cp ${BUILD_DIR}/common/libcommon.a ${BUILD_DIR}/lib
  40. cp ${BUILD_DIR}/libllama.a ${BUILD_DIR}/lib
  41. cp ${BUILD_DIR}/libggml_static.a ${BUILD_DIR}/lib
  42. }
  43. # Keep the local tree clean after we're done with the build
  44. cleanup() {
  45. (cd gguf/examples/server/ && git checkout CMakeLists.txt server.cpp)
  46. }