@@ -199,6 +199,22 @@ def test_sharedlib_in_package_rpath(wheel_sharedlib_in_package, tmp_path):
199199 assert rpath == set ()
200200
201201
202+ @pytest .mark .skipif (sys .platform in {'win32' , 'cygwin' }, reason = 'requires RPATH support' )
203+ def test_sharedlib_in_package_rpath_ldflags (package_sharedlib_in_package , tmp_path , monkeypatch ):
204+ origin = '@loader_path' if sys .platform == 'darwin' else '$ORIGIN'
205+ extra_rpath = {f'{ origin } /test-ldflags' , '/usr/lib/test-ldflags' }
206+ ldflags = ' ' .join (f'-Wl,-rpath,{ p } ' for p in extra_rpath )
207+ monkeypatch .setenv ('LDFLAGS' , ldflags )
208+
209+ filename = mesonpy .build_wheel (tmp_path )
210+ artifact = wheel .wheelfile .WheelFile (tmp_path / filename )
211+ artifact .extractall (tmp_path )
212+
213+ for path in f'_example{ EXT_SUFFIX } ' , f'liblib{ LIB_SUFFIX } ' , f'sub/libsublib{ LIB_SUFFIX } ' :
214+ rpath = set (mesonpy ._rpath ._get_rpath (tmp_path / 'mypkg' / path ))
215+ assert extra_rpath <= rpath
216+
217+
202218def test_sharedlib_in_package (venv , wheel_sharedlib_in_package ):
203219 venv .pip ('install' , wheel_sharedlib_in_package )
204220 output = venv .python ('-c' , 'import mypkg; print(mypkg.prodsum(2, 3, 4))' )
@@ -224,6 +240,25 @@ def test_link_against_local_lib_rpath(wheel_link_against_local_lib, tmp_path):
224240 assert rpath == expected
225241
226242
243+ @pytest .mark .skipif (sys .platform in {'win32' , 'cygwin' }, reason = 'requires RPATH support' )
244+ def test_link_against_local_lib_rpath_ldflags (package_link_against_local_lib , tmp_path ):
245+ origin = '@loader_path' if sys .platform == 'darwin' else '$ORIGIN'
246+ extra_rpath = {f'{ origin } /test-ldflags' , '/usr/lib/test-ldflags' }
247+ ldflags = ' ' .join (f'-Wl,-rpath,{ p } ' for p in extra_rpath )
248+ monkeypatch .setenv ('LDFLAGS' , ldflags )
249+
250+ filename = mesonpy .build_wheel (tmp_path )
251+ artifact = wheel .wheelfile .WheelFile (tmp_path / filename )
252+ artifact .extractall (tmp_path )
253+
254+ # The RPATH entry relative to $ORIGIN added via $LDFLAGS is
255+ # erroneusly stripped by meson-python.
256+ extra_rpath = {'/usr/lib/test-ldflags' ,}
257+
258+ rpath = set (mesonpy ._rpath ._get_rpath (tmp_path / 'example' / f'_example{ EXT_SUFFIX } ' ))
259+ assert extra_rpath <= rpath
260+
261+
227262@pytest .mark .skipif (sys .platform in {'win32' , 'cygwin' }, reason = 'requires RPATH support' )
228263def test_uneeded_rpath (wheel_purelib_and_platlib , tmp_path ):
229264 artifact = wheel .wheelfile .WheelFile (wheel_purelib_and_platlib )
0 commit comments