Skip to content

Commit 8ffb668

Browse files
committed
fix: sign Mach-O files in isolated temp dir to bypass bundle detection
codesign detects bundles by examining parent directory structure (Versions/, Resources/, Info.plist) via CFBundle internals — not just the directory name or extension. Renaming .framework dirs doesn't help. New approach: copy each Mach-O to an isolated temp dir before signing, then copy back. The code signature is embedded in the Mach-O binary's LC_CODE_SIGNATURE load command and is path-independent, so it survives the copy back to the original location. Also adds otool -L debug output to determine if Python.framework is actually needed at runtime.
1 parent 2c7b8ce commit 8ffb668

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

src-tauri/before_build.sh

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,39 +59,35 @@ find "$BACKEND_DIST" -path "*/Python.framework/*" -exec ls -la {} \; 2>/dev/null
5959

6060
# 5. On macOS, codesign all binaries for notarization.
6161
# cp -RL dereferences symlinks, which breaks .framework bundle structure.
62-
# codesign auto-detects *.framework/Name paths as bundles and rejects them.
63-
# Workaround: temporarily rename .framework dirs so codesign treats every
64-
# Mach-O as a standalone file, then restore the names for runtime.
62+
# codesign auto-detects bundles by examining parent dir structure (Versions/,
63+
# Resources/, Info.plist) via CFBundle — not just the directory name.
64+
# Workaround: copy each Mach-O to an isolated temp dir for signing, then
65+
# copy back. The signature is embedded in the Mach-O LC_CODE_SIGNATURE
66+
# load command and is path-independent.
6567
if [[ "$TARGET_TRIPLE" == *"apple"* ]]; then
6668
ENTITLEMENTS="$PROJECT_ROOT/src-tauri/entitlements.plist"
6769
SIGN_IDENTITY="${APPLE_SIGNING_IDENTITY:--}"
70+
SIGN_TMPDIR=$(mktemp -d)
6871
echo "Codesigning PyInstaller onedir output (identity: $SIGN_IDENTITY)..."
6972

70-
# a) Temporarily rename .framework dirs to prevent codesign bundle detection.
71-
# codesign detects bundles when a dir has ANY dot-extension and contains a
72-
# binary matching the dir stem (e.g. Python.*/Python). Removing the dot
73-
# entirely prevents this heuristic from triggering.
74-
# Process deepest paths first (sort -r) to avoid renaming parents before children.
75-
find "$BACKEND_DIST" -type d -name "*.framework" | sort -r | while read -r fw; do
76-
mv "$fw" "${fw%.framework}_framework_tmp"
77-
done
78-
79-
# b) Sign all Mach-O files (except the main executable) individually.
73+
# a) Sign all Mach-O files (except the main executable) individually.
74+
# Each file is copied to an isolated temp dir so codesign cannot
75+
# detect surrounding bundle structure and trigger bundle signing.
8076
find "$BACKEND_DIST" -type f ! -name "syft-space-backend" | while read -r f; do
8177
if file "$f" | grep -q "Mach-O"; then
78+
TMPFILE="$SIGN_TMPDIR/$(basename "$f")"
79+
cp "$f" "$TMPFILE"
8280
codesign --force --options runtime --entitlements "$ENTITLEMENTS" \
83-
--sign "$SIGN_IDENTITY" "$f"
81+
--sign "$SIGN_IDENTITY" "$TMPFILE"
82+
cp "$TMPFILE" "$f"
83+
rm "$TMPFILE"
8484
fi
8585
done
8686

87-
# c) Restore .framework dir names.
88-
find "$BACKEND_DIST" -type d -name "*_framework_tmp" | sort -r | while read -r fw; do
89-
mv "$fw" "${fw%_framework_tmp}.framework"
90-
done
91-
92-
# d) Sign the main executable last
87+
# b) Sign the main executable last (not inside a bundle, signs directly)
9388
codesign --force --options runtime --entitlements "$ENTITLEMENTS" \
9489
--sign "$SIGN_IDENTITY" "$BACKEND_DIST/syft-space-backend${EXE_EXT}"
90+
rm -rf "$SIGN_TMPDIR"
9591
echo "Codesigning complete."
9692

9793
# Debug: verify signatures on the previously-problematic files
@@ -107,6 +103,11 @@ if [[ "$TARGET_TRIPLE" == *"apple"* ]]; then
107103
codesign --verify --strict "$f" 2>&1 || true
108104
fi
109105
done
106+
107+
# Debug: show what the bootloader links against (helps determine if
108+
# Python.framework is needed at runtime or can be removed in the future)
109+
echo "=== Bootloader library dependencies ==="
110+
otool -L "$BACKEND_DIST/syft-space-backend" 2>&1 | head -20
110111
fi
111112

112113
# 6. Build frontend

0 commit comments

Comments
 (0)