Skip to content

Commit

Permalink
BUG: fix all RPATHs that start with $ORIGIN
Browse files Browse the repository at this point in the history
When shared libraries are build in a project subdir or in a
subproject, the RAPTH added by meson pointing to the shared library
build directory is not just '$ORIGIN/' but a longer relative path.

Apply the same fix to all RPATHs that start with '$ORING/'.

Fixes #509.
  • Loading branch information
metab0t authored and dnicolodi committed Oct 5, 2023
1 parent 36e8205 commit edf8ba2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
18 changes: 11 additions & 7 deletions mesonpy/_rpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ def _set_rpath(filepath: Path, rpath: Iterable[str]) -> None:
subprocess.run(['patchelf','--set-rpath', ':'.join(rpath), os.fspath(filepath)], check=True)

def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
rpath = _get_rpath(filepath)
if '$ORIGIN/' in rpath:
rpath = [('$ORIGIN/' + libs_relative_path if path == '$ORIGIN/' else path) for path in rpath]
_set_rpath(filepath, rpath)
old_rpath = _get_rpath(filepath)
new_rpath = []
for path in old_rpath:
if path.startswith('$ORIGIN/'):
path = '$ORIGIN/' + libs_relative_path
new_rpath.append(path)
if new_rpath != old_rpath:
_set_rpath(filepath, new_rpath)


elif sys.platform == 'darwin':
Expand All @@ -50,9 +54,9 @@ def _replace_rpath(filepath: Path, old: str, new: str) -> None:
subprocess.run(['install_name_tool', '-rpath', old, new, os.fspath(filepath)], check=True)

def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
rpath = _get_rpath(filepath)
if '@loader_path/' in rpath:
_replace_rpath(filepath, '@loader_path/', '@loader_path/' + libs_relative_path)
for path in _get_rpath(filepath):
if path.startswith('@loader_path/'):
_replace_rpath(filepath, path, '@loader_path/' + libs_relative_path)

else:

Expand Down
2 changes: 1 addition & 1 deletion tests/packages/link-against-local-lib/examplemod.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <Python.h>

#include "examplelib.h"
#include "lib/examplelib.h"

static PyObject* example_sum(PyObject* self, PyObject *args)
{
Expand Down
9 changes: 9 additions & 0 deletions tests/packages/link-against-local-lib/lib/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: 2022 The meson-python developers
#
# SPDX-License-Identifier: MIT

example_lib = shared_library(
'example',
'examplelib.c',
install: true,
)
6 changes: 1 addition & 5 deletions tests/packages/link-against-local-lib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

project('link-against-local-lib', 'c', version: '1.0.0')

example_lib = shared_library(
'example',
'examplelib.c',
install: true,
)
subdir('lib')

py = import('python').find_installation()

Expand Down

0 comments on commit edf8ba2

Please sign in to comment.