Skip to content

Commit 8278018

Browse files
author
skitsanos
committed
fix: Use portable rpath for binary distribution
Embed @executable_path/lib and @executable_path rpaths so the binary finds sherpa-onnx dylibs relative to itself, not hardcoded to the build machine path. Enables portable distribution as: transcribeit (binary) lib/libsherpa-onnx-c-api.dylib lib/libonnxruntime.dylib Linux uses $ORIGIN/lib and $ORIGIN equivalents.
1 parent 9857591 commit 8278018

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

build.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@ fn main() {
1515
path.to_path_buf()
1616
};
1717

18-
// Tell the linker where to find the shared libs
18+
// Tell the linker where to find the shared libs at build time
1919
println!("cargo:rustc-link-search=native={}", absolute.display());
2020

21-
// Embed rpath so the binary finds dylibs at runtime
21+
// Embed rpaths for runtime dylib resolution:
22+
// 1. @executable_path/lib — for portable distribution (dylibs next to binary in lib/)
23+
// 2. @executable_path — for dylibs in the same directory as the binary
24+
// 3. The absolute build-time path — for development convenience
25+
if cfg!(target_os = "macos") {
26+
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/lib");
27+
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path");
28+
} else {
29+
println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/lib");
30+
println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN");
31+
}
32+
// Also keep the build-time path for local development
2233
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", absolute.display());
2334
}
2435

0 commit comments

Comments
 (0)