Skip to content

Commit 3c3bcf5

Browse files
committed
BUG: do not remove RPATH entries relative to $ORIGIN
for packages using internal shared libraries relocated by meson-python.
1 parent 91fe153 commit 3c3bcf5

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

mesonpy/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,6 @@ def _install_path(self, wheel_file: mesonpy._wheelfile.WheelFile, origin: Path,
427427

428428
if self._has_internal_libs:
429429
if _is_native(origin):
430-
# When an executable, libray, or Python extension module is
431-
# dynamically linked to a library built as part of the project,
432-
# Meson adds a library load path to it pointing to the build
433-
# directory, in the form of a relative RPATH entry. meson-python
434-
# relocates the shared libraries to the $project.mesonpy.libs
435-
# folder. Rewrite the RPATH to point to that folder instead.
436430
libspath = os.path.relpath(self._libs_dir, destination.parent)
437431
mesonpy._rpath.fix_rpath(origin, libspath)
438432

mesonpy/_rpath.py

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

tests/test_wheel.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ def test_link_against_local_lib_rpath(wheel_link_against_local_lib, tmp_path):
235235

236236
origin = '@loader_path' if sys.platform == 'darwin' else '$ORIGIN'
237237
expected = {f'{origin}/../.link_against_local_lib.mesonpy.libs', 'custom-rpath',}
238+
# This RPATH entry should be removed by meson-python but it is not.
239+
expected.add(f'{origin}/lib')
238240

239241
rpath = set(mesonpy._rpath.get_rpath(tmp_path / 'example' / f'_example{EXT_SUFFIX}'))
240242
assert rpath == expected
@@ -251,10 +253,6 @@ def test_link_against_local_lib_rpath_ldflags(package_link_against_local_lib, tm
251253
artifact = wheel.wheelfile.WheelFile(tmp_path / filename)
252254
artifact.extractall(tmp_path)
253255

254-
# The RPATH entry relative to $ORIGIN added via $LDFLAGS is
255-
# erroneusly stripped by meson-python.
256-
extra_rpath = {'/usr/lib/test-ldflags',}
257-
258256
rpath = set(mesonpy._rpath.get_rpath(tmp_path / 'example' / f'_example{EXT_SUFFIX}'))
259257
assert extra_rpath <= rpath
260258

0 commit comments

Comments
 (0)