summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/compilers.py9
-rw-r--r--mesonbuild/compilers/mixins/clang.py12
-rw-r--r--mesonbuild/compilers/mixins/gnu.py15
-rw-r--r--mesonbuild/compilers/mixins/islinker.py4
-rw-r--r--mesonbuild/compilers/mixins/visualstudio.py9
-rw-r--r--mesonbuild/compilers/rust.py7
6 files changed, 32 insertions, 24 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 79044f74c..2d813eb9b 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -279,6 +279,7 @@ def get_base_compile_args(target: 'BuildTarget', compiler: 'Compiler', env: 'Env
num_threads = get_option_value_for_target(env, target, OptionKey('b_lto_threads'), 0)
ltomode = get_option_value_for_target(env, target, OptionKey('b_lto_mode'), 'default')
args.extend(compiler.get_lto_compile_args(
+ target=target,
threads=num_threads,
mode=ltomode))
lto = True
@@ -357,6 +358,7 @@ def get_base_link_args(target: 'BuildTarget',
num_threads = get_option_value_for_target(env, target, OptionKey('b_lto_threads'), 0)
lto_mode = get_option_value_for_target(env, target, OptionKey('b_lto_mode'), 'default')
args.extend(linker.get_lto_link_args(
+ target=target,
threads=num_threads,
mode=lto_mode,
thinlto_cache_dir=thinlto_cache_dir))
@@ -1043,11 +1045,12 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def get_embed_bitcode_args(self, bitcode: bool, lto: bool) -> T.List[str]:
return []
- def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
+ def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default') -> T.List[str]:
return []
- def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
- thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
+ def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
return self.linker.get_lto_args()
def get_lto_obj_cache_path(self, path: str) -> T.List[str]:
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index a6e644bd0..851b22f0a 100644
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -20,6 +20,7 @@ from .gnu import GnuLikeCompiler
if T.TYPE_CHECKING:
from ...options import MutableKeyedOptionDictType
from ...dependencies import Dependency # noqa: F401
+ from ...build import BuildTarget
from ..compilers import Compiler
CompilerMixinBase = Compiler
@@ -211,7 +212,8 @@ class ClangCompiler(GnuLikeCompiler):
def get_embed_bitcode_args(self, bitcode: bool, lto: bool) -> T.List[str]:
return ['-fembed-bitcode'] if bitcode else []
- def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
+ def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default') -> T.List[str]:
args: T.List[str] = []
if mode == 'thin':
# ThinLTO requires the use of gold, lld, ld64, lld-link or mold 1.1+
@@ -224,7 +226,7 @@ class ClangCompiler(GnuLikeCompiler):
args.append(f'-flto={mode}')
else:
assert mode == 'default', 'someone forgot to wire something up'
- args.extend(super().get_lto_compile_args(threads=threads))
+ args.extend(super().get_lto_compile_args(target=target, threads=threads))
return args
def linker_to_compiler_args(self, args: T.List[str]) -> T.List[str]:
@@ -233,9 +235,9 @@ class ClangCompiler(GnuLikeCompiler):
else:
return args
- def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
- thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
- args = self.get_lto_compile_args(threads=threads, mode=mode)
+ def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
+ args = self.get_lto_compile_args(target=target, threads=threads, mode=mode)
if mode == 'thin' and thinlto_cache_dir is not None:
# We check for ThinLTO linker support above in get_lto_compile_args, and all of them support
# get_thinlto_cache_args as well
diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py
index ede47203c..7e783e229 100644
--- a/mesonbuild/compilers/mixins/gnu.py
+++ b/mesonbuild/compilers/mixins/gnu.py
@@ -481,7 +481,8 @@ class GnuLikeCompiler(Compiler, metaclass=abc.ABCMeta):
return self._split_fetch_real_dirs(line.split('=', 1)[1])
return []
- def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
+ def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default') -> T.List[str]:
# This provides a base for many compilers, GCC and Clang override this
# for their specific arguments
return ['-flto']
@@ -612,8 +613,8 @@ class GnuCompiler(GnuLikeCompiler):
def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]:
return [prelink_name], ['-r', '-o', prelink_name] + obj_list
- def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default',
- thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
+ def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
args: T.List[str] = []
if threads == 0:
@@ -626,7 +627,7 @@ class GnuCompiler(GnuLikeCompiler):
elif threads > 0:
args.append(f'-flto={threads}')
else:
- args.extend(super().get_lto_compile_args(threads=threads))
+ args.extend(super().get_lto_compile_args(target=target, threads=threads))
if thinlto_cache_dir is not None:
# We check for ThinLTO linker support above in get_lto_compile_args, and all of them support
@@ -646,10 +647,10 @@ class GnuCompiler(GnuLikeCompiler):
return ['-fuse-ld=mold']
return super().use_linker_args(linker, version)
- def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
- thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
+ def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
args: T.List[str] = []
- args.extend(self.get_lto_compile_args(threads=threads, thinlto_cache_dir=thinlto_cache_dir))
+ args.extend(self.get_lto_compile_args(target=target, threads=threads, thinlto_cache_dir=thinlto_cache_dir))
return args
def get_profile_use_args(self) -> T.List[str]:
diff --git a/mesonbuild/compilers/mixins/islinker.py b/mesonbuild/compilers/mixins/islinker.py
index 4106f76cc..1c0361918 100644
--- a/mesonbuild/compilers/mixins/islinker.py
+++ b/mesonbuild/compilers/mixins/islinker.py
@@ -40,8 +40,8 @@ class BasicLinkerIsCompilerMixin(Compiler):
def sanitizer_link_args(self, target: BuildTarget, value: T.List[str]) -> T.List[str]:
return []
- def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
- thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
+ def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
return []
def can_linker_accept_rsp(self) -> bool:
diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py
index 88a842d9c..1a4311460 100644
--- a/mesonbuild/compilers/mixins/visualstudio.py
+++ b/mesonbuild/compilers/mixins/visualstudio.py
@@ -492,7 +492,8 @@ class ClangClCompiler(VisualStudioLikeCompiler):
raise mesonlib.MesonBugException('Could not find libomp')
return super().openmp_link_flags() + libs
- def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
+ def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default') -> T.List[str]:
args: T.List[str] = []
if mode == 'thin':
# LTO data generated by clang-cl is only usable by lld-link
@@ -501,11 +502,11 @@ class ClangClCompiler(VisualStudioLikeCompiler):
args.append(f'-flto={mode}')
else:
assert mode == 'default', 'someone forgot to wire something up'
- args.extend(super().get_lto_compile_args(threads=threads))
+ args.extend(super().get_lto_compile_args(target=target, threads=threads))
return args
- def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
- thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
+ def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
args = []
if mode == 'thin' and thinlto_cache_dir is not None:
args.extend(self.linker.get_thinlto_cache_args(thinlto_cache_dir))
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index 4088b5ca9..b09522f37 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -365,13 +365,14 @@ class RustCompiler(Compiler):
else:
return ['-C', 'embed-bitcode=no']
- def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
+ def get_lto_compile_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default') -> T.List[str]:
# TODO: what about -Clinker-plugin-lto?
rustc_lto = 'lto=thin' if mode == 'thin' else 'lto'
return ['-C', rustc_lto]
- def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
- thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
+ def get_lto_link_args(self, *, target: T.Optional[BuildTarget] = None, threads: int = 0,
+ mode: str = 'default', thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
# no need to specify anything because the rustc command line
# includes the result of get_lto_compile_args()
return []