|
2 | 2 | //! |
3 | 3 | //! Emits RPATH linker flags so binaries can find dynamic libraries |
4 | 4 | //! at runtime without setting `LD_LIBRARY_PATH`/`DYLD_LIBRARY_PATH`. |
5 | | -
|
| 5 | +//! |
| 6 | +//! Two layouts are supported: |
| 7 | +//! |
| 8 | +//! - **Vendored** (default): dynamic libs are copied into |
| 9 | +//! `fdb_libs/` and `eccodes_libs/` subdirectories next to the |
| 10 | +//! final binary. The rpath entries are binary-relative |
| 11 | +//! (`@executable_path/fdb_libs` on macOS, `$ORIGIN/fdb_libs` on |
| 12 | +//! Linux), so the binary is portable as long as the user ships |
| 13 | +//! those two directories alongside it. |
| 14 | +//! |
| 15 | +//! - **System**: libraries live wherever `find_package` resolved |
| 16 | +//! them (e.g. `/usr/lib`, `/opt/.../lib`, or a custom prefix). |
| 17 | +//! `fdb-sys`'s build script re-publishes each dependency's lib dir |
| 18 | +//! via `cargo:system_*_lib` metadata keys, and we emit an |
| 19 | +//! absolute rpath entry for each one so the binary still loads |
| 20 | +//! without `LD_LIBRARY_PATH` / `DYLD_LIBRARY_PATH`. |
6 | 21 | fn main() { |
7 | 22 | println!("cargo:rerun-if-changed=build.rs"); |
8 | 23 | bindman_utils::emit_rpath_flags(&["fdb_libs", "eccodes_libs"]); |
| 24 | + |
| 25 | + // When fdb-sys is in system mode, it re-publishes each |
| 26 | + // dependency's install lib dir so we can stamp matching |
| 27 | + // absolute rpath entries onto the final binary. The vendored |
| 28 | + // build leaves these unset, so this block is a no-op there. |
| 29 | + for key in [ |
| 30 | + "DEP_FDB_SYS_SYSTEM_FDB5_LIB", |
| 31 | + "DEP_FDB_SYS_SYSTEM_ECKIT_LIB", |
| 32 | + "DEP_FDB_SYS_SYSTEM_METKIT_LIB", |
| 33 | + "DEP_FDB_SYS_SYSTEM_ECCODES_LIB", |
| 34 | + ] { |
| 35 | + println!("cargo:rerun-if-env-changed={key}"); |
| 36 | + if let Ok(lib_dir) = std::env::var(key) { |
| 37 | + println!("cargo:rustc-link-arg=-Wl,-rpath,{lib_dir}"); |
| 38 | + } |
| 39 | + } |
9 | 40 | } |
0 commit comments