summaryrefslogtreecommitdiff
path: root/mesonbuild/build.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-12-05 09:17:24 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-12-17 14:04:17 -0800
commit4bad7111957bce8f8e751467bdcd7f5e76de04e3 (patch)
tree8ab56aa3ecaa84a4eaca45400cead4a97f0258c4 /mesonbuild/build.py
parenta152da9206891caad17fd9271aff04073e811784 (diff)
downloadmeson-4bad7111957bce8f8e751467bdcd7f5e76de04e3.tar.gz
build: clean up the `link` helper
Splits the subclass specific code into those classes
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r--mesonbuild/build.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index f32010917..7ac169cf4 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1468,15 +1468,6 @@ class BuildTarget(Target):
def link(self, targets: T.List[BuildTargetTypes]) -> None:
for t in targets:
- if isinstance(self, StaticLibrary) and self.install and t.is_internal():
- # When we're a static library and we link_with to an
- # internal/convenience library, promote to link_whole.
- self.link_whole([t], promoted=True)
- continue
- if isinstance(self, SharedLibrary) and isinstance(t, StaticLibrary) and not t.pic:
- msg = f"Can't link non-PIC static library {t.name!r} into shared library {self.name!r}. "
- msg += "Use the 'pic' option to static_library to build with PIC."
- raise InvalidArguments(msg)
self.check_can_link_together(t)
self.link_targets.append(t)
@@ -2346,6 +2337,16 @@ class StaticLibrary(BuildTarget):
self._bundle_static_library(lib, True)
self.link_whole_targets.append(t)
+ def link(self, targets: T.List[BuildTargetTypes]) -> None:
+ for t in targets:
+ if self.install and t.is_internal():
+ # When we're a static library and we link_with to an
+ # internal/convenience library, promote to link_whole.
+ self.link_whole([t], promoted=True)
+ continue
+ self.check_can_link_together(t)
+ self.link_targets.append(t)
+
def _bundle_static_library(self, t: StaticTargetTypes, promoted: bool = False) -> None:
if self.uses_rust():
# Rustc can bundle static libraries, no need to extract objects.
@@ -2684,6 +2685,15 @@ class SharedLibrary(BuildTarget):
raise InvalidArguments(msg)
self.link_whole_targets.append(t)
+ def link(self, targets: T.List[BuildTargetTypes]) -> None:
+ for t in targets:
+ if isinstance(t, StaticLibrary) and not t.pic:
+ msg = f"Can't link non-PIC static library {t.name!r} into shared library {self.name!r}. "
+ msg += "Use the 'pic' option to static_library to build with PIC."
+ raise InvalidArguments(msg)
+ self.check_can_link_together(t)
+ self.link_targets.append(t)
+
# A shared library that is meant to be used with dlopen rather than linking
# into something else.
class SharedModule(SharedLibrary):