gen_common.sh 1.39 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
    if [ -n "${OLLAMA_SKIP_PATCHING}" ]; then
29
30
31
        echo "Skipping submodule patching"
        return
    fi
32
33
    # Workaround git apply not handling creation well for iteration
    rm -f gguf/examples/server/server.h
34
    for patch in ${PATCHES}; do
35
36
37
38
39
        git -C gguf apply ../patches/${patch}
    done
}

build() {
40
41
    cmake -S ${LLAMACPP_DIR} -B ${BUILD_DIR} ${CMAKE_DEFS}
    cmake --build ${BUILD_DIR} ${CMAKE_TARGETS} -j8
42
}