11#! /bin/bash
2- set -eo pipefail
2+ set -euo pipefail
33
44# Build script for creating architecture-specific releases
55# Usage: ./build-release.sh [arm64|x86_64|both]
@@ -264,8 +264,7 @@ bundle_dylibs() {
264264 # (e.g. strchrnul) that don't exist on earlier OS versions → launch crash.
265265 echo " Verifying deployment target compatibility..."
266266 local deploy_target
267- deploy_target=$( xcodebuild -project " $PROJECT " -scheme " $SCHEME " -showBuildSettings 2> /dev/null \
268- | grep -m 1 ' MACOSX_DEPLOYMENT_TARGET' | awk ' {print $3}' )
267+ deploy_target=$( echo " $build_settings " | grep -m 1 ' MACOSX_DEPLOYMENT_TARGET' | awk ' {print $3}' )
269268 if [ -n " $deploy_target " ]; then
270269 local deploy_major
271270 deploy_major=$( echo " $deploy_target " | cut -d. -f1)
@@ -301,13 +300,6 @@ bundle_dylibs() {
301300 echo " ⚠️ WARNING: Could not determine deployment target, skipping dylib version check"
302301 fi
303302
304- # Sign bundled dylibs (will be re-signed with proper identity later)
305- echo " Signing bundled libraries (preliminary)..."
306- for fw in " $frameworks_dir " /* .dylib; do
307- [ -f " $fw " ] || continue
308- codesign -fs - --force " $fw " 2> /dev/null || true
309- done
310-
311303 echo " ✅ Bundled $count dynamic libraries into Frameworks/"
312304 ls -lh " $frameworks_dir " /* .dylib 2> /dev/null
313305}
@@ -317,6 +309,9 @@ build_for_arch() {
317309 echo " "
318310 echo " 🔨 Building for $arch ..."
319311
312+ # Fetch build settings once for this arch (used by build_for_arch and bundle_dylibs)
313+ build_settings=$( xcodebuild -project " $PROJECT " -scheme " $SCHEME " -configuration " $CONFIG " -arch " $arch " -showBuildSettings 2>&1 )
314+
320315 # Prepare architecture-specific libraries
321316 prepare_mariadb " $arch "
322317 prepare_libpq " $arch "
@@ -358,7 +353,7 @@ build_for_arch() {
358353 echo " ✅ Build succeeded for $arch "
359354
360355 # Get binary path with validation
361- DERIVED_DATA=$( xcodebuild -project " $PROJECT " -scheme " $SCHEME " -showBuildSettings 2>&1 | grep -m 1 " BUILD_DIR" | awk ' {print $3}' )
356+ DERIVED_DATA=$( echo " $build_settings " | grep -m 1 " BUILD_DIR" | awk ' {print $3}' )
362357
363358 if [ -z " $DERIVED_DATA " ]; then
364359 echo " ❌ FATAL: Failed to determine build directory from xcodebuild settings"
@@ -500,11 +495,18 @@ build_for_arch() {
500495 codesign -fs " $SIGN_IDENTITY " --force --options runtime --timestamp " $dylib "
501496 done
502497
503- # Sign plugin bundles (stripped binaries need re-signing)
498+ # Sign plugin bundles (stripped binaries need re-signing, preserve entitlements )
504499 if [ -d " $PLUGINS_DIR " ]; then
505500 for plugin in " $PLUGINS_DIR " /* .tableplugin; do
506501 [ -d " $plugin " ] || continue
507- codesign -fs " $SIGN_IDENTITY " --force --options runtime --timestamp " $plugin "
502+ local ent_file=" /tmp/plugin_entitlements_$$ .plist"
503+ codesign -d --entitlements - " $plugin " > " $ent_file " 2> /dev/null || true
504+ if [ -s " $ent_file " ]; then
505+ codesign -fs " $SIGN_IDENTITY " --force --options runtime --timestamp --entitlements " $ent_file " " $plugin "
506+ else
507+ codesign -fs " $SIGN_IDENTITY " --force --options runtime --timestamp " $plugin "
508+ fi
509+ rm -f " $ent_file "
508510 done
509511 fi
510512
0 commit comments