Skip to content

Commit

Permalink
ENH: extend RPATH support to more platforms
Browse files Browse the repository at this point in the history
Assume all platforms except Windows and macOS use ELF binaries.
  • Loading branch information
dnicolodi committed Dec 9, 2023
1 parent 9d0fa13 commit 62dd141
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions mesonpy/_rpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,10 @@
from mesonpy._compat import Iterable, Path


if sys.platform == 'linux':

def _get_rpath(filepath: Path) -> List[str]:
r = subprocess.run(['patchelf', '--print-rpath', os.fspath(filepath)], capture_output=True, text=True)
return r.stdout.strip().split(':')

def _set_rpath(filepath: Path, rpath: Iterable[str]) -> None:
subprocess.run(['patchelf','--set-rpath', ':'.join(rpath), os.fspath(filepath)], check=True)
if sys.platform == 'win32' or sys.platform == 'cygwin':

def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
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)

raise NotImplementedError(f'Bundling libraries in wheel is not supported on {sys.platform}')

elif sys.platform == 'darwin':

Expand All @@ -59,6 +44,21 @@ def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
_replace_rpath(filepath, path, '@loader_path/' + libs_relative_path)

else:
# Assume that any other platform uses ELF binaries.

def _get_rpath(filepath: Path) -> List[str]:
r = subprocess.run(['patchelf', '--print-rpath', os.fspath(filepath)], capture_output=True, text=True)
return r.stdout.strip().split(':')

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:
raise NotImplementedError(f'Bundling libraries in wheel is not supported on {sys.platform}')
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)

0 comments on commit 62dd141

Please sign in to comment.