From ee89525b91cf7d4e445dd069efc3d121f566488b Mon Sep 17 00:00:00 2001
From: Mohamed Akram <mohd.akram@outlook.com>
Date: Tue, 21 Apr 2026 22:28:13 +0400
Subject: [PATCH] build: fix install name when linking with static library

A static library can specify a dynamic library in `link_with`.
---
 mesonbuild/build.py                                   |  3 ---
 test cases/darwin/1 rpath removal on install/main.c   |  5 +++++
 .../darwin/1 rpath removal on install/meson.build     | 11 ++++++++++-
 unittests/darwintests.py                              |  8 ++++++++
 4 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 test cases/darwin/1 rpath removal on install/main.c

diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 6986a6c575f9..7cc2dc092000 100644
--- mesonbuild/build.py
+++ mesonbuild/build.py
@@ -2451,9 +2451,6 @@ def determine_default_prefix_and_suffix(self) -> T.Tuple[str, str]:
                         suffix = 'ma'
         return (prefix, suffix)
 
-    def get_link_deps_mapping(self, prefix: str) -> T.Mapping[str, str]:
-        return {}
-
     def get_default_install_dir(self) -> T.Tuple[str, str]:
         return self.environment.get_static_lib_dir(), '{libdir_static}'
 
diff --git a/test cases/darwin/1 rpath removal on install/main.c b/test cases/darwin/1 rpath removal on install/main.c
new file mode 100644
index 000000000000..735a406ce434
--- /dev/null
+++ b/test cases/darwin/1 rpath removal on install/main.c	
@@ -0,0 +1,5 @@
+#include "foo/foo.h"
+
+int main() {
+  foo();
+}
diff --git a/test cases/darwin/1 rpath removal on install/meson.build b/test cases/darwin/1 rpath removal on install/meson.build
index 093d7deba3a8..5ce4c722a42a 100644
--- test cases/darwin/1 rpath removal on install/meson.build	
+++ test cases/darwin/1 rpath removal on install/meson.build	
@@ -5,4 +5,13 @@ subdir('foo')
 bar = library('bar', 'bar.c',
   link_with: foo,
   install: true,
-)
\ No newline at end of file
+)
+
+bar_internal = static_library('bar-internal', 'bar.c',
+  link_with: foo,
+)
+
+main = executable('main', 'main.c',
+  link_with: bar_internal,
+  install: true,
+)
diff --git a/unittests/darwintests.py b/unittests/darwintests.py
index a7345b3c3092..fe292dd5cc1f 100644
--- unittests/darwintests.py
+++ unittests/darwintests.py
@@ -108,6 +108,12 @@ def _get_darwin_rpaths(self, fname: str) -> T.List[str]:
         rpaths = pattern.findall(out)
         return rpaths
 
+    def _get_darwin_rpath_libraries(self, fname: str) -> T.List[str]:
+        out = subprocess.check_output(['otool', '-L', fname], universal_newlines=True)
+        pattern = re.compile(r'@rpath/\S+')
+        libs = pattern.findall(out)
+        return libs
+
     @skipIfNoPkgconfig
     def test_library_versioning(self):
         '''
@@ -174,6 +180,8 @@ def test_darwin_meson_rpaths_removed_on_install(self):
         # Those RPATHs are no longer valid and should not be present after installation
         rpaths = self._get_darwin_rpaths(os.path.join(self.installdir, 'usr/lib/libbar.dylib'))
         self.assertListEqual(rpaths, [])
+        libs = self._get_darwin_rpath_libraries(os.path.join(self.installdir, 'usr/bin/main'))
+        self.assertListEqual(libs, [])
 
     @skip_if_not_language('rust')
     def test_rust_apple_framework_rlib(self):
