"scripts/build_windows.ps1" did not exist on "b0135f4b9b176eab9155b660d04c9ca2a1ec2341"
gen_common.sh 2.33 KB
Newer Older
1
2
3
# common logic accross linux and darwin

init_vars() {
4
    LLAMACPP_DIR=../llama.cpp
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
10
    else
        # TODO - add additional optimization flags...
11
        CMAKE_DEFS="-DCMAKE_BUILD_TYPE=Release -DLLAMA_SERVER_VERBOSE=off"
12
13
14
15
    fi
}

git_module_setup() {
16
    if [ -n "${OLLAMA_SKIP_PATCHING}" ]; then
17
18
19
        echo "Skipping submodule initialization"
        return
    fi
Daniel Hiltgen's avatar
Daniel Hiltgen committed
20
21
22
23
24
    # Make sure the tree is clean after the directory moves
    if [ -d "${LLAMACPP_DIR}/gguf" ]; then
        echo "Cleaning up old submodule"
        rm -rf ${LLAMACPP_DIR}
    fi
25
    git submodule init
26
    git submodule update --force ${LLAMACPP_DIR}
27
28
29
30

}

apply_patches() {
31
    # Wire up our CMakefile
32
33
    if ! grep ollama ${LLAMACPP_DIR}/examples/server/CMakeLists.txt; then
        echo 'include (../../../ext_server/CMakeLists.txt) # ollama' >>${LLAMACPP_DIR}/examples/server/CMakeLists.txt
34
    fi
35
    # Avoid duplicate main symbols when we link into the cgo binary
36
37
    sed -e 's/int main(/int __main(/g' <${LLAMACPP_DIR}/examples/server/server.cpp >${LLAMACPP_DIR}/examples/server/server.cpp.tmp &&
        mv ${LLAMACPP_DIR}/examples/server/server.cpp.tmp ${LLAMACPP_DIR}/examples/server/server.cpp
38
39
40
}

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

45
46
47
48
49
50
51
52
53
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
}

54
55
56
57
58
59
60
61
62
63
link_server_lib() {
    gcc -fPIC -g -shared -o ${BUILD_DIR}/lib/libext_server.so \
        -Wl,--whole-archive \
        ${BUILD_DIR}/lib/libext_server.a \
        -Wl,--no-whole-archive \
        ${BUILD_DIR}/lib/libcommon.a \
        ${BUILD_DIR}/lib/libllama.a

}

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