Debian Codegraph @

mesonbuild/compilers/mixins/islinker.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2019 The Meson development team
3 # Copyright © 2023 Intel Corporation
4
5 from __future__ import annotations
6
7 """Mixins for compilers that *are* linkers.
8
9 While many compilers (such as gcc and clang) are used by meson to dispatch
10 linker commands and other (like MSVC) are not, a few (such as DMD) actually
11 are both the linker and compiler in one binary. This module provides mixin
12 classes for those cases.
13 """
14
15 import typing as T
16
17 from ...mesonlib import EnvironmentException, MesonException, is_windows
18
19 if T.TYPE_CHECKING:
20 from ...compilers.compilers import Compiler
21 from ...build import BuildTarget
22 from ...options import OptionStore
23 else:
24 # This is a bit clever, for mypy we pretend that these mixins descend from
25 # Compiler, so we get all of the methods and attributes defined for us, but
26 # for runtime we make them descend from object (which all classes normally
27 # do). This gives up DRYer type checking, with no runtime impact
28 Compiler = object
29
30
31 class BasicLinkerIsCompilerMixin(Compiler):
32
33 """Provides a baseline of methods that a linker would implement.
34
35 In every case this provides a "no" or "empty" answer. If a compiler
36 implements any of these it needs a different mixin or to override that
37 functionality itself.
38 """
39
40 def sanitizer_link_args(self, target: BuildTarget, value: T.List[str]) -> T.List[str]:
41 return []
42
43 def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
44 mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
45 return []
46
47 def can_linker_accept_rsp(self) -> bool:
48 return is_windows()
49
50 def get_linker_exelist(self) -> T.List[str]:
51 return self.exelist.copy()
52
53 def get_linker_output_args(self, outputname: str) -> T.List[str]:
54 return []
55
56 def get_linker_always_args(self) -> T.List[str]:
57 return []
58
59 def get_linker_lib_prefix(self) -> str:
60 return ''
61
62 def get_option_link_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]:
63 return []
64
65 def has_multi_link_args(self, args: T.List[str]) -> T.Tuple[bool, bool]:
66 return False, False
67
68 def get_link_debugfile_args(self, targetfile: str) -> T.List[str]:
69 return []
70
71 def get_std_shared_lib_link_args(self) -> T.List[str]:
72 return []
73
74 def get_std_shared_module_args(self, options: OptionStore) -> T.List[str]:
75 return self.get_std_shared_lib_link_args()
76
77 def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
78 raise EnvironmentException(f'Linker {self.id} does not support link_whole')
79
80 def get_allow_undefined_link_args(self) -> T.List[str]:
81 raise EnvironmentException(f'Linker {self.id} does not support allow undefined')
82
83 def get_pie_link_args(self) -> T.List[str]:
84 raise EnvironmentException(f'Linker {self.id} does not support position-independent executable')
85
86 def get_undefined_link_args(self) -> T.List[str]:
87 return []
88
89 def get_coverage_link_args(self) -> T.List[str]:
90 return []
91
92 def no_undefined_link_args(self) -> T.List[str]:
93 return []
94
95 def bitcode_args(self) -> T.List[str]:
96 raise MesonException("This linker doesn't support bitcode bundles")
97
98 def get_soname_args(self, prefix: str, shlib_name: str,
99 suffix: str, soversion: str,
100 darwin_versions: T.Tuple[str, str]) -> T.List[str]:
101 raise MesonException("This linker doesn't support soname args")
102
103 def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
104 extra_paths: T.Optional[T.List[str]] = None
105 ) -> T.Tuple[T.List[str], T.Set[bytes]]:
106 return ([], set())
107
108 def get_asneeded_args(self) -> T.List[str]:
109 return []
110
111 def get_optimization_link_args(self, optimization_level: str) -> T.List[str]:
112 return []
113
114 def get_linker_fatal_warnings(self) -> T.List[str]:
115 return []
116
117 def get_link_debugfile_name(self, targetfile: str) -> T.Optional[str]:
118 return None
119
120 def thread_flags(self) -> T.List[str]:
121 return []
122
123 def thread_link_flags(self) -> T.List[str]:
124 return []