Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson strips rpaths set via pkgconfig on install #4027

Closed
dankegel opened this issue Aug 14, 2018 · 9 comments · Fixed by #7103
Closed

Meson strips rpaths set via pkgconfig on install #4027

dankegel opened this issue Aug 14, 2018 · 9 comments · Fixed by #7103

Comments

@dankegel
Copy link
Contributor

dankegel commented Aug 14, 2018

If a .pc file specifies -Wl,-rpath, it probably has a good reason to.
Thus it is surprising that meson strips those rpaths on install.
The workaround suggested by #1411
is awkward as it requires knowing what rpath the library needed.
[Edit: and it requires editing the meson config, which is awkward when
you're just trying to package, say, gstreamer to install to /opt/foo.
What's the point of meson's --prefix option if it forbids rpaths pointing into that prefix?]

Since rpath in .pc files are frowned upon in linux distributions, this is likely to only
affect third-party software that installs libraries to /opt.

If meson is making a policy statement that .pc files must not contain rpath options, it should say so clearly, and possibly abort when such .pc files are encountered

@barcharcraz
Copy link
Contributor

This issue affects SWI Prolog from Fedora 28 main repositories.

@nirbheek
Copy link
Member

Instead of stripping all RPATHs set, we could strip only the values that point to the builddir and sourcedir. I have no objections to this, since all other build systems seem to allow it, but it requires @jpakkane's approval.

@michaelkuhn
Copy link
Contributor

Meson's rpath stripping also impacts Spack (see spack/spack#10463). Spack sets rpaths for all dependencies on purpose but Meson removes them all on install. It would be nice to be able to tell Meson to leave the rpaths alone.

@dankegel
Copy link
Contributor Author

dankegel commented Apr 11, 2019

The original bug about rpath appears to be #314, which was closed after fixing some build rpath issues (but not the install rpath issues).

There are a number of related issue reports. One that gets referenced a lot is #2567.
It has some discussion explaining the philosophy of meson authors, pushing back on the request a bit.
github's "this bug was referenced in" links in that bug magically show the
hack that several projects use to just turn off meson's rpath stripping until a solution is found.

A really nice issue report for a very related issue on MacOS is #3077, which was fixed by 96b7fdb
That fix appears thorough, and has tests that are skipped on linux but which
could be enabled if the present bug (#4027) were fixed.

Also, if the wider issue is "meson does not support pkgconfig workflow with non-standard prefixes",
there is a corresponding problem at .pc generation time. Consider a third-party open source library that provides a .pc file. When a developer who maintains an ecosystem that lives in /opt/foo wants to add that library to her ecosystem, the generated .pc file should have the appropriate rpath injected into its .pc file... without having to patch the call to pkg.generate. (One could imagine meson offering a global option to inject that -Wl,-rpath option into generated .pc files. pkg.generate magically noticing that the library is installing into a non-system prefix, and injecting the option itself, might be even easier if there were a reliable way to do that.)

@dankegel
Copy link
Contributor Author

The workaround I'm trying now is:

e.g. in my debian/rules, I have

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
LDFLAGS:=-Wl,-rpath,$(PREFIX)/lib/$(DEB_HOST_MULTIARCH),-rpath,$(PREFIX)/lib
export LDFLAGS

Finners crossed.

@dankegel
Copy link
Contributor Author

dankegel commented Apr 25, 2019

Turns out I really do also need to inject an rpath into the .pc file as I mentioned earlier, so on Linux I'm also trying:

--- gstreamer-1.16.0/pkgconfig/gstreamer.pc.in.old      2019-04-25 11:29:08.385748960 -0700
+++ gstreamer-1.16.0/pkgconfig/gstreamer.pc.in  2019-04-25 11:30:09.201693902 -0700
@@ -14,5 +14,5 @@
 Version: @VERSION@
 Requires: glib-2.0, gobject-2.0
 Requires.private: gmodule-no-export-2.0 @UNWIND_REQUIRE@ @DW_REQUIRE@
-Libs: -L${libdir} -lgstreamer-@GST_API_VERSION@
+Libs: -L${libdir} -lgstreamer-@GST_API_VERSION@ -Wl,-rpath,${libdir}
 Cflags: -I${includedir}

because I don't have time for a proper kludge.

@dankegel
Copy link
Contributor Author

dankegel commented Aug 6, 2019

I enabled the test case in question in a branch:
https://github.com/dankegel/meson/commits/bug4027-enable-test-case

./run_unittests.py -v -s test_usage_external_library demonstrates the problem.

Applying https://raw.githubusercontent.com/MontaVista-OpenSourceTechnology/poky/f705787a07f1043d9143516cb3b9775fd758107d/meta/recipes-devtools/meson/meson/disable-rpath-handling.patch rescues it.

I'm still trying to figure out if that workaround is enough here.

thibauthourlier added a commit to thibauthourlier/linuxbrew-core that referenced this issue Aug 23, 2019
By default meson will remove all RPATH data when installing software
The patch the formula is fetching has been provided for fixing
mesonbuild/meson#4027 which is similar to
the problem linuxbrew is having as it doesn't install software in
the normal path.
The patch is adding a test before modifying RPATH:
- if install_rpath is set, modify RPATH to install_rpath
- otherwise, keep existing RPATH
dankegel pushed a commit to dankegel/meson that referenced this issue May 3, 2020
@dankegel
Copy link
Contributor Author

dankegel commented May 3, 2020

Had a moment to write a draft fix and clean test for this use case, and extend an older related test case.
See https://github.com/dankegel/meson/commits/bug4027-rpath-friendly
It's just a WIP, and doesn't address more interesting use cases yet.

dankegel pushed a commit to dankegel/meson that referenced this issue May 3, 2020
dankegel pushed a commit to dankegel/meson that referenced this issue May 4, 2020
dankegel added a commit to dankegel/meson that referenced this issue May 12, 2020
dankegel added a commit to dankegel/meson that referenced this issue May 16, 2020
dankegel added a commit to dankegel/meson that referenced this issue May 16, 2020
dankegel added a commit to dankegel/meson that referenced this issue May 16, 2020
@dankegel
Copy link
Contributor Author

ivoanjo added a commit to DataDog/libddprof that referenced this issue Feb 21, 2022
The `ddprof_ffi_with_rpath.pc` includes the linker flags
`-Wl,-rpath,${libdir}` so that libddprof can be linked to and used in
the directory it gets installed to.

Without this, we would need to set the same flags in the libddprof user
side, or use `LD_LIBRARY_PATH` or some other mean to tell the OS how
to find libddprof.

These two links helped me figure this out:
* https://amir.rachum.com/blog/2016/09/17/shared-libraries/
* mesonbuild/meson#4027

Also included is a change to `ffi-build.sh` so that the macOS dynamic
library is setup to correctly being used with rpath.
ivoanjo added a commit to DataDog/libddprof that referenced this issue Feb 22, 2022
… macOS (#26)

* Upgrade to latest version of `standard` gem

* Cleanup old versions from Rakefile

We don't support using an up-to-date `Rakefile` to release a version
other than the current in `version.rb` so it doesn't make sense to
keep old versions around.

* Avoid packaging a few more useless files

* Refactor `Rakefile` to avoid repetition, add experimental support for macOS

* Add mechanism to exclude some libddprof tarball files from package

* Package libddprof shared library only, ignore static library

This is still WIP, since the 0.3.0 release doesn't actually
ship a shared library.

* Code reformatter fixes

* Tweak experimental macOS packaging

* Add pkg-config variant that sets rpath

The `ddprof_ffi_with_rpath.pc` includes the linker flags
`-Wl,-rpath,${libdir}` so that libddprof can be linked to and used in
the directory it gets installed to.

Without this, we would need to set the same flags in the libddprof user
side, or use `LD_LIBRARY_PATH` or some other mean to tell the OS how
to find libddprof.

These two links helped me figure this out:
* https://amir.rachum.com/blog/2016/09/17/shared-libraries/
* mesonbuild/meson#4027

Also included is a change to `ffi-build.sh` so that the macOS dynamic
library is setup to correctly being used with rpath.
r1viollet pushed a commit to DataDog/libdatadog that referenced this issue May 5, 2022
… macOS (#26)

* Upgrade to latest version of `standard` gem

* Cleanup old versions from Rakefile

We don't support using an up-to-date `Rakefile` to release a version
other than the current in `version.rb` so it doesn't make sense to
keep old versions around.

* Avoid packaging a few more useless files

* Refactor `Rakefile` to avoid repetition, add experimental support for macOS

* Add mechanism to exclude some libddprof tarball files from package

* Package libddprof shared library only, ignore static library

This is still WIP, since the 0.3.0 release doesn't actually
ship a shared library.

* Code reformatter fixes

* Tweak experimental macOS packaging

* Add pkg-config variant that sets rpath

The `ddprof_ffi_with_rpath.pc` includes the linker flags
`-Wl,-rpath,${libdir}` so that libddprof can be linked to and used in
the directory it gets installed to.

Without this, we would need to set the same flags in the libddprof user
side, or use `LD_LIBRARY_PATH` or some other mean to tell the OS how
to find libddprof.

These two links helped me figure this out:
* https://amir.rachum.com/blog/2016/09/17/shared-libraries/
* mesonbuild/meson#4027

Also included is a change to `ffi-build.sh` so that the macOS dynamic
library is setup to correctly being used with rpath.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants