@@ -39,11 +39,21 @@ def set_rpath(filepath: Path, old: List[str], rpath: List[str]) -> None:
3939 @classmethod
4040 def fix_rpath (cls , filepath : Path , libs_relative_path : str ) -> None :
4141 old_rpath = cls .get_rpath (filepath )
42- new_rpath = []
43- for path in old_rpath :
44- if path .startswith (cls .origin ):
45- path = os .path .join (cls .origin , libs_relative_path )
46- new_rpath .append (path )
42+ new_rpath = old_rpath [:]
43+
44+ # When an executable, libray, or Python extension module is
45+ # dynamically linked to a library built as part of the project, Meson
46+ # adds a build RPATH pointing to the build directory, in the form of a
47+ # relative RPATH entry. We can use the presence of any RPATH entries
48+ # relative to ``$ORIGIN`` as an indicator that the installed object
49+ # depends on shared libraries internal to the project. In this case we
50+ # need to add an RPATH entry pointing to the meson-python shared
51+ # library install location. This heuristic is not perfect: RPATH
52+ # entries relative to ``$ORIGIN`` can exist for other reasons.
53+ # However, this only results in harmless additional RPATH entries.
54+ if any (path .startswith (cls .origin ) for path in old_rpath ):
55+ new_rpath .append (os .path .join (cls .origin , libs_relative_path ))
56+
4757 new_rpath = unique (new_rpath )
4858 if new_rpath != old_rpath :
4959 cls .set_rpath (filepath , old_rpath , new_rpath )
0 commit comments