-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
rpath doesn't get set with find_library('foo', dirs:'/path/to/lib') #314
Comments
You can not set rpath yourself for the build dir (you can set an rpath that will be set after 'ninja install'). This is because Meson needs to do some Magic to the object files while they are in the build tree. The established Unix convention is that you should not use rpath for finding public libraries, only for your private ones (like if you have stuff in |
Hi Jussi, This is one area where cmake and meson differ and IMO cmake does the "better thing". By default, cmake will jam in the Meson is the opposite - it doesn't provide the Are there any downsides to the cmake way? I know you mention some "magic". What I'm currently doing is putting in the My other issue is that meson will strip out the Thanks for taking the time to talk about these issues with me! |
The last time I checked, CMake has two properties for rpath. One for build tree and one after install. CMake stores internal dirs in the rpath so binaries can be run directly from the build tree. They are removed upon To set the rpath to be used after install, just set Setting rpath yourself is very much undefined behaviour. It might work. It might not work. It might stop working at any time for any reason. Setting builddir rpath has not been supported for a reason, which is that it is very easy to shoot yourself in the foot with it. At deployment time it can cause wacky stuff that is painful to debug. The simple and reliable ways to do dependencies is to either have a staging dir where you put your stuff (such as If there is need, we could add a new keyword argument such as |
Hi,
Yes, it does. cmake goes one step further and links in
:\
I agree - except I am on a system with a known configuration that must be setup the same way for things to work. In my specific case, the danger of shooting myself in the foot is limited...
The the project I'm working on, this would be pretty perfect. The code would look like:
Agreed, I wish I could avoid shared objects all together, but in this case, I can't. I'll follow up again tomorrow with what I'm seeing cmake do. Thanks! |
Here are the bits from cmake files. top level:
sub folder
And this outputs (during the link phase):
This allows the unit tests to work without any extra work. The rpath gets stripped during install (which is changeable via an option) |
What does it do for libraries obtained via FindPackage or pkg-config? |
The top level
Generates this: I'm not sure about pkg-config. |
Note that this issue makes meson-build binaries efffectively unusable without further wrapping in nixpkgs, since by design nix doesn't install all libraries into a common prefix and instead puts each library in its own prefix. Is there any workaround from the perspective of a package manager maintainer? |
Maintainers can edit the build files and set the For the general case I suppose we would want to set the RPATH when linking to any libraries that aren't already in the linker's search path. This would mean people wouldn't need to manually set I can only see advantages for this, any reason why we shouldn't do this? |
You'd also need to maintain the This would bring parity to that cmake does and would be a very welcome change. |
What would be the implications of this patch: |
That patch would result in the build-time rpaths being kept in the final binary. You can check by looking at the output of |
That patch would result in the build-time rpaths being kept in the final binary; including those created by meson for running binaries uninstalled. You can check by looking at the output of I think we should definitely auto-set RPATH when |
I mean, are there any downsides? Other than more directories to crawl through when loading a library. cc NixOS/nixpkgs#29784 (comment) |
No real downsides (besides affecting build reproducibility), as long as the build directory is truly temporary and will be gone afterwards. |
There is a downside as far as I understand. One could use executable('app', 'main.cpp',
dependencies: [ Xrandr ],
install: true,
install_rpath: '../custom-lib-path',
) With patch @yorickvP proposed that I want(ed) to incorporate in NixOS/nixpkgs#29784, I still believe that with this patch, Meson behavior is much more sane (and no project I've seen in the wild actually uses |
This should be |
I don't remember patches. Leaving the meson build dir in the rpath is a security problem if other people can write to them or change environment variables in them (don't get sanitized by sudo like |
Chiming in a bit late, but regarding:
I'd like to invoke CITATION NEEDED. Everything I've read from knowledgeable sources says that
Typically on gcc you would add non-standard software locations to Edit: and, incidentally, using |
If you have public libraries in non-standard locations (like |
This is not a possibility on NixOS, where every library is stored in its own directory like |
Would there be any disadvantage to doing the following? As I understand it, the whole X business is to ensure the diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 3f088b0f..71a5fe8e 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -834,12 +834,10 @@ class Compiler:
# Build_rpath is used as-is (it is usually absolute).
if build_rpath != '':
paths += ':' + build_rpath
- if len(paths) < len(install_rpath):
- padding = 'X' * (len(install_rpath) - len(paths))
- if not paths:
- paths = padding
- else:
- paths = paths + ':' + padding
+ if not paths:
+ paths = install_rpath
+ else:
+ paths = paths + ':' + install_rpath
args = ['-Wl,-rpath,' + paths]
if get_compiler_is_linuxlike(self):
# Rpaths to use while linking must be absolute. These are not
diff --git a/mesonbuild/scripts/meson_install.py b/mesonbuild/scripts/meson_install.py
index 985b0e94..665f523b 100644
--- a/mesonbuild/scripts/meson_install.py
+++ b/mesonbuild/scripts/meson_install.py
@@ -353,7 +353,6 @@ def install_targets(d):
if is_elf_platform() and os.path.isfile(outname):
try:
e = depfixer.Elf(outname, False)
- e.fix_rpath(install_rpath)
except SystemExit as e:
if isinstance(e.code, int) and e.code == 0:
pass |
The disadvantage would be that it would break everything. The X business is not there to prevent install rpath from being in the build dir, it is to ensure the build dir rpath is not there after an install. The final product must not contain any traces of the build dir. This is a hard, non-negotiable requirement from Linux distros. If rpath on binaries is not perfectly clean, the package will get autorejected. |
By default, meson strips all rpaths, see mesonbuild/meson#314 Remove the stripping (which might leave build rpaths inside installed binaries but at least gives us runnable binaries) until meson fixes this properly. Bump PKGREVISION.
By default, Meson strips RPATH from the executable it builds [1,2]. This will make support/scripts/check-host-rpath fail. So add a patch to prevent RPATH from being stripped. [1] mesonbuild/meson#2567 [2] mesonbuild/meson#314 (comment)
By default, Meson strips RPATH from the executable it builds [1,2], unless explicitly set via install_rpath. This will make support/scripts/check-host-rpath fail when building the host variant of a Meson-based package. So add a patch to prevent RPATH from being stripped if install_rpath is not set and notify user about it. [1] mesonbuild/meson#2567 [2] mesonbuild/meson#314 (comment) Signed-off-by: Eric Le Bihan <eric.le.bihan.dev@free.fr> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries can be run uninstalled without any special steps. These RPATHs will be wiped on install, so they do not affect reproducible builds. De-duping: Fixes #2150 Fixes #2118 RPATHs: Fixes #314 Fixes #2881 Also fixes the uninstalled usage portions of: #3038 #3077
This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries can be run uninstalled without any special steps. These RPATHs will be wiped on install, so they do not affect reproducible builds. De-duping: Fixes #2150 Fixes #2118 RPATHs: Fixes #314 Fixes #2881 Also fixes the uninstalled usage portions of: #3038 #3077
This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries can be run uninstalled without any special steps. These RPATHs will be wiped on install, so they do not affect reproducible builds. De-duping: Fixes #2150 Fixes #2118 RPATHs: Fixes #314 Fixes #2881 Also fixes the uninstalled usage portions of: #3038 #3077
This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries can be run uninstalled without any special steps. These RPATHs will be wiped on install, so they do not affect reproducible builds. De-duping: Fixes #2150 Fixes #2118 Fixes #3071 RPATHs: Fixes #314 Fixes #2881 Also fixes the uninstalled usage portions of: #3038 #3077
This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries can be run uninstalled without any special steps. These RPATHs will be wiped on install, so they do not affect reproducible builds. De-duping: Fixes #2150 Fixes #2118 Fixes #3071 RPATHs: Fixes #314 Fixes #2881 Also fixes the uninstalled usage portions of: #3038 #3077
This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries can be run uninstalled without any special steps. These RPATHs will be wiped on install, so they do not affect reproducible builds. De-duping: Fixes #2150 Fixes #2118 Fixes #3071 RPATHs: Fixes #314 Fixes #2881 Also fixes the uninstalled usage portions of: #3038 #3077
This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries can be run uninstalled without any special steps. These RPATHs will be wiped on install, so they do not affect reproducible builds. De-duping: Fixes #2150 Fixes #2118 Fixes #3071 RPATHs: Fixes #314 Fixes #2881 Also fixes the uninstalled usage portions of: #3038 #3077
By default, Meson strips RPATH from the executable it builds [1,2], unless explicitly set via install_rpath. This will make support/scripts/check-host-rpath fail when building the host variant of a Meson-based package. So add a patch to prevent RPATH from being stripped if install_rpath is not set and notify user about it. [1] mesonbuild/meson#2567 [2] mesonbuild/meson#314 (comment) Signed-off-by: Eric Le Bihan <eric.le.bihan.dev@free.fr> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This allows us to more aggressively de-dup them, and also sets RPATHs to all libraries that are not in the system linker paths so that binaries can be run uninstalled without any special steps. These RPATHs will be wiped on install, so they do not affect reproducible builds. De-duping: Fixes mesonbuild#2150 Fixes mesonbuild#2118 Fixes mesonbuild#3071 RPATHs: Fixes mesonbuild#314 Fixes mesonbuild#2881 Also fixes the uninstalled usage portions of: mesonbuild#3038 mesonbuild#3077
I don't think this is fixed. Here is a reproduction scenario:
|
I'm my pr #4321 i use find_library() with 'dirs:' and the rpath seems to work on Linux but not on Mac OSX. |
Buildroot has had a workaround for over a year now in regards to the fix_rpath on install bug: It seems like a trivial fix to implement, and I am not sure why it hasn't been done yet:
|
@arnout, thank you for the easy to reproduce test case. My attempt at a fix is #7103, now pending review. You can rescue your test case by applying #7103
|
By default, Meson strips RPATH from the executable it builds [1,2], unless explicitly set via install_rpath. This will make support/scripts/check-host-rpath fail when building the host variant of a Meson-based package. So add a patch to prevent RPATH from being stripped if install_rpath is not set and notify user about it. [1] mesonbuild/meson#2567 [2] mesonbuild/meson#314 (comment) Signed-off-by: Eric Le Bihan <eric.le.bihan.dev@free.fr> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Hi Jussi,
If you build a shared object with meson, the rpath get sets correctly (or so the docs say), but when I use find_library() and give it a search path, the rpath doesn't get set. This is causing me lot of pain.
I'm currently doing stuff like this:
Then doing this:
Am I doing it wrong?
The text was updated successfully, but these errors were encountered: