summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-07-23 10:57:47 -0700
committerDylan Baker <dylan@pnwbakers.com>2025-10-06 09:03:07 -0700
commit8847c938dd1c9e2c6e64e3050eb58f7ec54fccb3 (patch)
treeb8639caacc51a574fc9df438b0af1289fb14a891
parent806289a5d27958a084bc6cba41b7cf9ccee4ecf4 (diff)
downloadmeson-8847c938dd1c9e2c6e64e3050eb58f7ec54fccb3.tar.gz
compilers/asm: Store the C Compiler inside the Assembly Compilers
Such as NASM and MASM. These compilers don't actually do any linking, the just produce object files. As such, we need the C compiler to link the program in order to make things like sanity_check work.
-rw-r--r--mesonbuild/compilers/asm.py23
-rw-r--r--mesonbuild/compilers/detect.py13
2 files changed, 17 insertions, 19 deletions
diff --git a/mesonbuild/compilers/asm.py b/mesonbuild/compilers/asm.py
index 5f065e193..813c87fe6 100644
--- a/mesonbuild/compilers/asm.py
+++ b/mesonbuild/compilers/asm.py
@@ -11,7 +11,6 @@ from .mixins.ti import TICompiler
if T.TYPE_CHECKING:
from ..environment import Environment
- from ..linkers.linkers import DynamicLinker
from ..mesonlib import MachineChoice
from ..envconfig import MachineInfo
@@ -33,12 +32,13 @@ class ASMCompiler(Compiler):
_SUPPORTED_ARCHES: T.Set[str] = set()
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
- for_machine: MachineChoice, info: MachineInfo,
- linker: T.Optional[DynamicLinker] = None,
+ for_machine: 'MachineChoice', info: 'MachineInfo', compiler: Compiler,
full_version: T.Optional[str] = None, is_cross: bool = False):
+ assert compiler.linker is not None, 'for mypy'
if self._SUPPORTED_ARCHES and info.cpu_family not in self._SUPPORTED_ARCHES:
raise EnvironmentException(f'ASM Compiler {self.id} does not support building for {info.cpu_family} CPU family.')
- super().__init__(ccache, exelist, version, for_machine, info, linker, full_version, is_cross)
+ super().__init__(ccache, exelist, version, for_machine, info, compiler.linker, full_version, is_cross)
+ self._compiler = compiler
def _sanity_check_compile_args(self, env: Environment, sourcename: str, binname: str) -> T.List[str]:
return []
@@ -63,10 +63,9 @@ class NasmCompiler(ASMCompiler):
_SUPPORTED_ARCHES = {'x86', 'x86_64'}
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
- for_machine: 'MachineChoice', info: 'MachineInfo',
- linker: T.Optional['DynamicLinker'] = None,
+ for_machine: 'MachineChoice', info: 'MachineInfo', compiler: Compiler,
full_version: T.Optional[str] = None, is_cross: bool = False):
- super().__init__(ccache, exelist, version, for_machine, info, linker, full_version, is_cross)
+ super().__init__(ccache, exelist, version, for_machine, info, compiler, full_version, is_cross)
self.links_with_msvc = False
if 'link' in self.linker.id:
self.base_options.add(OptionKey('b_vscrt'))
@@ -280,10 +279,9 @@ class TILinearAsmCompiler(TICompiler, ASMCompiler):
_SUPPORTED_ARCHES = {'c6000'}
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
- for_machine: MachineChoice, info: MachineInfo,
- linker: T.Optional[DynamicLinker] = None,
+ for_machine: MachineChoice, info: MachineInfo, compiler: Compiler,
full_version: T.Optional[str] = None, is_cross: bool = False):
- ASMCompiler.__init__(self, ccache, exelist, version, for_machine, info, linker, full_version, is_cross)
+ ASMCompiler.__init__(self, ccache, exelist, version, for_machine, info, compiler, full_version, is_cross)
TICompiler.__init__(self)
def needs_static_linker(self) -> bool:
@@ -303,10 +301,9 @@ class MetrowerksAsmCompiler(MetrowerksCompiler, ASMCompiler):
language = 'nasm'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
- for_machine: 'MachineChoice', info: 'MachineInfo',
- linker: T.Optional['DynamicLinker'] = None,
+ for_machine: 'MachineChoice', info: 'MachineInfo', compiler: Compiler,
full_version: T.Optional[str] = None, is_cross: bool = False):
- ASMCompiler.__init__(self, ccache, exelist, version, for_machine, info, linker, full_version, is_cross)
+ ASMCompiler.__init__(self, ccache, exelist, version, for_machine, info, compiler, full_version, is_cross)
MetrowerksCompiler.__init__(self)
self.warn_args: T.Dict[str, T.List[str]] = {
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index a0ae8108d..483a584cb 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -22,6 +22,7 @@ import os
import typing as T
if T.TYPE_CHECKING:
+ from .asm import ASMCompiler
from .compilers import Compiler
from .c import CCompiler
from .cpp import CPPCompiler
@@ -1335,20 +1336,20 @@ def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
if 'NASM' in output:
comp_class = NasmCompiler
env.add_lang_args(comp_class.language, comp_class, for_machine)
- return comp_class([], comp, version, for_machine, info, cc.linker, is_cross=is_cross)
+ return comp_class([], comp, version, for_machine, info, cc, is_cross=is_cross)
elif 'yasm' in output:
comp_class = YasmCompiler
env.add_lang_args(comp_class.language, comp_class, for_machine)
- return comp_class([], comp, version, for_machine, info, cc.linker, is_cross=is_cross)
+ return comp_class([], comp, version, for_machine, info, cc, is_cross=is_cross)
elif 'Metrowerks' in output or 'Freescale' in output:
if 'ARM' in output:
comp_class_mwasmarm = MetrowerksAsmCompilerARM
env.add_lang_args(comp_class_mwasmarm.language, comp_class_mwasmarm, for_machine)
- return comp_class_mwasmarm([], comp, version, for_machine, info, cc.linker, is_cross=is_cross)
+ return comp_class_mwasmarm([], comp, version, for_machine, info, cc, is_cross=is_cross)
else:
comp_class_mwasmeppc = MetrowerksAsmCompilerEmbeddedPowerPC
env.add_lang_args(comp_class_mwasmeppc.language, comp_class_mwasmeppc, for_machine)
- return comp_class_mwasmeppc([], comp, version, for_machine, info, cc.linker, is_cross=is_cross)
+ return comp_class_mwasmeppc([], comp, version, for_machine, info, cc, is_cross=is_cross)
_handle_exceptions(popen_exceptions, compilers)
raise EnvironmentException('Unreachable code (exception to make mypy happy)')
@@ -1364,7 +1365,7 @@ def detect_masm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
info = env.machines[for_machine]
from .asm import MasmCompiler, MasmARMCompiler
- comp_class: T.Type[Compiler]
+ comp_class: T.Type[ASMCompiler]
if info.cpu_family == 'x86':
comp = ['ml']
comp_class = MasmCompiler
@@ -1389,7 +1390,7 @@ def detect_masm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
output = Popen_safe(comp + [arg])[2]
version = search_version(output)
env.add_lang_args(comp_class.language, comp_class, for_machine)
- return comp_class([], comp, version, for_machine, info, cc.linker, is_cross=is_cross)
+ return comp_class([], comp, version, for_machine, info, cc, is_cross=is_cross)
except OSError as e:
popen_exceptions[' '.join(comp + [arg])] = e
_handle_exceptions(popen_exceptions, [comp])