aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/development/tools/build-managers/meson/fix-rpath.patch
blob: d34b6c4c43457a11ff358fead3b8fe950584a93a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -456,6 +456,21 @@ class Backend:
                 args.extend(self.environment.coredata.get_external_link_args(target.for_machine, lang))
             except Exception:
                 pass
+
+        nix_ldflags = os.environ.get('NIX_LDFLAGS', '').split()
+        next_is_path = False
+        # Try to add rpaths set by user or ld-wrapper so that they are not removed.
+        # Based on https://github.com/NixOS/nixpkgs/blob/69711a2f5ffe8cda208163be5258266172ff527f/pkgs/build-support/bintools-wrapper/ld-wrapper.sh#L148-L177
+        for flag in nix_ldflags:
+            if flag == '-rpath' or flag == '-L':
+                next_is_path = True
+            elif next_is_path or flag.startswith('-L/'):
+                if flag.startswith('-L/'):
+                    flag = flag[2:]
+                if flag.startswith('@storeDir@'):
+                    dirs.add(flag)
+                next_is_path = False
+
         # Match rpath formats:
         # -Wl,-rpath=
         # -Wl,-rpath,