-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_app.sh
More file actions
executable file
·86 lines (75 loc) · 2.46 KB
/
build_app.sh
File metadata and controls
executable file
·86 lines (75 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
build_dir="${repo_root}/build"
executable_name="ggml-guided-diffusion"
build_jobs="${GD_BUILD_JOBS:-}"
run_after_build=1
clean_cmake=0
while [[ $# -gt 0 ]]; do
case "$1" in
--jobs)
if [[ $# -lt 2 ]]; then
echo "Missing value for --jobs"
exit 1
fi
build_jobs="$2"
shift 2
;;
--no-run)
run_after_build=0
shift
;;
--clean-cmake)
clean_cmake=1
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--jobs <n>] [--no-run] [--clean-cmake]"
echo "CUDA support is determined by which ggml was pre-built via ./build_ggml.sh [--cuda]"
exit 1
;;
esac
done
if [[ -z "${build_jobs}" ]]; then
if command -v nproc >/dev/null 2>&1; then
build_jobs="$(nproc)"
else
build_jobs="4"
fi
fi
cache_file="${build_dir}/CMakeCache.txt"
if [[ "${clean_cmake}" == "1" ]]; then
echo "Resetting app CMake state (--clean-cmake)"
rm -f "${cache_file}"
rm -rf "${build_dir}/CMakeFiles"
elif [[ -f "${cache_file}" ]]; then
cached_source_dir="$(sed -n 's|^CMAKE_HOME_DIRECTORY:INTERNAL=||p' "${cache_file}" | head -n1)"
if [[ -n "${cached_source_dir}" && "${cached_source_dir}" != "${repo_root}" ]]; then
echo "Detected stale CMake cache from: ${cached_source_dir}"
echo "Resetting build cache in ${build_dir}"
rm -f "${cache_file}"
rm -rf "${build_dir}/CMakeFiles"
fi
fi
ggml_install_dir="${repo_root}/libs/ggml/install"
if [[ ! -f "${ggml_install_dir}/lib/cmake/ggml/ggml-config.cmake" ]]; then
echo "Installed ggml not found at ${ggml_install_dir}."
echo "Run ./build_ggml.sh (with --cuda if needed) before building the app."
exit 1
fi
cmake_args=(
-DCMAKE_BUILD_TYPE=Release
-DGGML_INSTALL_DIR="${ggml_install_dir}"
)
cmake -S "${repo_root}" -B "${build_dir}" "${cmake_args[@]}"
echo "Building app with ${build_jobs} parallel job(s)"
cmake --build "${build_dir}" --config Release --parallel "${build_jobs}"
if [[ "${run_after_build}" == "1" ]]; then
"${build_dir}/${executable_name}" "${repo_root}/models"
echo "App build and model load completed successfully."
else
echo "Skipping post-build model run (--no-run)"
echo "App build completed successfully."
fi