From bab108742244bdfde769ea34424a0c0722a460c2 Mon Sep 17 00:00:00 2001 From: Laurin-Luis Lehning <65224843+e820@users.noreply.github.com> Date: Sun, 13 Dec 2020 15:34:50 +0100 Subject: Add support for driving lld-link indirectly through clang on Windows --- mesonbuild/compilers/mixins/clang.py | 8 +++++++- mesonbuild/environment.py | 6 +++++- mesonbuild/linkers.py | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py index acdb352..ab2d066 100644 --- a/mesonbuild/compilers/mixins/clang.py +++ b/mesonbuild/compilers/mixins/clang.py @@ -19,7 +19,7 @@ import shutil import typing as T from ... import mesonlib -from ...linkers import AppleDynamicLinker +from ...linkers import AppleDynamicLinker, ClangClDynamicLinker from ..compilers import CompileCheckMode from .gnu import GnuLikeCompiler @@ -108,6 +108,12 @@ class ClangCompiler(GnuLikeCompiler): else: # Shouldn't work, but it'll be checked explicitly in the OpenMP dependency. return [] + + def get_win_subsystem_args(self, value: str) -> T.List[str]: + if self.info.is_windows() and not self.info.is_cygwin() and isinstance(self.linker, ClangClDynamicLinker): + return [f'-Wl,/subsystem:{value}'] + + return super().get_win_subsystem_args(value) @classmethod def use_linker_args(cls, linker: str) -> T.List[str]: diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index faac0ed..c157bb2 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -940,6 +940,10 @@ class Environment: return LLVMDynamicLinker( compiler, for_machine, comp_class.LINKER_PREFIX, override, version=search_version(o)) + elif not invoked_directly: + return ClangClDynamicLinker( + for_machine, override, exelist=compiler, prefix=comp_class.LINKER_PREFIX, + version=search_version(o), direct=False, machine=None) if value is not None and invoked_directly: compiler = value @@ -1236,7 +1240,7 @@ class Environment: # style ld, but for clang on "real" windows we'll use # either link.exe or lld-link.exe try: - linker = self._guess_win_linker(compiler, cls, for_machine) + linker = self._guess_win_linker(compiler, cls, for_machine, invoked_directly=False) except MesonException: pass if linker is None: diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py index 589945c..967e465 100644 --- a/mesonbuild/linkers.py +++ b/mesonbuild/linkers.py @@ -1164,6 +1164,14 @@ class ClangClDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker): super().__init__(exelist or ['lld-link.exe'], for_machine, prefix, always_args, machine=machine, version=version, direct=direct) + def get_output_args(self, outputname: str) -> T.List[str]: + # If we're being driven indirectly by clang just skip /MACHINE + # as clang's target triple will handle the machine selection + if self.machine is None: + return self._apply_prefix([f"/OUT:{outputname}"]) + + return super().get_output_args(outputname) + class XilinkDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker): -- cgit v1.1