-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·414 lines (375 loc) · 11.1 KB
/
build.sh
File metadata and controls
executable file
·414 lines (375 loc) · 11.1 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#!/usr/bin/env bash
set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "$0")" && pwd)"
BUILD_TYPE="Release"
PRESET=""
# Initialize optional variables (required for set -u)
DO_BUNDLE="0"
DO_ARCHIVE="0"
PREFIX=""
ARCHIVE_NAME=""
GENERATOR=""
MACOS_ARCH=""
LIVEKIT_VERSION=""
# Detect OS for preset selection
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux";;
Darwin*) echo "macos";;
*) echo "linux";; # Default to linux
esac
}
OS_TYPE="$(detect_os)"
usage() {
cat <<EOF
Usage:
./build.sh <command> [options]
Commands:
debug Configure + build Debug version (build-debug/)
debug-examples Configure + build Debug version with examples
debug-tests Configure + build Debug version with tests
release Configure + build Release version (build-release/)
release-examples Configure + build Release version with examples
release-tests Configure + build Release version with tests
clean Clean both Debug and Release build directories
clean-all Full clean (build dirs + Rust targets)
help Show this help message
Options (for debug / release):
--bundle Install the SDK bundle using 'cmake --install'
--prefix <dir> Install prefix for --bundle
(default: ./sdk-out/livekit-sdk)
--archive After --bundle, create an archive of the SDK bundle
(.zip if available, otherwise .tar.gz)
--archive-name <name> Override archive base name (no extension)
--version <version> Inject SDK version into build (sets LIVEKIT_VERSION)
Example: 0.1.0 or 1.0.0-rc1
-G <generator> CMake generator (e.g. Ninja, "Unix Makefiles")
--macos-arch <arch> macOS architecture override (arm64 or x86_64)
Sets CMAKE_OSX_ARCHITECTURES
Examples:
./build.sh release
./build.sh release-examples
./build.sh debug
./build.sh debug-tests
./build.sh release-tests
./build.sh clean
./build.sh clean-all
EOF
}
parse_opts() {
shift || true
while [[ $# -gt 0 ]]; do
case "$1" in
--bundle)
DO_BUNDLE="1"
shift
;;
--prefix)
PREFIX="${2:-}"
if [[ -z "${PREFIX}" ]]; then
echo "ERROR: --prefix requires a value"
exit 1
fi
shift 2
;;
--archive)
DO_ARCHIVE="1"
shift
;;
--archive-name)
ARCHIVE_NAME="${2:-}"
if [[ -z "${ARCHIVE_NAME}" ]]; then
echo "ERROR: --archive-name requires a value"
exit 1
fi
shift 2
;;
-G)
GENERATOR="${2:-}"
if [[ -z "${GENERATOR}" ]]; then
echo "ERROR: -G requires a generator name"
exit 1
fi
shift 2
;;
--macos-arch)
MACOS_ARCH="${2:-}"
if [[ -z "${MACOS_ARCH}" ]]; then
echo "ERROR: --macos-arch requires a value (arm64 or x86_64)"
exit 1
fi
shift 2
;;
--version)
LIVEKIT_VERSION="${2:-}"
[[ -n "${LIVEKIT_VERSION}" ]] || { echo "ERROR: --version requires a value"; exit 1; }
shift 2
;;
-h|--help|help)
usage
exit 0
;;
*)
echo "ERROR: Unknown option: $1"
usage
exit 1
;;
esac
done
}
configure() {
echo "==> Configuring CMake (${BUILD_TYPE}) using preset ${PRESET}..."
local -a extra_args=()
if [[ -n "${LIVEKIT_VERSION}" ]]; then
echo "==> Injecting LIVEKIT_VERSION=${LIVEKIT_VERSION}"
extra_args+=("-DLIVEKIT_VERSION=${LIVEKIT_VERSION}")
fi
if ((${#extra_args[@]})); then
if ! cmake --preset "${PRESET}" "${extra_args[@]}"; then
echo "Warning: CMake preset '${PRESET}' failed. Falling back to traditional configure..."
cmake -S . -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" "${extra_args[@]}"
fi
else
if ! cmake --preset "${PRESET}"; then
echo "Warning: CMake preset '${PRESET}' failed. Falling back to traditional configure..."
cmake -S . -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}"
fi
fi
}
build() {
echo "==> Building (${BUILD_TYPE})..."
if [[ -n "${PRESET}" ]] && [[ -f "${PROJECT_ROOT}/CMakePresets.json" ]]; then
# Use preset build if available
cmake --build --preset "${PRESET}"
else
# Fallback to traditional build
cmake --build "${BUILD_DIR}"
fi
}
install_bundle() {
# Default prefix if user asked for --bundle but didn't set one
if [[ -z "${PREFIX}" ]]; then
PREFIX="${PROJECT_ROOT}/sdk-out/livekit-sdk"
fi
# Make prefix absolute for nicer archives
if [[ "${PREFIX}" != /* ]]; then
PREFIX="${PROJECT_ROOT}/${PREFIX}"
fi
echo "==> Installing SDK bundle to: ${PREFIX}"
rm -rf "${PREFIX}"
mkdir -p "${PREFIX}"
# Detect whether generator is multi-config (VS/Xcode) or single-config (Ninja/Unix Makefiles)
local is_multi_config=0
if [[ -f "${BUILD_DIR}/CMakeCache.txt" ]]; then
if grep -q '^CMAKE_CONFIGURATION_TYPES:STRING=' "${BUILD_DIR}/CMakeCache.txt"; then
is_multi_config=1
fi
fi
# Run install
if [[ "${is_multi_config}" -eq 1 ]]; then
echo "==> cmake --install (multi-config) config=${BUILD_TYPE}"
cmake --install "${BUILD_DIR}" --config "${BUILD_TYPE}" --prefix "${PREFIX}"
else
echo "==> cmake --install (single-config)"
cmake --install "${BUILD_DIR}" --prefix "${PREFIX}"
fi
local libdir=""
if [[ -d "${PREFIX}/lib" ]]; then
libdir="${PREFIX}/lib"
elif [[ -d "${PREFIX}/lib64" ]]; then
libdir="${PREFIX}/lib64"
else
echo "WARN: ${PREFIX}/lib or lib64 not found. Did you add install(TARGETS ...) rules?"
fi
if [[ -n "${libdir}" ]]; then
if [[ ! -d "${libdir}/cmake/LiveKit" ]]; then
echo "WARN: CMake package files not found under ${libdir}/cmake/LiveKit."
echo " Did you add install(EXPORT ...) + install(FILES LiveKitConfig*.cmake ...)?"
else
# Optional: verify that key files exist
if [[ ! -f "${libdir}/cmake/LiveKit/LiveKitConfig.cmake" ]]; then
echo "WARN: Missing ${libdir}/cmake/LiveKit/LiveKitConfig.cmake"
fi
if [[ ! -f "${libdir}/cmake/LiveKit/LiveKitTargets.cmake" ]]; then
echo "WARN: Missing ${libdir}/cmake/LiveKit/LiveKitTargets.cmake (install(EXPORT ...) didn’t run?)"
fi
if [[ ! -f "${libdir}/cmake/LiveKit/LiveKitConfigVersion.cmake" ]]; then
echo "WARN: Missing ${libdir}/cmake/LiveKit/LiveKitConfigVersion.cmake"
fi
fi
fi
}
archive_bundle() {
if [[ "${DO_BUNDLE}" != "1" ]]; then
echo "ERROR: --archive requires --bundle"
exit 1
fi
local base
if [[ -n "${ARCHIVE_NAME}" ]]; then
base="${ARCHIVE_NAME}"
else
base="$(basename "${PREFIX}")"
fi
local out_dir
out_dir="$(dirname "${PREFIX}")"
echo "==> Archiving bundle..."
pushd "${out_dir}" >/dev/null
# Prefer zip if available and user is on macOS/Linux too; otherwise tar.gz
if command -v zip >/dev/null 2>&1; then
rm -f "${base}.zip"
# Zip the directory (preserve folder root)
zip -r "${base}.zip" "${base}" >/dev/null
echo "==> Wrote: ${out_dir}/${base}.zip"
else
rm -f "${base}.tar.gz"
tar -czf "${base}.tar.gz" "${base}"
echo "==> Wrote: ${out_dir}/${base}.tar.gz"
fi
popd >/dev/null
}
clean() {
echo "==> Cleaning build artifacts..."
local debug_dir="${PROJECT_ROOT}/build-debug"
local release_dir="${PROJECT_ROOT}/build-release"
# For Ninja builds, use ninja -t clean directly to avoid CMake reconfiguration
# For other generators (e.g., Make), cmake --build --target clean works fine
if [[ -d "${debug_dir}" ]]; then
echo " Cleaning build-debug..."
if [[ -f "${debug_dir}/build.ninja" ]]; then
# Ninja: use -t clean to avoid reconfiguration
ninja -C "${debug_dir}" -t clean 2>/dev/null || rm -rf "${debug_dir}/lib" "${debug_dir}/bin" || true
elif [[ -f "${debug_dir}/Makefile" ]]; then
make -C "${debug_dir}" clean 2>/dev/null || true
else
echo " (skipping) Unknown build system or not configured"
fi
else
echo " (skipping) build-debug does not exist."
fi
if [[ -d "${release_dir}" ]]; then
echo " Cleaning build-release..."
if [[ -f "${release_dir}/build.ninja" ]]; then
# Ninja: use -t clean to avoid reconfiguration
ninja -C "${release_dir}" -t clean 2>/dev/null || rm -rf "${release_dir}/lib" "${release_dir}/bin" || true
elif [[ -f "${release_dir}/Makefile" ]]; then
make -C "${release_dir}" clean 2>/dev/null || true
else
echo " (skipping) Unknown build system or not configured"
fi
else
echo " (skipping) build-release does not exist."
fi
echo "==> Clean complete."
}
clean_all() {
echo "==> Running full clean-all (C++ + Rust)..."
echo "Removing build-debug directory..."
rm -rf "${PROJECT_ROOT}/build-debug" || true
echo "Removing build-release directory..."
rm -rf "${PROJECT_ROOT}/build-release" || true
echo "Removing Rust debug artifacts..."
rm -rf "${PROJECT_ROOT}/client-sdk-rust/target/debug" || true
echo "Removing Rust release artifacts..."
rm -rf "${PROJECT_ROOT}/client-sdk-rust/target/release" || true
echo "==> Clean-all complete."
}
if [[ $# -eq 0 ]]; then
usage
exit 0
fi
cmd="$1"
parse_opts "$@"
case "${cmd}" in
debug)
BUILD_TYPE="Debug"
BUILD_DIR="${PROJECT_ROOT}/build-debug"
PRESET="${OS_TYPE}-debug"
configure
build
if [[ "${DO_BUNDLE}" == "1" ]]; then
install_bundle
if [[ "${DO_ARCHIVE}" == "1" ]]; then
archive_bundle
fi
fi
;;
debug-examples)
BUILD_TYPE="Debug"
BUILD_DIR="${PROJECT_ROOT}/build-debug"
PRESET="${OS_TYPE}-debug-examples"
configure
build
if [[ "${DO_BUNDLE}" == "1" ]]; then
install_bundle
if [[ "${DO_ARCHIVE}" == "1" ]]; then
archive_bundle
fi
fi
;;
release)
BUILD_TYPE="Release"
BUILD_DIR="${PROJECT_ROOT}/build-release"
PRESET="${OS_TYPE}-release"
configure
build
if [[ "${DO_BUNDLE}" == "1" ]]; then
install_bundle
if [[ "${DO_ARCHIVE}" == "1" ]]; then
archive_bundle
fi
fi
;;
release-examples)
BUILD_TYPE="Release"
BUILD_DIR="${PROJECT_ROOT}/build-release"
PRESET="${OS_TYPE}-release-examples"
configure
build
if [[ "${DO_BUNDLE}" == "1" ]]; then
install_bundle
if [[ "${DO_ARCHIVE}" == "1" ]]; then
archive_bundle
fi
fi
;;
debug-tests)
BUILD_TYPE="Debug"
BUILD_DIR="${PROJECT_ROOT}/build-debug"
PRESET="${OS_TYPE}-debug-tests"
configure
build
if [[ "${DO_BUNDLE}" == "1" ]]; then
install_bundle
if [[ "${DO_ARCHIVE}" == "1" ]]; then
archive_bundle
fi
fi
;;
release-tests)
BUILD_TYPE="Release"
BUILD_DIR="${PROJECT_ROOT}/build-release"
PRESET="${OS_TYPE}-release-tests"
configure
build
if [[ "${DO_BUNDLE}" == "1" ]]; then
install_bundle
if [[ "${DO_ARCHIVE}" == "1" ]]; then
archive_bundle
fi
fi
;;
clean)
clean
;;
clean-all)
clean_all
;;
help|-h|--help)
usage
;;
*)
echo "Unknown command: ${cmd}"
usage
exit 1
;;
esac