Skip to content

Commit 4f58b70

Browse files
committed
FIX: bundle macOS dylibs recursively to any depth, setting install names and re-signing every nested library (fluidsynth pulls portaudio, glib and friends)
1 parent e525e0d commit 4f58b70

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

.github/workflows/nightly.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,38 @@ jobs:
172172
;;
173173
esac
174174
}
175+
bundle_lib() {
176+
# Recursively bundle the non-system dependencies of an already-copied lib/ dylib
177+
libfile="$1"
178+
bin_rpaths="$2"
179+
lrpaths=$(list_rpaths "$libfile")
180+
ldeps=$(otool -L "$libfile" | awk 'NR>1 {print $1}')
181+
while read -r ldep; do
182+
case "$ldep" in
183+
/usr/lib/*|/System/*|@loader_path/*|@executable_path/*|"") continue ;;
184+
esac
185+
lreal=$(resolve_dep "$ldep" $lrpaths $bin_rpaths) || {
186+
echo "::error::Cannot resolve dependency $ldep of $libfile"
187+
exit 1
188+
}
189+
lbase=$(basename "$lreal")
190+
if [[ ! -f "lib/$lbase" ]]; then
191+
cp -L "$lreal" "lib/$lbase"
192+
install_name_tool -id "@loader_path/$lbase" "lib/$lbase"
193+
codesign --force --sign - "lib/$lbase"
194+
bundle_lib "lib/$lbase" "$bin_rpaths"
195+
fi
196+
install_name_tool -change "$ldep" "@loader_path/$lbase" "$libfile"
197+
done <<< "$ldeps"
198+
codesign --force --sign - "$libfile"
199+
}
175200
bundle_binary() {
176201
bin="$1"
177202
rpaths=$(list_rpaths "$bin")
178203
deps=$(otool -L "$bin" | awk 'NR>1 {print $1}')
179204
while read -r dep; do
180205
case "$dep" in
181-
/usr/lib/*|/System/*|"") continue ;;
206+
/usr/lib/*|/System/*|@loader_path/*|@executable_path/*|"") continue ;;
182207
esac
183208
real=$(resolve_dep "$dep" $rpaths) || {
184209
echo "::error::Cannot resolve dependency $dep of $bin"
@@ -187,22 +212,9 @@ jobs:
187212
base=$(basename "$real")
188213
if [[ ! -f "lib/$base" ]]; then
189214
cp -L "$real" "lib/$base"
190-
dylib_rpaths=$(list_rpaths "lib/$base")
191-
ndeps=$(otool -L "lib/$base" | awk 'NR>1 {print $1}')
192-
while read -r ndep; do
193-
case "$ndep" in
194-
/usr/lib/*|/System/*|"") continue ;;
195-
esac
196-
nreal=$(resolve_dep "$ndep" $dylib_rpaths $rpaths) || {
197-
echo "::error::Cannot resolve dependency $ndep of $base"
198-
exit 1
199-
}
200-
nbase=$(basename "$nreal")
201-
[[ -f "lib/$nbase" ]] || cp -L "$nreal" "lib/$nbase"
202-
install_name_tool -change "$ndep" "@loader_path/$nbase" "lib/$base"
203-
done <<< "$ndeps"
204215
install_name_tool -id "@loader_path/$base" "lib/$base"
205216
codesign --force --sign - "lib/$base"
217+
bundle_lib "lib/$base" "$rpaths"
206218
fi
207219
install_name_tool -change "$dep" "@executable_path/lib/$base" "$bin"
208220
done <<< "$deps"
@@ -213,7 +225,7 @@ jobs:
213225
for bin in simutrans-extended simutrans-extended-server makeobj-extended nettool-extended; do
214226
bundle_binary "$bin"
215227
done
216-
# Verification: no binary may reference Homebrew paths or unresolved @rpath entries
228+
# Verification: no bundled file may reference Homebrew paths or unresolved @rpath entries
217229
for bin in simutrans-extended simutrans-extended-server makeobj-extended nettool-extended lib/*; do
218230
[[ -f "$bin" ]] || continue
219231
if otool -L "$bin" | awk 'NR>1 {print $1}' | grep -qE '^(@rpath/|/opt/homebrew/|/usr/local/)'; then

0 commit comments

Comments
 (0)