Skip to content

Commit 6b1251d

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

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

mesonpy/_rpath.py

Lines changed: 18 additions & 18 deletions
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)

tests/test_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_invalid_build_dir(package_pure, tmp_path, mocker):
330330
project.build()
331331

332332

333-
@pytest.mark.skipif(not os.getenv('CI') or sys.platform != 'win32', reason='Requires MSVC')
333+
@pytest.mark.skipif(not os.getenv('CI') or sys.platform != 'win32', reason='requires MSVC')
334334
def test_compiler(venv, package_detect_compiler, tmp_path):
335335
# Check that things are setup properly to use the MSVC compiler on
336336
# Windows. This effectively means running the compilation step

tests/test_wheel.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_license_pep639(wheel_license_pep639):
158158
'''))
159159

160160

161-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
161+
@pytest.mark.skipif(sys.platform in {'win32', 'cygwin'}, reason='requires RPATH support')
162162
def test_contents(package_library, wheel_library):
163163
artifact = wheel.wheelfile.WheelFile(wheel_library)
164164

@@ -194,12 +194,12 @@ def test_link_library_in_subproject(venv, wheel_link_library_in_subproject):
194194
assert int(output) == 9
195195

196196

197-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
197+
@pytest.mark.skipif(sys.platform in {'win32', 'cygwin'}, reason='requires RPATH support')
198198
def test_rpath(wheel_link_against_local_lib, tmp_path):
199199
artifact = wheel.wheelfile.WheelFile(wheel_link_against_local_lib)
200200
artifact.extractall(tmp_path)
201201

202-
origin = {'linux': '$ORIGIN', 'darwin': '@loader_path', 'sunos5': '$ORIGIN'}[sys.platform]
202+
origin = '@loader_path' if sys.platform == 'darwin' else '$ORIGIN'
203203
expected = {f'{origin}/.link_against_local_lib.mesonpy.libs', 'custom-rpath',}
204204

205205
rpath = set(mesonpy._rpath._get_rpath(tmp_path / f'example{EXT_SUFFIX}'))
@@ -208,19 +208,18 @@ def test_rpath(wheel_link_against_local_lib, tmp_path):
208208
assert rpath >= expected
209209

210210

211-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
211+
@pytest.mark.skipif(sys.platform in {'win32', 'cygwin'}, reason='requires RPATH support')
212212
def test_uneeded_rpath(wheel_purelib_and_platlib, tmp_path):
213213
artifact = wheel.wheelfile.WheelFile(wheel_purelib_and_platlib)
214214
artifact.extractall(tmp_path)
215215

216-
origin = {'linux': '$ORIGIN', 'darwin': '@loader_path', 'sunos5': '$ORIGIN'}[sys.platform]
217-
216+
origin = '@loader_path' if sys.platform == 'darwin' else '$ORIGIN'
218217
rpath = mesonpy._rpath._get_rpath(tmp_path / f'plat{EXT_SUFFIX}')
219218
for path in rpath:
220219
assert origin not in path
221220

222221

223-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
222+
@pytest.mark.skipif(sys.platform in {'win32', 'cygwin'}, reason='requires executable bit support')
224223
def test_executable_bit(wheel_executable_bit):
225224
artifact = wheel.wheelfile.WheelFile(wheel_executable_bit)
226225

0 commit comments

Comments
 (0)