diff --git a/mesonpy/_rpath.py b/mesonpy/_rpath.py index 084467162..8e2f05be5 100644 --- a/mesonpy/_rpath.py +++ b/mesonpy/_rpath.py @@ -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': 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': @@ -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)