nasm: Fallback to native compiler when cross compiling

If nasm is not defined in cross file binaries we can fallback to build
machine nasm.

When cross compiling C code we need a different gcc binary for native
and cross targets, e.g. `gcc` and `x86_64-w64-mingw32-gcc`. But when
cross compiling NASM code the compiler is the same, it is the source
code that has to be made for the target platform. We can thus use nasm
from build machine's PATH to cross compile for Windows on Linux for
example. The difference is the arguments Meson will pass when invoking
nasm e.g. `-fwin64`. That is already handled by NasmCompiler class.
pull/13152/head
Xavier Claessens 1 year ago committed by Nirbheek Chauhan
parent e4d2aac988
commit 6a1732a29d
  1. 12
      mesonbuild/compilers/detect.py

@ -115,7 +115,8 @@ def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoic
# Helpers
# =======
def _get_compilers(env: 'Environment', lang: str, for_machine: MachineChoice) -> T.Tuple[T.List[T.List[str]], T.List[str]]:
def _get_compilers(env: 'Environment', lang: str, for_machine: MachineChoice,
allow_build_machine: bool = False) -> T.Tuple[T.List[T.List[str]], T.List[str]]:
'''
The list of compilers is detected in the exact same way for
C, C++, ObjC, ObjC++, Fortran, CS so consolidate it here.
@ -127,7 +128,9 @@ def _get_compilers(env: 'Environment', lang: str, for_machine: MachineChoice) ->
compilers = [comp]
else:
if not env.machines.matches_build_machine(for_machine):
raise EnvironmentException(f'{lang!r} compiler binary not defined in cross or native file')
if allow_build_machine:
return _get_compilers(env, lang, MachineChoice.BUILD)
raise EnvironmentException(f'{lang!r} compiler binary not defined in cross file [binaries] section')
compilers = [[x] for x in defaults[lang]]
ccache = BinaryTable.detect_compiler_cache()
@ -1230,9 +1233,12 @@ def detect_swift_compiler(env: 'Environment', for_machine: MachineChoice) -> Com
def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler:
from .asm import NasmCompiler, YasmCompiler, MetrowerksAsmCompilerARM, MetrowerksAsmCompilerEmbeddedPowerPC
compilers, _ = _get_compilers(env, 'nasm', for_machine)
is_cross = env.is_cross_build(for_machine)
# When cross compiling and nasm is not defined in the cross file we can
# fallback to the build machine nasm.
compilers, _ = _get_compilers(env, 'nasm', for_machine, allow_build_machine=True)
# We need a C compiler to properly detect the machine info and linker
cc = detect_c_compiler(env, for_machine)
if not is_cross:

Loading…
Cancel
Save