Skip to content

Commit 8cc9c68

Browse files
committed
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.
1 parent e385874 commit 8cc9c68

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

mesonbuild/compilers/asm.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from .mixins.ti import TICompiler
1212

1313
if T.TYPE_CHECKING:
14-
from ..environment import Environment
1514
from ..linkers.linkers import DynamicLinker
1615
from ..mesonlib import MachineChoice
1716
from ..envconfig import MachineInfo
17+
from ..environment import Environment
1818

1919
nasm_optimization_args: T.Dict[str, T.List[str]] = {
2020
'plain': [],
@@ -31,6 +31,19 @@ class ASMCompiler(Compiler):
3131

3232
"""Shared base class for all ASM Compilers (Assemblers)"""
3333

34+
_SUPPORTED_ARCHES: T.Set[str] = set()
35+
36+
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
37+
for_machine: MachineChoice, info: MachineInfo,
38+
linker: T.Optional[DynamicLinker] = None,
39+
full_version: T.Optional[str] = None, is_cross: bool = False):
40+
if self._SUPPORTED_ARCHES and info.cpu_family not in self._SUPPORTED_ARCHES:
41+
raise EnvironmentException(f'ASM Compiler {self.id} does not support building for {info.cpu_family} CPU family.')
42+
super().__init__(ccache, exelist, version, for_machine, info, linker, full_version, is_cross)
43+
44+
def sanity_check(self, work_dir: str, environment: Environment) -> None:
45+
return None
46+
3447

3548
class NasmCompiler(ASMCompiler):
3649
language = 'nasm'
@@ -45,6 +58,8 @@ class NasmCompiler(ASMCompiler):
4558
'mtd': ['/DEFAULTLIB:libucrtd.lib', '/DEFAULTLIB:libvcruntimed.lib', '/DEFAULTLIB:libcmtd.lib'],
4659
}
4760

61+
_SUPPORTED_ARCHES = {'x86', 'x86_64'}
62+
4863
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
4964
for_machine: 'MachineChoice', info: 'MachineInfo',
5065
linker: T.Optional['DynamicLinker'] = None,
@@ -100,10 +115,6 @@ def get_depfile_suffix(self) -> str:
100115
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
101116
return ['-MD', outfile, '-MQ', outtarget]
102117

103-
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
104-
if self.info.cpu_family not in {'x86', 'x86_64'}:
105-
raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
106-
107118
def get_pic_args(self) -> T.List[str]:
108119
return []
109120

@@ -160,6 +171,8 @@ class MasmCompiler(ASMCompiler):
160171
language = 'masm'
161172
id = 'ml'
162173

174+
_SUPPORTED_ARCHES = {'x86', 'x86_64'}
175+
163176
def get_compile_only_args(self) -> T.List[str]:
164177
return ['/c']
165178

@@ -187,10 +200,6 @@ def get_debug_args(self, is_debug: bool) -> T.List[str]:
187200
return ['/Zi']
188201
return []
189202

190-
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
191-
if self.info.cpu_family not in {'x86', 'x86_64'}:
192-
raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
193-
194203
def get_pic_args(self) -> T.List[str]:
195204
return []
196205

@@ -217,6 +226,7 @@ def depfile_for_object(self, objfile: str) -> T.Optional[str]:
217226
class MasmARMCompiler(ASMCompiler):
218227
language = 'masm'
219228
id = 'armasm'
229+
_SUPPORTED_ARCHES = {'arm', 'aarch64'}
220230

221231
def needs_static_linker(self) -> bool:
222232
return True
@@ -238,10 +248,6 @@ def get_debug_args(self, is_debug: bool) -> T.List[str]:
238248
return ['-g']
239249
return []
240250

241-
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
242-
if self.info.cpu_family not in {'arm', 'aarch64'}:
243-
raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
244-
245251
def get_pic_args(self) -> T.List[str]:
246252
return []
247253

@@ -267,6 +273,7 @@ def depfile_for_object(self, objfile: str) -> T.Optional[str]:
267273
# https://downloads.ti.com/docs/esd/SPRUI04/
268274
class TILinearAsmCompiler(TICompiler, ASMCompiler):
269275
language = 'linearasm'
276+
_SUPPORTED_ARCHES = {'c6000'}
270277

271278
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
272279
for_machine: MachineChoice, info: MachineInfo,
@@ -284,10 +291,6 @@ def get_always_args(self) -> T.List[str]:
284291
def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]:
285292
return []
286293

287-
def sanity_check(self, work_dir: str, environment: Environment) -> None:
288-
if self.info.cpu_family not in {'c6000'}:
289-
raise EnvironmentException(f'TI Linear ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
290-
291294
def get_depfile_suffix(self) -> str:
292295
return 'd'
293296

@@ -325,21 +328,15 @@ def needs_static_linker(self) -> bool:
325328

326329
class MetrowerksAsmCompilerARM(MetrowerksAsmCompiler):
327330
id = 'mwasmarm'
331+
_SUPPORTED_ARCHES = {'arm'}
328332

329333
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:
330334
return mwasmarm_instruction_set_args.get(instruction_set, None)
331335

332-
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
333-
if self.info.cpu_family not in {'arm'}:
334-
raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')
335-
336336

337337
class MetrowerksAsmCompilerEmbeddedPowerPC(MetrowerksAsmCompiler):
338338
id = 'mwasmeppc'
339+
_SUPPORTED_ARCHES = {'ppc'}
339340

340341
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:
341342
return mwasmeppc_instruction_set_args.get(instruction_set, None)
342-
343-
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
344-
if self.info.cpu_family not in {'ppc'}:
345-
raise EnvironmentException(f'ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')

mesonbuild/compilers/detect.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
if T.TYPE_CHECKING:
2525
from .compilers import Compiler
26+
from .asm import ASMCompiler
2627
from .c import CCompiler
2728
from .cpp import CPPCompiler
2829
from .fortran import FortranCompiler
@@ -1334,6 +1335,7 @@ def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
13341335
continue
13351336

13361337
version = search_version(output)
1338+
comp_class: T.Type[ASMCompiler]
13371339
if 'NASM' in output:
13381340
comp_class = NasmCompiler
13391341
env.add_lang_args(comp_class.language, comp_class, for_machine)
@@ -1366,7 +1368,7 @@ def detect_masm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
13661368
info = env.machines[for_machine]
13671369

13681370
from .asm import MasmCompiler, MasmARMCompiler
1369-
comp_class: T.Type[Compiler]
1371+
comp_class: T.Type[ASMCompiler]
13701372
if info.cpu_family == 'x86':
13711373
comp = ['ml']
13721374
comp_class = MasmCompiler
@@ -1400,7 +1402,7 @@ def detect_masm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
14001402
def detect_linearasm_compiler(env: Environment, for_machine: MachineChoice) -> Compiler:
14011403
from .asm import TILinearAsmCompiler
14021404
comp = ['cl6x']
1403-
comp_class: T.Type[Compiler] = TILinearAsmCompiler
1405+
comp_class: T.Type[ASMCompiler] = TILinearAsmCompiler
14041406
arg = '-h'
14051407
info = env.machines[for_machine]
14061408
cc = detect_c_compiler(env, for_machine)

0 commit comments

Comments
 (0)