summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/asm.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-09-25 13:50:46 -0700
committerDylan Baker <dylan@pnwbakers.com>2025-10-29 07:57:26 -0700
commitdd2ccaa751894b1f7f6dcbd0913a18cc57693feb (patch)
tree3d57b384a7d4761b0f018561fa5fa0382e1335c0 /mesonbuild/compilers/asm.py
parente0637066cf2bdc697ecee6fa382f6f00cda1c276 (diff)
downloadmeson-dd2ccaa751894b1f7f6dcbd0913a18cc57693feb.tar.gz
compilers/asm: Move arch support check to initializer
It really isn't a sanity check that a specific compiler doesn't work on a specific platform. This re-implements the check as a shared component in the ASMCompiler base class, which has the advantage of code sharing.
Diffstat (limited to 'mesonbuild/compilers/asm.py')
-rw-r--r--mesonbuild/compilers/asm.py47
1 files changed, 22 insertions, 25 deletions
diff --git a/mesonbuild/compilers/asm.py b/mesonbuild/compilers/asm.py
index d0bea57ec..fd6a0de33 100644
--- a/mesonbuild/compilers/asm.py
+++ b/mesonbuild/compilers/asm.py
@@ -11,10 +11,10 @@ from .mixins.metrowerks import MetrowerksCompiler, mwasmarm_instruction_set_args
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
+ from ..environment import Environment
nasm_optimization_args: T.Dict[str, T.List[str]] = {
'plain': [],
@@ -31,6 +31,19 @@ class ASMCompiler(Compiler):
"""Shared base class for all ASM Compilers (Assemblers)"""
+ _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,
+ full_version: T.Optional[str] = None, is_cross: bool = False):
+ 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)
+
+ def sanity_check(self, work_dir: str, environment: Environment) -> None:
+ return None
+
class NasmCompiler(ASMCompiler):
language = 'nasm'
@@ -45,6 +58,8 @@ class NasmCompiler(ASMCompiler):
'mtd': ['/DEFAULTLIB:libucrtd.lib', '/DEFAULTLIB:libvcruntimed.lib', '/DEFAULTLIB:libcmtd.lib'],
}
+ _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,
@@ -100,10 +115,6 @@ class NasmCompiler(ASMCompiler):
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
return ['-MD', outfile, '-MQ', outtarget]
- def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
- if self.info.cpu_family not in {'x86', 'x86_64'}:
- raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
-
def get_pic_args(self) -> T.List[str]:
return []
@@ -160,6 +171,8 @@ class MasmCompiler(ASMCompiler):
language = 'masm'
id = 'ml'
+ _SUPPORTED_ARCHES = {'x86', 'x86_64'}
+
def get_compile_only_args(self) -> T.List[str]:
return ['/c']
@@ -187,10 +200,6 @@ class MasmCompiler(ASMCompiler):
return ['/Zi']
return []
- def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
- if self.info.cpu_family not in {'x86', 'x86_64'}:
- raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
-
def get_pic_args(self) -> T.List[str]:
return []
@@ -217,6 +226,7 @@ class MasmCompiler(ASMCompiler):
class MasmARMCompiler(ASMCompiler):
language = 'masm'
id = 'armasm'
+ _SUPPORTED_ARCHES = {'arm', 'aarch64'}
def needs_static_linker(self) -> bool:
return True
@@ -238,10 +248,6 @@ class MasmARMCompiler(ASMCompiler):
return ['-g']
return []
- def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
- if self.info.cpu_family not in {'arm', 'aarch64'}:
- raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
-
def get_pic_args(self) -> T.List[str]:
return []
@@ -267,6 +273,7 @@ class MasmARMCompiler(ASMCompiler):
# https://downloads.ti.com/docs/esd/SPRUI04/
class TILinearAsmCompiler(TICompiler, ASMCompiler):
language = 'linearasm'
+ _SUPPORTED_ARCHES = {'c6000'}
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
for_machine: MachineChoice, info: MachineInfo,
@@ -284,10 +291,6 @@ class TILinearAsmCompiler(TICompiler, ASMCompiler):
def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]:
return []
- def sanity_check(self, work_dir: str, environment: Environment) -> None:
- if self.info.cpu_family not in {'c6000'}:
- raise EnvironmentException(f'TI Linear ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
-
def get_depfile_suffix(self) -> str:
return 'd'
@@ -325,21 +328,15 @@ class MetrowerksAsmCompiler(MetrowerksCompiler, ASMCompiler):
class MetrowerksAsmCompilerARM(MetrowerksAsmCompiler):
id = 'mwasmarm'
+ _SUPPORTED_ARCHES = {'arm'}
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:
return mwasmarm_instruction_set_args.get(instruction_set, None)
- def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
- if self.info.cpu_family not in {'arm'}:
- raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
-
class MetrowerksAsmCompilerEmbeddedPowerPC(MetrowerksAsmCompiler):
id = 'mwasmeppc'
+ _SUPPORTED_ARCHES = {'ppc'}
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:
return mwasmeppc_instruction_set_args.get(instruction_set, None)
-
- def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
- if self.info.cpu_family not in {'ppc'}:
- raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')