gen_common.sh 1.67 KB
Newer Older
1
2
3
# common logic accross linux and darwin

init_vars() {
4
    LLAMACPP_DIR=gguf
5
    PATCHES="0001-Expose-callable-API-for-server.patch"
6
    CMAKE_DEFS="-DLLAMA_ACCELERATE=on"
7
    # TODO - LLAMA_K_QUANTS is stale and needs to be mapped to newer cmake settings
8
    CMAKE_TARGETS="--target ggml --target ggml_static --target llama --target build_info --target common --target ext_server --target llava_static"
9
    if echo "${CGO_CFLAGS}" | grep -- '-g' >/dev/null; then
10
        CMAKE_DEFS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=on -DLLAMA_GPROF=on -DLLAMA_SERVER_VERBOSE=on ${CMAKE_DEFS}"
11
12
    else
        # TODO - add additional optimization flags...
13
        CMAKE_DEFS="-DCMAKE_BUILD_TYPE=Release -DLLAMA_SERVER_VERBOSE=off ${CMAKE_DEFS}"
14
15
16
17
    fi
}

git_module_setup() {
18
    if [ -n "${OLLAMA_SKIP_PATCHING}" ]; then
19
20
21
        echo "Skipping submodule initialization"
        return
    fi
22
23
24
25
26
27
    git submodule init
    git submodule update --force gguf

}

apply_patches() {
28
29
30
    # Wire up our CMakefile
    if ! grep ollama.txt gguf/examples/server/CMakeLists.txt; then
        echo 'include (../../../ollama.txt)' >>gguf/examples/server/CMakeLists.txt
31
    fi
32
33
34
    # 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
35
36
37
}

build() {
38
39
    cmake -S ${LLAMACPP_DIR} -B ${BUILD_DIR} ${CMAKE_DEFS}
    cmake --build ${BUILD_DIR} ${CMAKE_TARGETS} -j8
40
}
41
42
43
44
45

# Keep the local tree clean after we're done with the build
cleanup() {
    (cd gguf/examples/server/ && git checkout CMakeLists.txt server.cpp)
}