I can think of a few ways that might help to address this. Keep in mind that these will need to be adjusted to your setup and use-case.
- If you construct `LD_LIBRARY_PATH` at runtime, e.g. in a test script, then you can include `$PWD` to construct an absolute `LD_LIBRARY_PATH` that takes different execroot paths on different machines into account. E.g.
```
LD_LIBRARY_PATH="$PWD/<relative_path>"
```
This assumes that `<relative_path>` is valid within the Bazel execroot.
- When you fetch external binaries you can use [patchelf](
https://github.com/NixOS/patchelf) to patch their `RUNPATH` or needed entries. E.g.
```
RELPATH=$(realpath --relative-to=$(dirname <output-file>) <libdir>)
patchelf --set-rpath "\$ORIGIN/$RELPATH:<other_rpath_entries>"
```
The value `$ORIGIN` tells the dynamic loader to search relative to the binary, see `ld(1)`.
- Use [Nix](
https://nixos.org/nix/) and [rules_nixpkgs](
https://github.com/tweag/rules_nixpkgs) to pin all external dependencies including system libraries and tools instead of fetching external binaries using `http_archive`. In that case Nix would install external tools under paths like `/nix/store/<hash>-mytool` which would be the same across (similar) machines (paths would differ between, e.g., Linux and macOS).
I hope that helps.
Best, Andreas