Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -1043,11 +1045,12 @@ def remove_linkerlike_args(self, args: T.List[str]) -> T.List[str]:
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]:
Expand Down
12 changes: 7 additions & 5 deletions mesonbuild/compilers/mixins/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
if T.TYPE_CHECKING:
from ...options import MutableKeyedOptionDictType
from ...dependencies import Dependency # noqa: F401
from ...build import BuildTarget
from ..compilers import Compiler

CompilerMixinBase = Compiler
Expand Down Expand Up @@ -211,7 +212,8 @@ def get_coverage_link_args(self) -> T.List[str]:
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+
Expand All @@ -224,7 +226,7 @@ def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.
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]:
Expand All @@ -233,9 +235,9 @@ def linker_to_compiler_args(self, args: T.List[str]) -> T.List[str]:
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
Expand Down
15 changes: 8 additions & 7 deletions mesonbuild/compilers/mixins/gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ def get_compiler_dirs(self, name: str) -> T.List[str]:
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']
Expand Down Expand Up @@ -612,8 +613,8 @@ def get_has_func_attribute_extra_args(self, name: str) -> T.List[str]:
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:
Expand All @@ -626,7 +627,7 @@ def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default',
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
Expand All @@ -646,10 +647,10 @@ def use_linker_args(cls, linker: str, version: str) -> T.List[str]:
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]:
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/mixins/islinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions mesonbuild/compilers/mixins/visualstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ def openmp_link_flags(self) -> T.List[str]:
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
Expand All @@ -501,11 +502,11 @@ def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.
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))
Expand Down
10 changes: 7 additions & 3 deletions mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,17 @@ def get_embed_bitcode_args(self, bitcode: bool, lto: bool) -> T.List[str]:
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]:
if target.rust_crate_type in {'dylib', 'proc-macro'}:
return []

# 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 []
Expand Down
Loading