Skip to content

Commit 89518ef

Browse files
Vincent Herbstclaude
andcommitted
fix(demo): embed the dynamic FFmpegBuild frameworks in the demo .app
The demo bundle shipped without the frameworks its binary loads through @rpath, so the 6.5.6 build aborted at launch with "Library not loaded: @rpath/Libavcodec.framework/Versions/A/Libavcodec" (AetherPlayer#2). It was not machine specific: the bundle contained none of them. Those libraries were statically linked once, and the script recorded that as a comment ending "if FFmpegBuild ever switches to dynamic frameworks, this is where they'd be copied to". It since did switch, because LGPL wants them relinkable, and a comment cannot notice that happening. The binary today loads nine frameworks through @rpath. Copy them into Contents/Frameworks, add the matching rpath, sign nested code inside out (signing the .app seals whatever Frameworks/ already holds), and replace the stale note with a check that fails the build when an @rpath dependency is missing from the bundle. Verified against a universal release build: the guard reports 18 unresolved dependencies (nine frameworks across two slices) before embedding and none after, and the resulting bundle launches instead of aborting in dyld. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
1 parent 1d9785b commit 89518ef

1 file changed

Lines changed: 56 additions & 5 deletions

File tree

‎Examples/DemoPlayerMac/Scripts/build-dmg.sh‎

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,51 @@ mkdir -p "$APP_DIR/Contents/Resources"
7979
cp "$BINARY" "$APP_DIR/Contents/MacOS/DemoPlayerMac"
8080
chmod +x "$APP_DIR/Contents/MacOS/DemoPlayerMac"
8181

82-
# FFmpeg / dav1d / etc. are statically linked into the binary (verified
83-
# via `otool -L`, no LC_LOAD_DYLIB entries for the custom frameworks),
84-
# so the .app's Frameworks/ directory stays empty. If FFmpegBuild ever
85-
# switches to dynamic frameworks, this is where they'd be copied to.
82+
# Phase 2b: Embed the FFmpegBuild frameworks the binary links against.
83+
#
84+
# These used to be statically linked, and an earlier revision of this script
85+
# recorded that as a comment saying "if FFmpegBuild ever switches to dynamic
86+
# frameworks, this is where they'd be copied to". It since did (LGPL wants the
87+
# libraries relinkable), and a comment cannot notice that. The shipped 6.5.6
88+
# demo died at launch on a reporter's machine with
89+
# Library not loaded: @rpath/Libavcodec.framework/Versions/A/Libavcodec
90+
# (AetherPlayer#2). So the copy below is followed by a check that actually
91+
# fails the build, rather than a note describing what someone ought to do.
92+
echo " embedding frameworks..."
93+
FW_SRC="$(dirname "$BINARY")"
94+
mkdir -p "$APP_DIR/Contents/Frameworks"
95+
fw_count=0
96+
for fw in "$FW_SRC"/*.framework; do
97+
[ -d "$fw" ] || continue
98+
cp -R "$fw" "$APP_DIR/Contents/Frameworks/"
99+
fw_count=$((fw_count + 1))
100+
done
101+
echo " embedded $fw_count framework(s) from $FW_SRC"
102+
103+
# The binary's own LC_RPATH does not point at Contents/Frameworks, so add it.
104+
# Duplicate entries are harmless but noisy, so only add when absent.
105+
if ! otool -l "$APP_DIR/Contents/MacOS/DemoPlayerMac" | grep -q "@executable_path/../Frameworks"; then
106+
install_name_tool -add_rpath "@executable_path/../Frameworks" \
107+
"$APP_DIR/Contents/MacOS/DemoPlayerMac"
108+
fi
109+
110+
# Guard: every @rpath load command must resolve to something inside the bundle.
111+
# This is the check whose absence shipped a demo that could not launch.
112+
unresolved=0
113+
while read -r dep; do
114+
[ -n "$dep" ] || continue
115+
rel="${dep#@rpath/}"
116+
if [ ! -e "$APP_DIR/Contents/Frameworks/$rel" ]; then
117+
echo " UNRESOLVED: $dep"
118+
unresolved=$((unresolved + 1))
119+
fi
120+
done < <(otool -L "$APP_DIR/Contents/MacOS/DemoPlayerMac" | awk '/@rpath\//{print $1}')
121+
if [ "$unresolved" -gt 0 ]; then
122+
echo "FAIL: $unresolved @rpath dependency/dependencies missing from the bundle." >&2
123+
echo " The .app would die at launch with a dyld 'Library not loaded' abort." >&2
124+
exit 1
125+
fi
126+
echo " all @rpath dependencies resolve inside the bundle"
86127

87128
# Phase 3: Inject Info.plist + Hardened Runtime entitlements.
88129
echo "==> [3/6] Writing Info.plist + entitlements..."
@@ -148,13 +189,23 @@ cat > "$ENTITLEMENTS" <<ENT
148189
ENT
149190

150191
# Phase 4: Code-sign with Hardened Runtime.
192+
# Nested code signs first, inside out: signing the .app seals whatever its
193+
# Frameworks/ already contains, so an unsigned framework there makes the
194+
# --strict verify below fail (and notarization reject the submission).
151195
echo "==> [4/6] Code-signing..."
196+
for fw in "$APP_DIR/Contents/Frameworks"/*.framework; do
197+
[ -d "$fw" ] || continue
198+
codesign --force --options runtime --timestamp \
199+
--sign "$DEVELOPER_ID" \
200+
"$fw"
201+
done
202+
152203
codesign --force --options runtime --timestamp \
153204
--entitlements "$ENTITLEMENTS" \
154205
--sign "$DEVELOPER_ID" \
155206
"$APP_DIR"
156207

157-
codesign --verify --verbose=2 --strict "$APP_DIR"
208+
codesign --verify --verbose=2 --strict --deep "$APP_DIR"
158209

159210
# Phase 5: Notarize (if profile provided).
160211
if [[ -n "$NOTARY_PROFILE" ]]; then

0 commit comments

Comments
 (0)