Skip to content

Commit 1ac3f34

Browse files
committed
ENH: extend RPATH support to more platforms
Assume all platforms except Windows and macOS use ELF binaries.
1 parent b3358ce commit 1ac3f34

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

mesonpy/_rpath.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,10 @@
1616
from mesonpy._compat import Iterable, Path
1717

1818

19-
if sys.platform == 'linux':
20-
21-
def _get_rpath(filepath: Path) -> List[str]:
22-
r = subprocess.run(['patchelf', '--print-rpath', os.fspath(filepath)], capture_output=True, text=True)
23-
return r.stdout.strip().split(':')
24-
25-
def _set_rpath(filepath: Path, rpath: Iterable[str]) -> None:
26-
subprocess.run(['patchelf','--set-rpath', ':'.join(rpath), os.fspath(filepath)], check=True)
19+
if sys.platform == 'win32' or sys.platform == 'cygwin':
2720

2821
def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
29-
old_rpath = _get_rpath(filepath)
30-
new_rpath = []
31-
for path in old_rpath:
32-
if path.startswith('$ORIGIN/'):
33-
path = '$ORIGIN/' + libs_relative_path
34-
new_rpath.append(path)
35-
if new_rpath != old_rpath:
36-
_set_rpath(filepath, new_rpath)
37-
22+
raise NotImplementedError(f'Bundling libraries in wheel is not supported on {sys.platform}')
3823

3924
elif sys.platform == 'darwin':
4025

@@ -85,6 +70,21 @@ def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
8570
_set_rpath(filepath, new_rpath)
8671

8772
else:
73+
# Assume that any other platform uses ELF binaries.
74+
75+
def _get_rpath(filepath: Path) -> List[str]:
76+
r = subprocess.run(['patchelf', '--print-rpath', os.fspath(filepath)], capture_output=True, text=True)
77+
return r.stdout.strip().split(':')
78+
79+
def _set_rpath(filepath: Path, rpath: Iterable[str]) -> None:
80+
subprocess.run(['patchelf','--set-rpath', ':'.join(rpath), os.fspath(filepath)], check=True)
8881

8982
def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
90-
raise NotImplementedError(f'Bundling libraries in wheel is not supported on {sys.platform}')
83+
old_rpath = _get_rpath(filepath)
84+
new_rpath = []
85+
for path in old_rpath:
86+
if path.startswith('$ORIGIN/'):
87+
path = '$ORIGIN/' + libs_relative_path
88+
new_rpath.append(path)
89+
if new_rpath != old_rpath:
90+
_set_rpath(filepath, new_rpath)

0 commit comments

Comments
 (0)