aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2023-06-08 08:13:40 -0400
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2024-04-26 23:09:30 +0530
commit6a1732a29d315aeef2d0a81394b2846c97df42c0 (patch)
tree76ec2633731eb70d1e4c595e01dba141efcd9436 /mesonbuild
parente4d2aac988925d1f7b8eae762ec24f6af63569df (diff)
downloadmeson-6a1732a29d315aeef2d0a81394b2846c97df42c0.zip
meson-6a1732a29d315aeef2d0a81394b2846c97df42c0.tar.gz
meson-6a1732a29d315aeef2d0a81394b2846c97df42c0.tar.bz2
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.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/compilers/detect.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index dade204..0872728 100644
--- a/mesonbuild/compilers/detect.py
+++ b/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: