diff --git a/mesonbuild/linkers/detect.py b/mesonbuild/linkers/detect.py index cd3c7b2ef..0dce5ad50 100644 --- a/mesonbuild/linkers/detect.py +++ b/mesonbuild/linkers/detect.py @@ -3,6 +3,7 @@ from __future__ import annotations +from .base import RSPFileSyntax from .. import mlog from ..mesonlib import ( EnvironmentException, @@ -40,6 +41,11 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty from . import linkers env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env) + if invoked_directly or comp_class.get_argument_syntax() == 'msvc': + rsp_syntax = RSPFileSyntax.MSVC + else: + rsp_syntax = RSPFileSyntax.GCC + # Explicitly pass logo here so that we can get the version of link.exe if not use_linker_prefix or comp_class.LINKER_PREFIX is None: check_args = ['/logo', '--version'] @@ -71,7 +77,8 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty elif not invoked_directly: return linkers.ClangClDynamicLinker( for_machine, override, exelist=compiler, prefix=comp_class.LINKER_PREFIX, - version=search_version(o), direct=False, machine=None) + version=search_version(o), direct=False, machine=None, + rsp_syntax=rsp_syntax) if value is not None and invoked_directly: compiler = value @@ -82,7 +89,8 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty return linkers.ClangClDynamicLinker( for_machine, [], prefix=comp_class.LINKER_PREFIX if use_linker_prefix else [], - exelist=compiler, version=search_version(o), direct=invoked_directly) + exelist=compiler, version=search_version(o), direct=invoked_directly, + rsp_syntax=rsp_syntax) elif 'OPTLINK' in o: # Optlink's stdout *may* begin with a \r character. return linkers.OptlinkDynamicLinker(compiler, for_machine, version=search_version(o)) @@ -97,7 +105,8 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty return linkers.MSVCDynamicLinker( for_machine, [], machine=target, exelist=compiler, prefix=comp_class.LINKER_PREFIX if use_linker_prefix else [], - version=search_version(out), direct=invoked_directly) + version=search_version(out), direct=invoked_directly, + rsp_syntax=rsp_syntax) elif 'GNU coreutils' in o: import shutil fullpath = shutil.which(compiler[0]) diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index c3750ccc3..18157a36b 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -1274,11 +1274,13 @@ class VisualStudioLikeLinkerMixin(DynamicLinkerBase): def __init__(self, exelist: T.List[str], for_machine: mesonlib.MachineChoice, prefix_arg: T.Union[str, T.List[str]], always_args: T.List[str], *, - version: str = 'unknown version', direct: bool = True, machine: str = 'x86'): + version: str = 'unknown version', direct: bool = True, machine: str = 'x86', + rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC): # There's no way I can find to make mypy understand what's going on here super().__init__(exelist, for_machine, prefix_arg, always_args, version=version) self.machine = machine self.direct = direct + self.rsp_syntax = rsp_syntax def invoked_by_compiler(self) -> bool: return not self.direct @@ -1322,7 +1324,7 @@ class VisualStudioLikeLinkerMixin(DynamicLinkerBase): return self._apply_prefix(['/IMPLIB:' + implibname]) def rsp_file_syntax(self) -> RSPFileSyntax: - return RSPFileSyntax.MSVC + return self.rsp_syntax class MSVCDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker): @@ -1335,9 +1337,10 @@ class MSVCDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker): exelist: T.Optional[T.List[str]] = None, prefix: T.Union[str, T.List[str]] = '', machine: str = 'x86', version: str = 'unknown version', - direct: bool = True): + direct: bool = True, rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC): super().__init__(exelist or ['link.exe'], for_machine, - prefix, always_args, machine=machine, version=version, direct=direct) + prefix, always_args, machine=machine, version=version, direct=direct, + rsp_syntax=rsp_syntax) def get_always_args(self) -> T.List[str]: return self._apply_prefix(['/release']) + super().get_always_args() @@ -1359,9 +1362,10 @@ class ClangClDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker): exelist: T.Optional[T.List[str]] = None, prefix: T.Union[str, T.List[str]] = '', machine: str = 'x86', version: str = 'unknown version', - direct: bool = True): + direct: bool = True, rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC): super().__init__(exelist or ['lld-link.exe'], for_machine, - prefix, always_args, machine=machine, version=version, direct=direct) + prefix, always_args, machine=machine, version=version, direct=direct, + rsp_syntax=rsp_syntax) def get_output_args(self, outputname: str) -> T.List[str]: # If we're being driven indirectly by clang just skip /MACHINE