yams/scripts/macos-rpath-install-names.sh
trvon 545f461ae1
build(macos): keep libyams_onnx_resource @rpath-relative after install
Meson rewrites the install name of installed dylibs to their absolute
install path and points consumers at it, so the staged macOS payload
referenced /opt/homebrew/lib/yams/libyams_onnx_resource.dylib: yams-cli
from an unzipped release archive (or a staging dir) died in dyld
("Library not loaded ... no such file"), and Homebrew depended on its
prefix symlinks to resolve it.

A darwin-only Meson install script (scripts/macos-rpath-install-names.sh,
tag runtime) restores @rpath/libyams_onnx_resource.dylib as the library
id and in yams-cli/yams-daemon and the plugins, which already carry
@executable_path/../lib/yams and @loader_path/.. RPATHs.

Verified on macOS arm64 (ONNX + Glint release build): otool -L shows
@rpath/libyams_onnx_resource.dylib; a `zip -ry` archive of the stage
unzipped to an unrelated directory runs `yams --version`, codesign -v
passes, and the Glint plugin dlopens from there.

Signed-off-by: trvon <me@trevon.dev>
2026-10-01 20:29:46 -06:00

30 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Meson install script (macOS): keep YAMS's private dylibs @rpath-relative.
#
# macos-rpath-install-names.sh <libdir>
#
# Meson rewrites the install name of every installed shared library to its
# absolute install path (e.g. /opt/homebrew/lib/yams/libyams_onnx_resource.dylib)
# and points consumers at that path, so a staged or unzipped tree only runs from
# its final prefix. The executables already carry @executable_path/../lib/yams
# and the plugins @loader_path/.. RPATHs; restore the @rpath install name so
# those RPATHs are what resolves the library.
set -euo pipefail
libdir="${1:?usage: $0 <libdir>}"
root="${MESON_INSTALL_DESTDIR_PREFIX:?run from meson install}"
lib="$root/$libdir/yams/libyams_onnx_resource.dylib"
[ -f "$lib" ] || exit 0
new_id="@rpath/libyams_onnx_resource.dylib"
old_id="$(otool -D "$lib" | tail -n 1)"
if [ "$old_id" != "$new_id" ]; then
install_name_tool -id "$new_id" "$lib"
fi
for f in "$root"/bin/* "$root/$libdir"/yams/plugins/*.dylib "$root/$libdir"/yams/plugins/*.so; do
[ -f "$f" ] && [ ! -L "$f" ] || continue
if otool -L "$f" 2>/dev/null | grep -qF "$old_id "; then
install_name_tool -change "$old_id" "$new_id" "$f"
fi
done