fix: rewrite dylib install name on macOS so rpath resolution works

The ACINQ secp256k1-kmp-jni dylib ships with a relative LC_ID_DYLIB
("build/darwin/libsecp256k1-jni.dylib"). macOS dyld resolves this
literally, ignoring the -Wl,-rpath passed at link time, causing an
immediate abort at launch. Using install_name_tool to rewrite the
install name to @rpath/libsecp256k1-jni.dylib lets dyld find the
library via the rpath we already set.

https://claude.ai/code/session_01WSNE6QKiYM2ZutQD2UihCW
This commit is contained in:
Claude
2026-04-09 23:09:17 +00:00
parent 05d59dfde6
commit 8804e243a4
+8
View File
@@ -60,6 +60,14 @@ if [ -z "$SO_FILE" ]; then
fi
cp "$SO_FILE" "$WORK/"
# On macOS the dylib's LC_ID_DYLIB (install name) is a relative path like
# "build/darwin/libsecp256k1-jni.dylib". dyld resolves it literally, ignoring
# -rpath, so the binary fails at launch. Rewrite the install name to use
# @rpath so the -Wl,-rpath we pass to gcc actually works.
if [ "$OS_NAME" = "Darwin" ]; then
install_name_tool -id "@rpath/$SO_NAME" "$WORK/$SO_NAME" 2>/dev/null || true
fi
if ! gcc -O2 -o "$WORK/bench" "$BENCH_DIR/secp256k1_native_bench.c" \
-L"$WORK" -lsecp256k1-jni -Wl,-rpath,"$WORK" 2>&1; then
echo "gcc compilation failed"