Skip to content
Closed
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
8 changes: 8 additions & 0 deletions mesonbuild/compilers/mixins/visualstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def get_always_args(self) -> T.List[str]:
# TODO: use ImmutableListProtocol[str] here instead
return self.always_args.copy()

def get_compiler_args_for_mode(self, mode: CompileCheckMode) -> T.List[str]:
# Linker always-args are intended for link.exe, which Meson invokes as
# a separate build step. Compiler checks link through cl.exe instead,
# where unwrapped linker options such as /release are compiler errors.
if mode is CompileCheckMode.LINK:
return self.get_always_args()
return super().get_compiler_args_for_mode(mode)

def get_no_stdinc_args(self) -> T.List[str]:
return ['/X']

Expand Down
9 changes: 8 additions & 1 deletion unittests/internaltests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import mesonbuild.scripts.env2mfile
from mesonbuild import coredata
from mesonbuild.compilers.c import ClangCCompiler, GnuCCompiler
from mesonbuild.compilers.compilers import ManyInOneLinkerOptionStyle
from mesonbuild.compilers.compilers import CompileCheckMode, ManyInOneLinkerOptionStyle
from mesonbuild.compilers.cpp import VisualStudioCPPCompiler
from mesonbuild.compilers.d import DmdDCompiler
from mesonbuild.compilers.detect import detect_c_compiler
Expand Down Expand Up @@ -293,6 +293,13 @@ def test_compiler_args_class_visualstudio(self):
a = cc.compiler_args(cc.get_always_args())
self.assertEqual(a.to_native(copy=True), ['/nologo', '/utf-8', '/Zc:__cplusplus'])

# Linker always-args must not leak into cl.exe compiler checks. In
# particular, link.exe accepts /release while cl.exe rejects it.
self.assertEqual(
cc.get_compiler_args_for_mode(CompileCheckMode.LINK),
['/nologo', '/utf-8', '/Zc:__cplusplus'],
)

# Ensure /source-charset: removes /utf-8
a.append('/source-charset:utf-8')
self.assertEqual(a.to_native(copy=True), ['/nologo', '/Zc:__cplusplus', '/source-charset:utf-8'])
Expand Down
Loading