Fix native builds on Windows ARM64 machines

I made the mistake of always selecting the debug CRT for compiler
checks on Windows 4 years ago:
https://github.com/mesonbuild/meson/pull/543
https://github.com/mesonbuild/meson/pull/614

The idea was to always build the tests with debugging enabled so that
the compiler doesn't optimize the tests away. But we stopped doing
that a while ago, and also the debug CRT has no relation to that.

We should select the CRT in the same way that we do for building
targets: based on the options.

On Windows ARM64, the debug CRT for ARM64 isn't always available, and
the release CRT is available only after installing the runtime
package. Without this, we will always try to pick the debug CRT even
when --buildtype=debugoptimized or release.
pull/7450/head
Nirbheek Chauhan 4 years ago committed by Nirbheek Chauhan
parent c57616884f
commit 21da2c9040
  1. 3
      mesonbuild/compilers/compilers.py
  2. 3
      mesonbuild/compilers/cuda.py
  3. 12
      mesonbuild/compilers/mixins/clike.py
  4. 3
      mesonbuild/compilers/mixins/islinker.py
  5. 13
      mesonbuild/linkers.py

@ -854,9 +854,6 @@ class Compiler(metaclass=abc.ABCMeta):
def bitcode_args(self) -> T.List[str]: def bitcode_args(self) -> T.List[str]:
return self.linker.bitcode_args() return self.linker.bitcode_args()
def get_linker_debug_crt_args(self) -> T.List[str]:
return self.linker.get_debug_crt_args()
def get_buildtype_linker_args(self, buildtype: str) -> T.List[str]: def get_buildtype_linker_args(self, buildtype: str) -> T.List[str]:
return self.linker.get_buildtype_args(buildtype) return self.linker.get_buildtype_args(buildtype)

@ -263,9 +263,6 @@ class CudaCompiler(Compiler):
def get_depfile_suffix(self): def get_depfile_suffix(self):
return 'd' return 'd'
def get_linker_debug_crt_args(self) -> T.List[str]:
return self._cook_link_args(self.host_compiler.get_linker_debug_crt_args())
def get_buildtype_linker_args(self, buildtype): def get_buildtype_linker_args(self, buildtype):
return self._cook_link_args(self.host_compiler.get_buildtype_linker_args(buildtype)) return self._cook_link_args(self.host_compiler.get_buildtype_linker_args(buildtype))

@ -366,9 +366,17 @@ class CLikeCompiler:
def _get_basic_compiler_args(self, env, mode: str): def _get_basic_compiler_args(self, env, mode: str):
cargs, largs = [], [] cargs, largs = [], []
# Select a CRT if needed since we're linking
if mode == 'link': if mode == 'link':
cargs += self.get_linker_debug_crt_args() # Sometimes we need to manually select the CRT to use with MSVC.
# One example is when trying to do a compiler check that involves
# linking with static libraries since MSVC won't select a CRT for
# us in that case and will error out asking us to pick one.
try:
crt_val = env.coredata.base_options['b_vscrt'].value
buildtype = env.coredata.base_options['buildtype'].value
cargs += self.get_crt_compile_args(crt_val, buildtype)
except (KeyError, AttributeError):
pass
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS and CPPFLAGS from the env # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS and CPPFLAGS from the env
sys_args = env.coredata.get_external_args(self.for_machine, self.language) sys_args = env.coredata.get_external_args(self.for_machine, self.language)

@ -110,9 +110,6 @@ class BasicLinkerIsCompilerMixin:
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]: install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
return ([], set()) return ([], set())
def get_linker_debug_crt_args(self) -> T.List[str]:
return []
def get_asneeded_args(self) -> T.List[str]: def get_asneeded_args(self) -> T.List[str]:
return [] return []

@ -451,9 +451,6 @@ class DynamicLinker(LinkerEnvVarsMixin, metaclass=abc.ABCMeta):
def bitcode_args(self) -> T.List[str]: def bitcode_args(self) -> T.List[str]:
raise mesonlib.MesonException('This linker does not support bitcode bundles') raise mesonlib.MesonException('This linker does not support bitcode bundles')
def get_debug_crt_args(self) -> T.List[str]:
return []
def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str, def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: str, build_rpath: str, rpath_paths: str, build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]: install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
@ -998,16 +995,6 @@ class VisualStudioLikeLinkerMixin:
def invoked_by_compiler(self) -> bool: def invoked_by_compiler(self) -> bool:
return not self.direct return not self.direct
def get_debug_crt_args(self) -> T.List[str]:
"""Arguments needed to select a debug crt for the linker.
Sometimes we need to manually select the CRT (C runtime) to use with
MSVC. One example is when trying to link with static libraries since
MSVC won't auto-select a CRT for us in that case and will error out
asking us to select one.
"""
return self._apply_prefix('/MDd')
def get_output_args(self, outputname: str) -> T.List[str]: def get_output_args(self, outputname: str) -> T.List[str]:
return self._apply_prefix(['/MACHINE:' + self.machine, '/OUT:' + outputname]) return self._apply_prefix(['/MACHINE:' + self.machine, '/OUT:' + outputname])

Loading…
Cancel
Save