Repository navigation
Expand file tree
/
Copy pathgitlab_build_release_macos.sh
More file actions
637 lines (560 loc) · 26 KB
/
Copy pathgitlab_build_release_macos.sh
File metadata and controls
637 lines (560 loc) · 26 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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
#!/bin/bash
set -e
set -o pipefail
while getopts ":dpa:snt:xbc:1h" opt; do
case "${opt}" in
d )
export BUILD_TARGET="deps"
;;
p )
export PACK_DEPS="1"
;;
a )
export ARCH="$OPTARG"
;;
s )
export BUILD_TARGET="slicer"
;;
n )
export NIGHTLY_BUILD="1"
;;
t )
export OSX_DEPLOYMENT_TARGET="$OPTARG"
;;
x )
export SLICER_CMAKE_GENERATOR="Ninja Multi-Config"
export SLICER_BUILD_TARGET="all"
export DEPS_CMAKE_GENERATOR="Ninja"
;;
b )
export BUILD_ONLY="1"
;;
c )
export BUILD_CONFIG="$OPTARG"
;;
1 )
export CMAKE_BUILD_PARALLEL_LEVEL=1
;;
h ) echo "Usage: ./gitlab_build_release_macos.sh [-d]"
echo " -d: Build deps only"
echo " -a: Set ARCHITECTURE (arm64 or x86_64 or universal)"
echo " -s: Build slicer only"
echo " -n: Nightly build"
echo " -t: Specify minimum version of the target platform, default is 12.0"
echo " -x: Use Ninja Multi-Config CMake generator, default is Xcode"
echo " -b: Build without reconfiguring CMake"
echo " -c: Set CMake build configuration, default is Release"
echo " -1: Use single job for building"
exit 0
;;
* )
;;
esac
done
# ============================================================
# GitLab repository configuration
# ============================================================
if [ -z "$GITLAB_BASE_URL" ]; then
export GITLAB_BASE_URL="gitlab.s.com"
fi
if [ -z "$GITLAB_GROUP" ]; then
export GITLAB_GROUP="snapmaker_orca"
fi
if [ -z "$LOCAL_REF_BASE" ]; then
export LOCAL_REF_BASE="/Users/snapmaker/Documents/gitlab_pro/OrcaSlicer"
fi
GITLAB_VENDOR="git@${GITLAB_BASE_URL}:${GITLAB_GROUP}/snapmaker_orca_vendor.git"
GITLAB_WXWIDGETS="git@${GITLAB_BASE_URL}:${GITLAB_GROUP}/Orca-deps-wxWidgets.git"
GITLAB_SENTRY="git@${GITLAB_BASE_URL}:${GITLAB_GROUP}/sentry-native.git"
ORCA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="${ORCA_ROOT}"
VENDOR_DIR="${ORCA_ROOT}/gitlab_vendor"
WXWIDGETS_DIR="${ORCA_ROOT}/Orca-deps-wxWidgets"
SENTRY_DIR="${ORCA_ROOT}/sentry-native"
# ============================================================
# Restore patched cmake files on script exit
# ============================================================
function restore_vendor_cmake() {
if [ -d "${VENDOR_DIR}/.git" ]; then
echo "Restoring patched vendor cmake files..."
pushd "${VENDOR_DIR}" > /dev/null
git checkout -- gitlab_deps/wxWidgets/wxWidgets.cmake 2>/dev/null || true
git checkout -- gitlab_deps/Sentry/Sentry.cmake 2>/dev/null || true
git checkout -- gitlab_deps/OpenVDB/OpenVDB.cmake 2>/dev/null || true
popd > /dev/null
fi
}
trap restore_vendor_cmake EXIT
# ============================================================
# Clone / sync GitLab sub-repositories
# ============================================================
function sync_gitlab_repos() {
echo "============================================================"
echo " Syncing GitLab sub-repositories..."
echo "============================================================"
echo " ORCA_ROOT : ${ORCA_ROOT}"
echo " VENDOR : ${VENDOR_DIR}"
echo " WXWIDGETS : ${WXWIDGETS_DIR}"
echo " SENTRY : ${SENTRY_DIR}"
echo "============================================================"
echo
# --- gitlab_vendor ---
if [ -d "${VENDOR_DIR}/.git" ]; then
echo " vendor: fetching latest..."
pushd "${VENDOR_DIR}" > /dev/null
git fetch origin
git reset --hard FETCH_HEAD
popd > /dev/null
else
rm -rf "${VENDOR_DIR}"
echo " vendor: cloning ${GITLAB_VENDOR} ..."
git clone --depth 50 --reference-if-able "${LOCAL_REF_BASE}/gitlab_vendor" "${GITLAB_VENDOR}" "${VENDOR_DIR}"
fi
# --- Orca-deps-wxWidgets ---
if [ -d "${WXWIDGETS_DIR}/.git" ]; then
echo " wxWidgets: pulling latest..."
pushd "${WXWIDGETS_DIR}" > /dev/null
git pull --ff-only
popd > /dev/null
else
rm -rf "${WXWIDGETS_DIR}"
echo " wxWidgets: cloning ${GITLAB_WXWIDGETS} ..."
git clone --depth 50 --reference-if-able "${LOCAL_REF_BASE}/Orca-deps-wxWidgets" "${GITLAB_WXWIDGETS}" "${WXWIDGETS_DIR}"
fi
# --- sentry-native ---
if [ -d "${SENTRY_DIR}/.git" ]; then
echo " sentry: pulling latest..."
pushd "${SENTRY_DIR}" > /dev/null
git pull --ff-only
popd > /dev/null
else
rm -rf "${SENTRY_DIR}"
echo " sentry: cloning ${GITLAB_SENTRY} ..."
git clone --depth 50 --reference-if-able "${LOCAL_REF_BASE}/sentry-native" "${GITLAB_SENTRY}" "${SENTRY_DIR}"
fi
# --- sentry-native submodule (crashpad) ---
echo " sentry: fixing submodule URLs (HTTP -> SSH) and initializing..."
pushd "${SENTRY_DIR}" > /dev/null
# Use git global url.insteadOf to redirect ALL HTTP URLs to SSH.
# This handles nested submodules (crashpad has 3 sub-submodules)
# that also use HTTP in their own .gitmodules files.
# Keep --global (git -c does not reach nested submodule git processes).
# Always unset on the way out so a failed submodule update cannot leak
# the redirect into the user's global git config. Restore a pre-existing
# value if the machine already had the same insteadOf key.
INSTEADOF_OLD="$(git config --global --get "url.git@${GITLAB_BASE_URL}:.insteadOf" 2>/dev/null || true)"
restore_insteadOf() {
if [ -n "${INSTEADOF_OLD}" ]; then
git config --global "url.git@${GITLAB_BASE_URL}:.insteadOf" "${INSTEADOF_OLD}"
else
git config --global --unset "url.git@${GITLAB_BASE_URL}:.insteadOf" 2>/dev/null || true
fi
}
git config --global url."git@${GITLAB_BASE_URL}:".insteadOf "http://${GITLAB_BASE_URL}/"
submodule_failed=0
git submodule update --init --recursive --depth 1 || submodule_failed=1
restore_insteadOf
if [ "${submodule_failed}" -ne 0 ]; then
popd > /dev/null
echo " sentry: submodule update failed"
exit 1
fi
popd > /dev/null
echo " All repos synced successfully."
echo
}
# ============================================================
# Patch vendor cmake files to use local source dirs
# Instead of letting ExternalProject git-clone from GitHub,
# we point it to the already-cloned local repos from GitLab.
# ============================================================
function patch_cmake_for_local_sources() {
echo "Patching cmake files for local sources..."
local WX_CMAKE="${VENDOR_DIR}/gitlab_deps/wxWidgets/wxWidgets.cmake"
local SENTRY_CMAKE="${VENDOR_DIR}/gitlab_deps/Sentry/Sentry.cmake"
# wxWidgets: replace GIT_REPOSITORY with SOURCE_DIR, remove GIT_SHALLOW
if [ -f "$WX_CMAKE" ]; then
sed -i '' \
-e 's|GIT_REPOSITORY "https://github\.com/SoftFever/Orca-deps-wxWidgets"|SOURCE_DIR "'"${WXWIDGETS_DIR}"'"|' \
-e '/GIT_SHALLOW ON/d' \
"$WX_CMAKE"
echo " wxWidgets -> SOURCE_DIR"
fi
# Sentry: replace GIT_REPOSITORY with SOURCE_DIR, remove GIT_TAG + GIT_SHALLOW
if [ -f "$SENTRY_CMAKE" ]; then
sed -i '' -E \
-e 's|GIT_REPOSITORY[[:space:]]+https://github\.com/getsentry/sentry-native\.git|SOURCE_DIR "'"${SENTRY_DIR}"'"|' \
-e '/GIT_TAG[[:space:]]+[0-9.]+/d' \
-e '/GIT_SHALLOW[[:space:]]+ON/d' \
"$SENTRY_CMAKE"
echo " Sentry -> SOURCE_DIR"
fi
# OpenVDB: fix Apple Clang 17+ compatibility (-Wmissing-template-arg-list-after-template-kw)
local OPENVDB_CMAKE="${VENDOR_DIR}/gitlab_deps/OpenVDB/OpenVDB.cmake"
if [ -f "$OPENVDB_CMAKE" ]; then
if grep -q "Wno-missing-template-arg-list-after-template-kw" "$OPENVDB_CMAKE"; then
echo " OpenVDB -> already patched"
else
sed -i '' 's|-DDISABLE_DEPENDENCY_VERSION_CHECKS=ON|-DDISABLE_DEPENDENCY_VERSION_CHECKS=ON\n -DCMAKE_CXX_FLAGS=-Wno-missing-template-arg-list-after-template-kw|' "$OPENVDB_CMAKE"
echo " OpenVDB -> add Clang 17 compat flag"
fi
fi
echo
}
# ============================================================
# Prepare gitlab_deps_src from vendor
# The slicer build uses deps_src/ via add_subdirectory().
# We copy the vendor's version to gitlab_deps_src/ and
# pass -DDEPS_SRC_DIR=gitlab_deps_src to CMake.
# The original deps_src/ is NOT touched.
# ============================================================
function prepare_deps_src() {
echo "Preparing vendored library sources..."
if [ -d "${VENDOR_DIR}/gitlab_deps_src" ]; then
# Remove stale copy from previous run
if [ -d "${ORCA_ROOT}/gitlab_deps_src" ]; then
echo " Removing stale gitlab_deps_src/..."
rm -rf "${ORCA_ROOT}/gitlab_deps_src"
fi
# Copy vendor version to root as gitlab_deps_src/
echo " Copying vendor/gitlab_deps_src/ to gitlab_deps_src/..."
cp -R "${VENDOR_DIR}/gitlab_deps_src" "${ORCA_ROOT}/gitlab_deps_src"
else
echo " [WARNING] Vendor repo has no gitlab_deps_src/, using original deps_src/"
fi
echo " deps_src ready."
echo
}
# ============================================================
# Set build defaults
# ============================================================
if [ -z "$ARCH" ]; then
ARCH="$(uname -m)"
export ARCH
fi
if [ -z "$BUILD_CONFIG" ]; then
export BUILD_CONFIG="Release"
fi
if [ -z "$BUILD_TARGET" ]; then
export BUILD_TARGET="all"
fi
if [ -z "$SLICER_CMAKE_GENERATOR" ]; then
export SLICER_CMAKE_GENERATOR="Xcode"
fi
if [ -z "$SLICER_BUILD_TARGET" ]; then
export SLICER_BUILD_TARGET="ALL_BUILD"
fi
if [ -z "$DEPS_CMAKE_GENERATOR" ]; then
export DEPS_CMAKE_GENERATOR="Unix Makefiles"
fi
if [ -z "$OSX_DEPLOYMENT_TARGET" ]; then
export OSX_DEPLOYMENT_TARGET="12.0"
fi
echo "Build params:"
echo " - ARCH: $ARCH"
echo " - BUILD_CONFIG: $BUILD_CONFIG"
echo " - BUILD_TARGET: $BUILD_TARGET"
echo " - CMAKE_GENERATOR: $SLICER_CMAKE_GENERATOR for Slicer, $DEPS_CMAKE_GENERATOR for deps"
echo " - OSX_DEPLOYMENT_TARGET: $OSX_DEPLOYMENT_TARGET"
echo
# ============================================================
# Paths for GitLab build
# deps source: gitlab_vendor/gitlab_deps (patched cmake files)
# deps build: gitlab_vendor/gitlab_deps/build/$ARCH
# deps output: gitlab_vendor/gitlab_deps/build/$ARCH/OrcaSlicer_dep
# slicer build: gitlab_build/$ARCH
# slicer output: gitlab_build/$ARCH/Snapmaker_Orca/
# ============================================================
DEPS_DIR="${ORCA_ROOT}/gitlab_vendor/gitlab_deps"
DEPS_BUILD_DIR="$DEPS_DIR/build/$ARCH"
DEPS="$DEPS_BUILD_DIR/OrcaSlicer_dep"
PROJECT_BUILD_DIR="$ORCA_ROOT/gitlab_build/$ARCH"
# For Multi-config generators like Ninja and Xcode
export BUILD_DIR_CONFIG_SUBDIR="/$BUILD_CONFIG"
function build_deps() {
# iterate over two architectures: x86_64 and arm64
for _ARCH in x86_64 arm64; do
# if ARCH is universal or equal to _ARCH
if [ "$ARCH" == "universal" ] || [ "$ARCH" == "$_ARCH" ]; then
DEPS_BUILD_DIR="$DEPS_DIR/build/$_ARCH"
DEPS="$DEPS_BUILD_DIR/OrcaSlicer_dep"
echo "Building deps for $_ARCH..."
(
set -x
mkdir -p "$DEPS"
cd "$DEPS_BUILD_DIR"
if [ "1." != "$BUILD_ONLY". ]; then
cmake "${DEPS_DIR}" \
-G "${DEPS_CMAKE_GENERATOR}" \
-DDESTDIR="$DEPS" \
-DOPENSSL_ARCH="darwin64-${_ARCH}-cc" \
-DCMAKE_BUILD_TYPE="$BUILD_CONFIG" \
-DCMAKE_OSX_ARCHITECTURES:STRING="${_ARCH}" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="${OSX_DEPLOYMENT_TARGET}"
fi
cmake --build . --config "$BUILD_CONFIG" --target deps
)
fi
done
}
function pack_deps() {
echo "Packing deps..."
(
set -x
cd "$DEPS_DIR"
tar -zcvf "OrcaSlicer_dep_mac_${ARCH}_$(date +"%Y%m%d").tar.gz" "build"
)
}
function build_slicer() {
# iterate over two architectures: x86_64 and arm64
for _ARCH in x86_64 arm64; do
# if ARCH is universal or equal to _ARCH
if [ "$ARCH" == "universal" ] || [ "$ARCH" == "$_ARCH" ]; then
PROJECT_BUILD_DIR="$ORCA_ROOT/gitlab_build/$_ARCH"
DEPS_BUILD_DIR="$DEPS_DIR/build/$_ARCH"
DEPS="$DEPS_BUILD_DIR/OrcaSlicer_dep"
echo "Building slicer for $_ARCH..."
(
set -x
mkdir -p "$PROJECT_BUILD_DIR"
cd "$PROJECT_BUILD_DIR"
if [ "1." != "$BUILD_ONLY". ]; then
cmake "${ORCA_ROOT}" \
-G "${SLICER_CMAKE_GENERATOR}" \
-DBBL_RELEASE_TO_PUBLIC=1 \
-DORCA_TOOLS=ON \
${ORCA_UPDATER_SIG_KEY:+-DORCA_UPDATER_SIG_KEY="$ORCA_UPDATER_SIG_KEY"} \
-DDEPS_SRC_DIR=gitlab_deps_src \
-DCMAKE_PREFIX_PATH="$DEPS/usr/local" \
-DCMAKE_INSTALL_PREFIX="$PWD/Snapmaker_Orca" \
-DCMAKE_BUILD_TYPE="$BUILD_CONFIG" \
-DCMAKE_MACOSX_RPATH=ON \
-DCMAKE_INSTALL_RPATH="${DEPS}/usr/local" \
-DCMAKE_MACOSX_BUNDLE=ON \
-DCMAKE_OSX_ARCHITECTURES="${_ARCH}" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="${OSX_DEPLOYMENT_TARGET}"
fi
cmake --build . --config "$BUILD_CONFIG" --target "$SLICER_BUILD_TARGET"
# Explicitly build profile_validator if ORCA_TOOLS is enabled
if [ "$SLICER_BUILD_TARGET" = "all" ] || [ "$SLICER_BUILD_TARGET" = "ALL_BUILD" ]; then
cmake --build . --config "$BUILD_CONFIG" --target Snapmaker_Orca_profile_validator || echo "Warning: Snapmaker_Orca_profile_validator build failed or not available"
fi
)
echo "Verify localization with gettext..."
(
cd "$PROJECT_DIR"
./scripts/run_gettext.sh
)
echo "Fix macOS app package..."
(
cd "$PROJECT_BUILD_DIR"
mkdir -p Snapmaker_Orca
cd Snapmaker_Orca
# remove previously built app
rm -rf "./Snapmaker Orca.app"
# determine source app path (handle both space and underscore names)
APP_SOURCE_PATH="../src$BUILD_DIR_CONFIG_SUBDIR/Snapmaker Orca.app"
if [ ! -d "$APP_SOURCE_PATH" ]; then
APP_SOURCE_PATH="../src$BUILD_DIR_CONFIG_SUBDIR/Snapmaker_Orca.app"
fi
if [ ! -d "$APP_SOURCE_PATH" ]; then
echo "Error: cannot find built app bundle at $APP_SOURCE_PATH"
exit 1
fi
# fully copy newly built app (rename to canonical name with space)
cp -pR "$APP_SOURCE_PATH" "./Snapmaker Orca.app"
# fix resources
resources_path=$(readlink "./Snapmaker Orca.app/Contents/Resources")
rm "./Snapmaker Orca.app/Contents/Resources"
cp -R "$resources_path" "./Snapmaker Orca.app/Contents/Resources"
# delete .DS_Store file
find "./Snapmaker Orca.app/" -name '.DS_Store' -delete
# Copy Sentry crashpad_handler and libsentry.dylib for crash reporting
CRASHPAD_HANDLER="${DEPS}/usr/local/bin/crashpad_handler"
LIBSENTRY="${DEPS}/usr/local/lib/libsentry.dylib"
APP_MACOS_DIR='./Snapmaker Orca.app/Contents/MacOS'
APP_FRAMEWORKS_DIR='./Snapmaker Orca.app/Contents/Frameworks'
EXECUTABLE="${APP_MACOS_DIR}/Snapmaker_Orca"
if [ -f "${CRASHPAD_HANDLER}" ]; then
echo "Copying crashpad_handler to app bundle..."
cp -f "${CRASHPAD_HANDLER}" "${APP_MACOS_DIR}/crashpad_handler"
# Sign crashpad_handler
codesign --force --sign - "${APP_MACOS_DIR}/crashpad_handler" 2>/dev/null || true
else
echo "Warning: crashpad_handler not found at ${CRASHPAD_HANDLER}"
fi
if [ -f "${LIBSENTRY}" ]; then
echo "Copying libsentry.dylib to Frameworks..."
mkdir -p "${APP_FRAMEWORKS_DIR}"
cp -f "${LIBSENTRY}" "${APP_FRAMEWORKS_DIR}/libsentry.dylib"
# Sign libsentry.dylib
codesign --force --sign - "${APP_FRAMEWORKS_DIR}/libsentry.dylib" 2>/dev/null || true
# Update rpath in Snapmaker_Orca to use @executable_path relative path
if [ -f "${EXECUTABLE}" ]; then
echo "Updating libsentry.dylib rpath in Snapmaker_Orca..."
install_name_tool -change "@rpath/libsentry.dylib" "@executable_path/../Frameworks/libsentry.dylib" "${EXECUTABLE}" 2>/dev/null || true
# Re-sign the executable after modification
codesign --force --sign - "${EXECUTABLE}" 2>/dev/null || true
fi
else
echo "Warning: libsentry.dylib not found at ${LIBSENTRY}"
fi
# Copy Snapmaker_Orca_profile_validator.app if it exists
if [ -f "../src$BUILD_DIR_CONFIG_SUBDIR/Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" ]; then
echo "Copying Snapmaker_Orca_profile_validator.app..."
rm -rf ./Snapmaker_Orca_profile_validator.app
cp -pR "../src$BUILD_DIR_CONFIG_SUBDIR/Snapmaker_Orca_profile_validator.app" ./Snapmaker_Orca_profile_validator.app
# delete .DS_Store file
find ./Snapmaker_Orca_profile_validator.app/ -name '.DS_Store' -delete
fi
# Generate dSYM debug symbols for debugging and Sentry crash reporting
# Always generate dSYM files - they are useful for crash analysis even without Sentry
echo "Generating dSYM debug symbols..."
DSYM_DIR="./dSYM"
mkdir -p "${DSYM_DIR}"
# Generate dSYM for main app
if [ -f "${APP_MACOS_DIR}/Snapmaker_Orca" ]; then
echo "Generating dSYM for Snapmaker_Orca..."
dsymutil "${APP_MACOS_DIR}/Snapmaker_Orca" -o "${DSYM_DIR}/Snapmaker_Orca.dSYM" 2>/dev/null || echo "Warning: Failed to generate dSYM for Snapmaker_Orca (no debug symbols?)"
fi
# Generate dSYM for crashpad_handler if it exists
if [ -f "${APP_MACOS_DIR}/crashpad_handler" ]; then
echo "Generating dSYM for crashpad_handler..."
dsymutil "${APP_MACOS_DIR}/crashpad_handler" -o "${DSYM_DIR}/crashpad_handler.dSYM" 2>/dev/null || true
fi
# Generate dSYM for libsentry.dylib if it exists
if [ -f "${APP_FRAMEWORKS_DIR}/libsentry.dylib" ]; then
echo "Generating dSYM for libsentry.dylib..."
dsymutil "${APP_FRAMEWORKS_DIR}/libsentry.dylib" -o "${DSYM_DIR}/libsentry.dSYM" 2>/dev/null || true
fi
# Generate dSYM for profile_validator if it exists
if [ -f "./Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" ]; then
echo "Generating dSYM for Snapmaker_Orca_profile_validator..."
dsymutil "./Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" -o "${DSYM_DIR}/Snapmaker_Orca_profile_validator.dSYM" 2>/dev/null || true
fi
echo "dSYM files generated in ${DSYM_DIR}"
ls -la "${DSYM_DIR}" 2>/dev/null || echo "No dSYM files generated"
)
fi
done
}
function build_universal() {
echo "Building universal binary..."
PROJECT_BUILD_DIR="$ORCA_ROOT/gitlab_build/$ARCH"
# Create universal binary
echo "Creating universal binary..."
mkdir -p "$PROJECT_BUILD_DIR/Snapmaker_Orca"
UNIVERSAL_APP="$PROJECT_BUILD_DIR/Snapmaker_Orca/Snapmaker Orca.app"
rm -rf "$UNIVERSAL_APP"
cp -R "$ORCA_ROOT/gitlab_build/arm64/Snapmaker_Orca/Snapmaker Orca.app" "$UNIVERSAL_APP"
# Get the binary path inside the .app bundle
BINARY_PATH="Contents/MacOS/Snapmaker_Orca"
# Create universal binary using lipo
lipo -create \
"$ORCA_ROOT/gitlab_build/x86_64/Snapmaker_Orca/Snapmaker Orca.app/$BINARY_PATH" \
"$ORCA_ROOT/gitlab_build/arm64/Snapmaker_Orca/Snapmaker Orca.app/$BINARY_PATH" \
-output "$UNIVERSAL_APP/$BINARY_PATH"
echo "Universal binary created at $UNIVERSAL_APP"
# Create universal crashpad_handler if both architectures have it
CRASHPAD_ARM64="${ORCA_ROOT}/gitlab_build/arm64/Snapmaker_Orca/Snapmaker Orca.app/Contents/MacOS/crashpad_handler"
CRASHPAD_X86="${ORCA_ROOT}/gitlab_build/x86_64/Snapmaker_Orca/Snapmaker Orca.app/Contents/MacOS/crashpad_handler"
CRASHPAD_UNIVERSAL="${UNIVERSAL_APP}/Contents/MacOS/crashpad_handler"
if [ -f "${CRASHPAD_ARM64}" ] && [ -f "${CRASHPAD_X86}" ]; then
echo "Creating universal crashpad_handler..."
lipo -create "${CRASHPAD_X86}" "${CRASHPAD_ARM64}" -output "${CRASHPAD_UNIVERSAL}"
codesign --force --sign - "${CRASHPAD_UNIVERSAL}" 2>/dev/null || true
elif [ -f "${CRASHPAD_ARM64}" ]; then
cp -f "${CRASHPAD_ARM64}" "${CRASHPAD_UNIVERSAL}"
codesign --force --sign - "${CRASHPAD_UNIVERSAL}" 2>/dev/null || true
fi
# Create universal libsentry.dylib if both architectures have it
LIBSENTRY_ARM64="${ORCA_ROOT}/gitlab_build/arm64/Snapmaker_Orca/Snapmaker Orca.app/Contents/Frameworks/libsentry.dylib"
LIBSENTRY_X86="${ORCA_ROOT}/gitlab_build/x86_64/Snapmaker_Orca/Snapmaker Orca.app/Contents/Frameworks/libsentry.dylib"
LIBSENTRY_UNIVERSAL="${UNIVERSAL_APP}/Contents/Frameworks/libsentry.dylib"
if [ -f "${LIBSENTRY_ARM64}" ] && [ -f "${LIBSENTRY_X86}" ]; then
echo "Creating universal libsentry.dylib..."
mkdir -p "${UNIVERSAL_APP}/Contents/Frameworks"
lipo -create "${LIBSENTRY_X86}" "${LIBSENTRY_ARM64}" -output "${LIBSENTRY_UNIVERSAL}"
codesign --force --sign - "${LIBSENTRY_UNIVERSAL}" 2>/dev/null || true
elif [ -f "${LIBSENTRY_ARM64}" ]; then
mkdir -p "${UNIVERSAL_APP}/Contents/Frameworks"
cp -f "${LIBSENTRY_ARM64}" "${LIBSENTRY_UNIVERSAL}"
codesign --force --sign - "${LIBSENTRY_UNIVERSAL}" 2>/dev/null || true
fi
# Update rpath in universal Snapmaker_Orca
if [ -f "${LIBSENTRY_UNIVERSAL}" ]; then
echo "Updating libsentry.dylib rpath in universal Snapmaker_Orca..."
install_name_tool -change "@rpath/libsentry.dylib" "@executable_path/../Frameworks/libsentry.dylib" "${UNIVERSAL_APP}/${BINARY_PATH}" 2>/dev/null || true
codesign --force --sign - "${UNIVERSAL_APP}/${BINARY_PATH}" 2>/dev/null || true
fi
# Create universal binary for profile validator if it exists
if [ -f "$ORCA_ROOT/gitlab_build/arm64/Snapmaker_Orca/Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" ] && \
[ -f "$ORCA_ROOT/gitlab_build/x86_64/Snapmaker_Orca/Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" ]; then
echo "Creating universal binary for Snapmaker_Orca_profile_validator..."
UNIVERSAL_VALIDATOR_APP="$PROJECT_BUILD_DIR/Snapmaker_Orca/Snapmaker_Orca_profile_validator.app"
rm -rf "$UNIVERSAL_VALIDATOR_APP"
cp -R "$ORCA_ROOT/gitlab_build/arm64/Snapmaker_Orca/Snapmaker_Orca_profile_validator.app" "$UNIVERSAL_VALIDATOR_APP"
# Get the binary path inside the profile validator .app bundle
VALIDATOR_BINARY_PATH="Contents/MacOS/Snapmaker_Orca_profile_validator"
# Create universal binary using lipo
lipo -create \
"$ORCA_ROOT/gitlab_build/x86_64/Snapmaker_Orca/Snapmaker_Orca_profile_validator.app/$VALIDATOR_BINARY_PATH" \
"$ORCA_ROOT/gitlab_build/arm64/Snapmaker_Orca/Snapmaker_Orca_profile_validator.app/$VALIDATOR_BINARY_PATH" \
-output "$UNIVERSAL_VALIDATOR_APP/$VALIDATOR_BINARY_PATH"
echo "Universal binary for Snapmaker_Orca_profile_validator created at $UNIVERSAL_VALIDATOR_APP"
fi
# Generate dSYM for universal binary - always generate for debugging and Sentry crash reporting
echo "Generating dSYM for universal binary..."
DSYM_DIR="$PROJECT_BUILD_DIR/Snapmaker_Orca/dSYM"
mkdir -p "${DSYM_DIR}"
# Generate dSYM for universal main app
if [ -f "$UNIVERSAL_APP/$BINARY_PATH" ]; then
echo "Generating dSYM for universal Snapmaker_Orca..."
dsymutil "$UNIVERSAL_APP/$BINARY_PATH" -o "${DSYM_DIR}/Snapmaker_Orca.dSYM" 2>/dev/null || echo "Warning: Failed to generate dSYM for universal Snapmaker_Orca"
fi
# Generate dSYM for universal crashpad_handler if it exists
if [ -f "$UNIVERSAL_APP/Contents/MacOS/crashpad_handler" ]; then
echo "Generating dSYM for universal crashpad_handler..."
dsymutil "$UNIVERSAL_APP/Contents/MacOS/crashpad_handler" -o "${DSYM_DIR}/crashpad_handler.dSYM" 2>/dev/null || true
fi
# Generate dSYM for universal libsentry.dylib if it exists
if [ -f "$UNIVERSAL_APP/Contents/Frameworks/libsentry.dylib" ]; then
echo "Generating dSYM for universal libsentry.dylib..."
dsymutil "$UNIVERSAL_APP/Contents/Frameworks/libsentry.dylib" -o "${DSYM_DIR}/libsentry.dSYM" 2>/dev/null || true
fi
# Generate dSYM for universal profile_validator if it exists
if [ -f "$UNIVERSAL_VALIDATOR_APP/$VALIDATOR_BINARY_PATH" ]; then
echo "Generating dSYM for universal Snapmaker_Orca_profile_validator..."
dsymutil "$UNIVERSAL_VALIDATOR_APP/$VALIDATOR_BINARY_PATH" -o "${DSYM_DIR}/Snapmaker_Orca_profile_validator.dSYM" 2>/dev/null || true
fi
echo "Universal dSYM files generated in ${DSYM_DIR}"
ls -la "${DSYM_DIR}" 2>/dev/null || echo "No dSYM files generated"
}
# ============================================================
# GitLab build: sync repos, patch cmake, prepare sources
# ============================================================
sync_gitlab_repos
patch_cmake_for_local_sources
prepare_deps_src
case "${BUILD_TARGET}" in
all)
build_deps
build_slicer
;;
deps)
build_deps
;;
slicer)
build_slicer
;;
*)
echo "Unknown target: $BUILD_TARGET. Available targets: deps, slicer, all."
exit 1
;;
esac
if [ "$ARCH" = "universal" ] && [ "$BUILD_TARGET" != "deps" ]; then
build_universal
fi
if [ "1." == "$PACK_DEPS". ]; then
pack_deps
fi