aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2018-10-04 20:52:08 -0400
committerJohn Ericson <git@JohnEricson.me>2019-06-09 13:13:25 -0400
commit07777e15d47dbddaf849d24b3a30c85745c533ca (patch)
treef472472ed511498c329b4e13e19b1585e1afb621 /mesonbuild/compilers
parent32e827dcdc451e1c5dde952cf08e4b654eac7057 (diff)
downloadmeson-07777e15d47dbddaf849d24b3a30c85745c533ca.zip
meson-07777e15d47dbddaf849d24b3a30c85745c533ca.tar.gz
meson-07777e15d47dbddaf849d24b3a30c85745c533ca.tar.bz2
Purge `is_cross` and friends without changing user interfaces
In most cases instead pass `for_machine`, the name of the relevant machines (what compilers target, what targets run on, etc). This allows us to use the cross code path in the native case, deduplicating the code. As one can see, environment got bigger as more information is kept structured there, while ninjabackend got a smaller. Overall a few amount of lines were added, but the hope is what's added is a lot simpler than what's removed.
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py50
-rw-r--r--mesonbuild/compilers/clike.py36
-rw-r--r--mesonbuild/compilers/compilers.py7
-rw-r--r--mesonbuild/compilers/cpp.py50
-rw-r--r--mesonbuild/compilers/cs.py14
-rw-r--r--mesonbuild/compilers/cuda.py6
-rw-r--r--mesonbuild/compilers/d.py26
-rw-r--r--mesonbuild/compilers/fortran.py52
-rw-r--r--mesonbuild/compilers/java.py6
-rw-r--r--mesonbuild/compilers/objc.py20
-rw-r--r--mesonbuild/compilers/objcpp.py20
-rw-r--r--mesonbuild/compilers/rust.py8
-rw-r--r--mesonbuild/compilers/swift.py14
-rw-r--r--mesonbuild/compilers/vala.py20
14 files changed, 147 insertions, 182 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 3e536ea..3b58a07 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -16,7 +16,7 @@ import os.path
import typing
from .. import coredata
-from ..mesonlib import MesonException, version_compare, mlog
+from ..mesonlib import MachineChoice, MesonException, mlog, version_compare
from .c_function_attributes import C_FUNC_ATTRIBUTES
from .clike import CLikeCompiler
@@ -47,11 +47,11 @@ class CCompiler(CLikeCompiler, Compiler):
except KeyError:
raise MesonException('Unknown function attribute "{}"'.format(name))
- def __init__(self, exelist, version, is_cross: bool,
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool,
exe_wrapper: typing.Optional[str] = None, **kwargs):
# If a child ObjC or CPP class has already set it, don't set it ourselves
self.language = 'c'
- Compiler.__init__(self, exelist, version, **kwargs)
+ Compiler.__init__(self, exelist, version, for_machine, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrapper)
def get_no_stdinc_args(self):
@@ -76,8 +76,8 @@ class CCompiler(CLikeCompiler, Compiler):
class ClangCCompiler(ClangCompiler, CCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
@@ -119,8 +119,8 @@ class ClangCCompiler(ClangCompiler, CCompiler):
class ArmclangCCompiler(ArmclangCompiler, CCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
ArmclangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
@@ -148,8 +148,8 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
class GnuCCompiler(GnuCompiler, CCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
@@ -191,14 +191,14 @@ class GnuCCompiler(GnuCompiler, CCompiler):
class PGICCompiler(PGICompiler, CCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
PGICompiler.__init__(self, compiler_type)
class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
- GnuCCompiler.__init__(self, exelist, version, compiler_type, is_cross, exe_wrapper, defines, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ GnuCCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, defines, **kwargs)
ElbrusCompiler.__init__(self, compiler_type, defines)
# It does support some various ISO standards and c/gnu 90, 9x, 1x in addition to those which GNU CC supports.
@@ -223,8 +223,8 @@ class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler):
class IntelCCompiler(IntelGnuLikeCompiler, CCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
IntelGnuLikeCompiler.__init__(self, compiler_type)
self.lang_header = 'c-header'
default_warn_args = ['-Wall', '-w3', '-diag-disable:remark']
@@ -267,14 +267,14 @@ class VisualStudioLikeCCompilerMixin:
class VisualStudioCCompiler(VisualStudioLikeCompiler, VisualStudioLikeCCompilerMixin, CCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrap, target: str):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target: str):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap)
VisualStudioLikeCompiler.__init__(self, target)
self.id = 'msvc'
class ClangClCCompiler(VisualStudioLikeCompiler, VisualStudioLikeCCompilerMixin, CCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrap, target):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap)
VisualStudioLikeCompiler.__init__(self, target)
self.id = 'clang-cl'
@@ -285,8 +285,8 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM
__have_warned = False
- def __init__(self, exelist, version, is_cross, exe_wrap, target):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap)
IntelVisualStudioLikeCompiler.__init__(self, target)
def get_options(self):
@@ -310,8 +310,8 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM
class ArmCCompiler(ArmCompiler, CCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
ArmCompiler.__init__(self, compiler_type)
def get_options(self):
@@ -329,8 +329,8 @@ class ArmCCompiler(ArmCompiler, CCompiler):
return args
class CcrxCCompiler(CcrxCompiler, CCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
- CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
CcrxCompiler.__init__(self, compiler_type)
# Override CCompiler.get_always_args
diff --git a/mesonbuild/compilers/clike.py b/mesonbuild/compilers/clike.py
index 968685b..8941931 100644
--- a/mesonbuild/compilers/clike.py
+++ b/mesonbuild/compilers/clike.py
@@ -30,7 +30,7 @@ import typing
from pathlib import Path
from .. import mesonlib
-from ..mesonlib import MachineChoice, LibType
+from ..mesonlib import LibType
from .. import mlog
from . import compilers
@@ -277,7 +277,7 @@ class CLikeCompiler:
m = env.machines[self.for_machine]
if m.is_windows() or m.is_cygwin():
return ['-Wl,--export-all-symbols']
- elif mesonlib.for_darwin(env):
+ elif env.machines[self.for_machine].is_darwin():
return []
else:
return ['-Wl,-export-dynamic']
@@ -384,13 +384,9 @@ class CLikeCompiler:
# Select a CRT if needed since we're linking
if mode == 'link':
args += self.get_linker_debug_crt_args()
- if env.is_cross_build() and not self.is_cross:
- for_machine = MachineChoice.BUILD
- else:
- for_machine = MachineChoice.HOST
if mode in {'compile', 'preprocess'}:
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS and CPPFLAGS from the env
- sys_args = env.coredata.get_external_args(for_machine, self.language)
+ sys_args = env.coredata.get_external_args(self.for_machine, self.language)
# Apparently it is a thing to inject linker flags both
# via CFLAGS _and_ LDFLAGS, even though the former are
# also used during linking. These flags can break
@@ -399,7 +395,7 @@ class CLikeCompiler:
args += cleaned_sys_args
elif mode == 'link':
# Add LDFLAGS from the env
- args += env.coredata.get_external_link_args(for_machine, self.language)
+ args += env.coredata.get_external_link_args(self.for_machine, self.language)
return args
def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'):
@@ -885,7 +881,7 @@ class CLikeCompiler:
for p in prefixes:
for s in suffixes:
patterns.append(p + '{}.' + s)
- if shared and mesonlib.for_openbsd(env):
+ if shared and env.machines[self.for_machine].is_openbsd():
# Shared libraries on OpenBSD can be named libfoo.so.X.Y:
# https://www.openbsd.org/faq/ports/specialtopics.html#SharedLibs
#
@@ -912,9 +908,9 @@ class CLikeCompiler:
else:
prefixes = ['lib', '']
# Library suffixes and prefixes
- if mesonlib.for_darwin(env):
+ if env.machines[self.for_machine].is_darwin():
shlibext = ['dylib', 'so']
- elif mesonlib.for_windows(env):
+ elif env.machines[self.for_machine].is_windows():
# FIXME: .lib files can be import or static so we should read the
# file, figure out which one it is, and reject the wrong kind.
if isinstance(self, compilers.VisualStudioLikeCompiler):
@@ -923,7 +919,7 @@ class CLikeCompiler:
shlibext = ['dll.a', 'lib', 'dll']
# Yep, static libraries can also be foo.lib
stlibext += ['lib']
- elif mesonlib.for_cygwin(env):
+ elif env.machines[self.for_machine].is_cygwin():
shlibext = ['dll', 'dll.a']
prefixes = ['cyg'] + prefixes
else:
@@ -1074,11 +1070,7 @@ class CLikeCompiler:
commands = self.get_exelist() + ['-v', '-E', '-']
commands += self.get_always_args()
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
- if env.is_cross_build() and not self.is_cross:
- for_machine = MachineChoice.BUILD
- else:
- for_machine = MachineChoice.HOST
- commands += env.coredata.get_external_args(for_machine, self.language)
+ commands += env.coredata.get_external_args(self.for_machine, self.language)
mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')
os_env = os.environ.copy()
os_env['LC_ALL'] = 'C'
@@ -1127,12 +1119,14 @@ class CLikeCompiler:
return self.find_framework_impl(name, env, extra_dirs, allow_system)
def thread_flags(self, env):
- if mesonlib.for_haiku(env) or mesonlib.for_darwin(env):
+ host_m = env.machines[self.for_machine]
+ if host_m.is_haiku() or host_m.is_darwin():
return []
return ['-pthread']
def thread_link_flags(self, env):
- if mesonlib.for_haiku(env) or mesonlib.for_darwin(env):
+ host_m = env.machines[self.for_machine]
+ if host_m.is_haiku() or host_m.is_darwin():
return []
return ['-pthread']
@@ -1190,8 +1184,8 @@ class CLikeCompiler:
def has_func_attribute(self, name, env):
# Just assume that if we're not on windows that dllimport and dllexport
# don't work
- if not (mesonlib.for_windows(env) or
- mesonlib.for_cygwin(env)):
+ m = env.machines[self.for_machine]
+ if not (m.is_windows() or m.is_cygwin()):
if name in ['dllimport', 'dllexport']:
return False, False
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 3ad80fe..0a228b4 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -21,7 +21,7 @@ from .. import coredata
from .. import mlog
from .. import mesonlib
from ..mesonlib import (
- EnvironmentException, MesonException, OrderedSet,
+ EnvironmentException, MachineChoice, MesonException, OrderedSet,
version_compare, Popen_safe
)
from ..envconfig import (
@@ -871,7 +871,7 @@ class Compiler:
# manually searched.
internal_libs = ()
- def __init__(self, exelist, version, **kwargs):
+ def __init__(self, exelist, version, for_machine: MachineChoice, **kwargs):
if isinstance(exelist, str):
self.exelist = [exelist]
elif isinstance(exelist, list):
@@ -889,6 +889,7 @@ class Compiler:
self.full_version = kwargs['full_version']
else:
self.full_version = None
+ self.for_machine = for_machine
self.base_options = []
def __repr__(self):
@@ -2183,7 +2184,7 @@ class ClangCompiler(GnuLikeCompiler):
class ArmclangCompiler:
def __init__(self, compiler_type):
- if not self.is_cross:
+ if self.is_cross:
raise EnvironmentException('armclang supports only cross-compilation.')
# Check whether 'armlink.exe' is available in path
self.linker_exe = 'armlink.exe'
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 253525a..e43d839 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -19,7 +19,7 @@ import typing
from .. import coredata
from .. import mlog
-from ..mesonlib import MesonException, version_compare
+from ..mesonlib import MesonException, MachineChoice, version_compare
from .compilers import (
gnu_winlibs,
@@ -55,11 +55,11 @@ class CPPCompiler(CLikeCompiler, Compiler):
except KeyError:
raise MesonException('Unknown function attribute "{}"'.format(name))
- def __init__(self, exelist, version, is_cross: bool,
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool,
exe_wrap: typing.Optional[str] = None, **kwargs):
# If a child ObjCPP class has already set it, don't set it ourselves
self.language = 'cpp'
- Compiler.__init__(self, exelist, version, **kwargs)
+ Compiler.__init__(self, exelist, version, for_machine, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrap)
def get_display_language(self):
@@ -147,8 +147,8 @@ class CPPCompiler(CLikeCompiler, Compiler):
class ClangCPPCompiler(ClangCompiler, CPPCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'0': [],
@@ -185,8 +185,8 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
ArmclangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'0': [],
@@ -221,8 +221,8 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
class GnuCPPCompiler(GnuCompiler, CPPCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrap, defines, **kwargs):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrap, defines, **kwargs):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'0': [],
@@ -272,14 +272,14 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
class PGICPPCompiler(PGICompiler, CPPCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
PGICompiler.__init__(self, compiler_type)
class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
- GnuCPPCompiler.__init__(self, exelist, version, compiler_type, is_cross, exe_wrapper, defines, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ GnuCPPCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, defines, **kwargs)
ElbrusCompiler.__init__(self, compiler_type, defines)
# It does not support c++/gnu++ 17 and 1z, but still does support 0x, 1y, and gnu++98.
@@ -308,8 +308,8 @@ class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler):
class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrap, **kwargs):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrap, **kwargs):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs)
IntelGnuLikeCompiler.__init__(self, compiler_type)
self.lang_header = 'c++-header'
default_warn_args = ['-Wall', '-w3', '-diag-disable:remark',
@@ -441,8 +441,8 @@ class CPP11AsCPP14Mixin:
class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, VisualStudioLikeCompiler, CPPCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrap, target):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, exe_wrap, target):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap)
VisualStudioLikeCompiler.__init__(self, target)
self.base_options = ['b_pch', 'b_vscrt'] # FIXME add lto, pgo and the like
self.id = 'msvc'
@@ -474,8 +474,8 @@ class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixi
return args
class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, VisualStudioLikeCompiler, CPPCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrap, target):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap)
VisualStudioLikeCompiler.__init__(self, target)
self.id = 'clang-cl'
@@ -486,8 +486,8 @@ class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, Vi
class IntelClCPPCompiler(VisualStudioLikeCPPCompilerMixin, IntelVisualStudioLikeCompiler, CPPCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrap, target):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap)
IntelVisualStudioLikeCompiler.__init__(self, target)
def get_options(self):
@@ -497,8 +497,8 @@ class IntelClCPPCompiler(VisualStudioLikeCPPCompilerMixin, IntelVisualStudioLike
class ArmCPPCompiler(ArmCompiler, CPPCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrap=None, **kwargs):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrap=None, **kwargs):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs)
ArmCompiler.__init__(self, compiler_type)
def get_options(self):
@@ -525,8 +525,8 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler):
class CcrxCPPCompiler(CcrxCompiler, CPPCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrap=None, **kwargs):
- CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrap=None, **kwargs):
+ CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs)
CcrxCompiler.__init__(self, compiler_type)
# Override CCompiler.get_always_args
diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py
index c6355f2..8069ab1 100644
--- a/mesonbuild/compilers/cs.py
+++ b/mesonbuild/compilers/cs.py
@@ -17,7 +17,7 @@ import os.path, subprocess
from ..mesonlib import EnvironmentException
from ..mesonlib import is_windows
-from .compilers import Compiler, mono_buildtype_args
+from .compilers import Compiler, MachineChoice, mono_buildtype_args
cs_optimization_args = {'0': [],
'g': [],
@@ -28,9 +28,9 @@ cs_optimization_args = {'0': [],
}
class CsCompiler(Compiler):
- def __init__(self, exelist, version, comp_id, runner=None):
+ def __init__(self, exelist, version, for_machine: MachineChoice, comp_id, runner=None):
self.language = 'cs'
- super().__init__(exelist, version)
+ super().__init__(exelist, version, for_machine)
self.id = comp_id
self.is_cross = False
self.runner = runner
@@ -143,14 +143,14 @@ class CsCompiler(Compiler):
return cs_optimization_args[optimization_level]
class MonoCompiler(CsCompiler):
- def __init__(self, exelist, version):
- super().__init__(exelist, version, 'mono',
+ def __init__(self, exelist, version, for_machine: MachineChoice):
+ super().__init__(exelist, version, for_machine, 'mono',
'mono')
class VisualStudioCsCompiler(CsCompiler):
- def __init__(self, exelist, version):
- super().__init__(exelist, version, 'csc')
+ def __init__(self, exelist, version, for_machine: MachineChoice):
+ super().__init__(exelist, version, for_machine, 'csc')
def get_buildtype_args(self, buildtype):
res = mono_buildtype_args[buildtype]
diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py
index 51a1300..3c38c09 100644
--- a/mesonbuild/compilers/cuda.py
+++ b/mesonbuild/compilers/cuda.py
@@ -15,15 +15,15 @@
import re, os.path
from .. import mlog
-from ..mesonlib import EnvironmentException, Popen_safe
+from ..mesonlib import EnvironmentException, MachineChoice, Popen_safe
from .compilers import (Compiler, cuda_buildtype_args, cuda_optimization_args,
cuda_debug_args, CompilerType, get_gcc_soname_args)
class CudaCompiler(Compiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None):
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None):
if not hasattr(self, 'language'):
self.language = 'cuda'
- super().__init__(exelist, version)
+ super().__init__(exelist, version, for_machine)
self.is_cross = is_cross
self.exe_wrapper = exe_wrapper
self.id = 'nvcc'
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 46cc054..b7bc49a 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -73,11 +73,10 @@ class DCompiler(Compiler):
'mtd': ['-mscrtlib=libcmtd'],
}
- def __init__(self, exelist, version, is_cross, arch, **kwargs):
+ def __init__(self, exelist, version, for_machine: MachineChoice, arch, **kwargs):
self.language = 'd'
- super().__init__(exelist, version, **kwargs)
+ super().__init__(exelist, version, for_machine, **kwargs)
self.id = 'unknown'
- self.is_cross = is_cross
self.arch = arch
def sanity_check(self, work_dir, environment):
@@ -308,17 +307,12 @@ class DCompiler(Compiler):
# Add link flags needed to find dependencies
args += d.get_link_args()
- if env.is_cross_build() and not self.is_cross:
- for_machine = MachineChoice.BUILD
- else:
- for_machine = MachineChoice.HOST
-
if mode == 'compile':
# Add DFLAGS from the env
- args += env.coredata.get_external_args(for_machine, self.language)
+ args += env.coredata.get_external_args(self.for_machine, self.language)
elif mode == 'link':
# Add LDFLAGS from the env
- args += env.coredata.get_external_link_args(for_machine, self.language)
+ args += env.coredata.get_external_link_args(self.for_machine, self.language)
# extra_args must override all other arguments, so we add them last
args += extra_args
return args
@@ -494,8 +488,8 @@ class DCompiler(Compiler):
return ['-pthread']
class GnuDCompiler(DCompiler):
- def __init__(self, exelist, version, is_cross, arch, **kwargs):
- DCompiler.__init__(self, exelist, version, is_cross, arch, **kwargs)
+ def __init__(self, exelist, version, for_machine: MachineChoice, arch, **kwargs):
+ DCompiler.__init__(self, exelist, version, for_machine, arch, **kwargs)
self.id = 'gcc'
default_warn_args = ['-Wall', '-Wdeprecated']
self.warn_args = {'0': [],
@@ -557,8 +551,8 @@ class GnuDCompiler(DCompiler):
return gnu_optimization_args[optimization_level]
class LLVMDCompiler(DCompiler):
- def __init__(self, exelist, version, is_cross, arch, **kwargs):
- DCompiler.__init__(self, exelist, version, is_cross, arch, **kwargs)
+ def __init__(self, exelist, version, for_machine: MachineChoice, arch, **kwargs):
+ DCompiler.__init__(self, exelist, version, for_machine, arch, **kwargs)
self.id = 'llvm'
self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt']
@@ -595,8 +589,8 @@ class LLVMDCompiler(DCompiler):
class DmdDCompiler(DCompiler):
- def __init__(self, exelist, version, is_cross, arch, **kwargs):
- DCompiler.__init__(self, exelist, version, is_cross, arch, **kwargs)
+ def __init__(self, exelist, version, for_machine: MachineChoice, arch, **kwargs):
+ DCompiler.__init__(self, exelist, version, for_machine, arch, **kwargs)
self.id = 'dmd'
self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt']
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index 5de1de4..fe23b6b 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -40,9 +40,9 @@ from mesonbuild.mesonlib import (
class FortranCompiler(CLikeCompiler, Compiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwargs):
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs):
self.language = 'fortran'
- Compiler.__init__(self, exelist, version, **kwargs)
+ Compiler.__init__(self, exelist, version, for_machine, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrapper)
self.id = 'unknown'
@@ -62,12 +62,8 @@ class FortranCompiler(CLikeCompiler, Compiler):
source_name.write_text('print *, "Fortran compilation is working."; end')
- if environment.is_cross_build() and not self.is_cross:
- for_machine = MachineChoice.BUILD
- else:
- for_machine = MachineChoice.HOST
- extra_flags = environment.coredata.get_external_args(for_machine, self.language)
- extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
+ extra_flags = environment.coredata.get_external_args(self.for_machine, self.language)
+ extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
extra_flags += self.get_always_args()
# %% build the test executable
pc = subprocess.Popen(self.exelist + extra_flags + [str(source_name), '-o', str(binary_name)])
@@ -167,8 +163,8 @@ class FortranCompiler(CLikeCompiler, Compiler):
class GnuFortranCompiler(GnuCompiler, FortranCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
- FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall']
self.warn_args = {'0': [],
@@ -189,13 +185,13 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
return ['-lgfortran', '-lm']
class ElbrusFortranCompiler(GnuFortranCompiler, ElbrusCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
- GnuFortranCompiler.__init__(self, exelist, version, compiler_type, is_cross, exe_wrapper, defines, **kwargs)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ GnuFortranCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, defines, **kwargs)
ElbrusCompiler.__init__(self, compiler_type, defines)
class G95FortranCompiler(FortranCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwags):
- FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags):
+ FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags)
self.id = 'g95'
default_warn_args = ['-Wall']
self.warn_args = {'0': [],
@@ -212,8 +208,8 @@ class G95FortranCompiler(FortranCompiler):
class SunFortranCompiler(FortranCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwags):
- FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags):
+ FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags)
self.id = 'sun'
def get_dependency_gen_args(self, outtarget, outfile):
@@ -236,9 +232,9 @@ class SunFortranCompiler(FortranCompiler):
class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwags):
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags):
self.file_suffixes = ('f90', 'f', 'for', 'ftn', 'fpp')
- FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
+ FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags)
# FIXME: Add support for OS X and Windows in detect_fortran_compiler so
# we are sent the type of compiler
IntelGnuLikeCompiler.__init__(self, CompilerType.ICC_STANDARD)
@@ -293,8 +289,8 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
class PathScaleFortranCompiler(FortranCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwags):
- FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags):
+ FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags)
self.id = 'pathscale'
default_warn_args = ['-fullwarn']
self.warn_args = {'0': [],
@@ -307,8 +303,8 @@ class PathScaleFortranCompiler(FortranCompiler):
class PGIFortranCompiler(PGICompiler, FortranCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwags):
- FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags):
+ FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags)
PGICompiler.__init__(self, compiler_type)
def language_stdlib_only_link_flags(self) -> List[str]:
@@ -316,8 +312,8 @@ class PGIFortranCompiler(PGICompiler, FortranCompiler):
'-lpgf90rtl', '-lpgftnrtl', '-lrt']
class FlangFortranCompiler(ClangCompiler, FortranCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwags):
- FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags):
+ FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags)
ClangCompiler.__init__(self, CompilerType.CLANG_STANDARD)
self.id = 'flang'
default_warn_args = ['-Minform=inform']
@@ -327,8 +323,8 @@ class FlangFortranCompiler(ClangCompiler, FortranCompiler):
'3': default_warn_args}
class Open64FortranCompiler(FortranCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwags):
- FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags):
+ FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags)
self.id = 'open64'
default_warn_args = ['-fullwarn']
self.warn_args = {'0': [],
@@ -341,8 +337,8 @@ class Open64FortranCompiler(FortranCompiler):
class NAGFortranCompiler(FortranCompiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwags):
- FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags):
+ FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags)
self.id = 'nagfor'
def get_warn_args(self, level):
diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py
index 5d7f865..ea1fa0f 100644
--- a/mesonbuild/compilers/java.py
+++ b/mesonbuild/compilers/java.py
@@ -14,14 +14,14 @@
import os.path, shutil, subprocess
-from ..mesonlib import EnvironmentException
+from ..mesonlib import EnvironmentException, MachineChoice
from .compilers import Compiler, java_buildtype_args
class JavaCompiler(Compiler):
- def __init__(self, exelist, version):
+ def __init__(self, exelist, version, for_machine: MachineChoice):
self.language = 'java'
- super().__init__(exelist, version)
+ super().__init__(exelist, version, for_machine)
self.id = 'unknown'
self.is_cross = False
self.javarunner = 'java'
diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py
index 55311ed..f9ca793 100644
--- a/mesonbuild/compilers/objc.py
+++ b/mesonbuild/compilers/objc.py
@@ -21,9 +21,9 @@ from .clike import CLikeCompiler
from .compilers import Compiler, ClangCompiler, GnuCompiler
class ObjCCompiler(CLikeCompiler, Compiler):
- def __init__(self, exelist, version, is_cross: bool, exe_wrap: typing.Optional[str]):
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, exe_wrap: typing.Optional[str]):
self.language = 'objc'
- Compiler.__init__(self, exelist, version)
+ Compiler.__init__(self, exelist, version, for_machine)
CLikeCompiler.__init__(self, is_cross, exe_wrap)
def get_display_language(self):
@@ -33,15 +33,11 @@ class ObjCCompiler(CLikeCompiler, Compiler):
# TODO try to use sanity_check_impl instead of duplicated code
source_name = os.path.join(work_dir, 'sanitycheckobjc.m')
binary_name = os.path.join(work_dir, 'sanitycheckobjc')
- if environment.is_cross_build() and not self.is_cross:
- for_machine = MachineChoice.BUILD
- else:
- for_machine = MachineChoice.HOST
- extra_flags = environment.coredata.get_external_args(for_machine, self.language)
+ extra_flags = environment.coredata.get_external_args(self.for_machine, self.language)
if self.is_cross:
extra_flags += self.get_compile_only_args()
else:
- extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
+ extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
with open(source_name, 'w') as ofile:
ofile.write('#import<stdio.h>\n'
'int main(int argc, char **argv) { return 0; }\n')
@@ -59,8 +55,8 @@ class ObjCCompiler(CLikeCompiler, Compiler):
class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None):
- ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None):
+ ObjCCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
@@ -70,8 +66,8 @@ class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None):
- ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None):
+ ObjCCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper)
ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [],
diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py
index 6743f89..2e81b4c 100644
--- a/mesonbuild/compilers/objcpp.py
+++ b/mesonbuild/compilers/objcpp.py
@@ -21,9 +21,9 @@ from .clike import CLikeCompiler
from .compilers import Compiler, ClangCompiler, GnuCompiler
class ObjCPPCompiler(CLikeCompiler, Compiler):
- def __init__(self, exelist, version, is_cross: bool, exe_wrap: typing.Optional[str]):
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, exe_wrap: typing.Optional[str]):
self.language = 'objcpp'
- Compiler.__init__(self, exelist, version)
+ Compiler.__init__(self, exelist, version, for_machine)
CLikeCompiler.__init__(self, is_cross, exe_wrap)
def get_display_language(self):
@@ -33,15 +33,11 @@ class ObjCPPCompiler(CLikeCompiler, Compiler):
# TODO try to use sanity_check_impl instead of duplicated code
source_name = os.path.join(work_dir, 'sanitycheckobjcpp.mm')
binary_name = os.path.join(work_dir, 'sanitycheckobjcpp')
- if environment.is_cross_build() and not self.is_cross:
- for_machine = MachineChoice.BUILD
- else:
- for_machine = MachineChoice.HOST
- extra_flags = environment.coredata.get_external_args(for_machine, self.language)
+ extra_flags = environment.coredata.get_external_args(self.for_machine, self.language)
if self.is_cross:
extra_flags += self.get_compile_only_args()
else:
- extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
+ extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
with open(source_name, 'w') as ofile:
ofile.write('#import<stdio.h>\n'
'class MyClass;'
@@ -60,8 +56,8 @@ class ObjCPPCompiler(CLikeCompiler, Compiler):
class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None):
- ObjCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None):
+ ObjCPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'0': [],
@@ -71,8 +67,8 @@ class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler):
- def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None):
- ObjCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
+ def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None):
+ ObjCPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper)
ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'0': [],
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index 410125a..17b7e3b 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -14,7 +14,7 @@
import subprocess, os.path
-from ..mesonlib import EnvironmentException, Popen_safe
+from ..mesonlib import EnvironmentException, MachineChoice, Popen_safe
from .compilers import Compiler, rust_buildtype_args, clike_debug_args
@@ -27,12 +27,12 @@ rust_optimization_args = {'0': [],
}
class RustCompiler(Compiler):
- def __init__(self, exelist, version, is_cross, exe_wrapper=None):
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None):
self.language = 'rust'
- super().__init__(exelist, version)
- self.is_cross = is_cross
+ super().__init__(exelist, version, for_machine)
self.exe_wrapper = exe_wrapper
self.id = 'rustc'
+ self.is_cross = is_cross
def needs_static_linker(self):
return False
diff --git a/mesonbuild/compilers/swift.py b/mesonbuild/compilers/swift.py
index 17705ac..0038264 100644
--- a/mesonbuild/compilers/swift.py
+++ b/mesonbuild/compilers/swift.py
@@ -27,12 +27,12 @@ swift_optimization_args = {'0': [],
}
class SwiftCompiler(Compiler):
- def __init__(self, exelist, version):
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross):
self.language = 'swift'
- super().__init__(exelist, version)
+ super().__init__(exelist, version, for_machine)
self.version = version
self.id = 'llvm'
- self.is_cross = False
+ self.is_cross = is_cross
def get_linker_exelist(self):
return self.exelist[:]
@@ -102,15 +102,11 @@ class SwiftCompiler(Compiler):
src = 'swifttest.swift'
source_name = os.path.join(work_dir, src)
output_name = os.path.join(work_dir, 'swifttest')
- if environment.is_cross_build() and not self.is_cross:
- for_machine = MachineChoice.BUILD
- else:
- for_machine = MachineChoice.HOST
- extra_flags = environment.coredata.get_external_args(for_machine, self.language)
+ extra_flags = environment.coredata.get_external_args(self.for_machine, self.language)
if self.is_cross:
extra_flags += self.get_compile_only_args()
else:
- extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
+ extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
with open(source_name, 'w') as ofile:
ofile.write('''print("Swift compilation is working.")
''')
diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py
index c0b2a68..0a612ae 100644
--- a/mesonbuild/compilers/vala.py
+++ b/mesonbuild/compilers/vala.py
@@ -20,12 +20,12 @@ from ..mesonlib import EnvironmentException, MachineChoice, version_compare
from .compilers import Compiler
class ValaCompiler(Compiler):
- def __init__(self, exelist, version):
+ def __init__(self, exelist, version, for_machine: MachineChoice, is_cross):
self.language = 'vala'
- super().__init__(exelist, version)
+ super().__init__(exelist, version, for_machine)
self.version = version
+ self.is_cross = is_cross
self.id = 'valac'
- self.is_cross = False
self.base_options = ['b_colorout']
def name_string(self):
@@ -87,15 +87,11 @@ class ValaCompiler(Compiler):
def sanity_check(self, work_dir, environment):
code = 'class MesonSanityCheck : Object { }'
- if environment.is_cross_build() and not self.is_cross:
- for_machine = MachineChoice.BUILD
- else:
- for_machine = MachineChoice.HOST
- extra_flags = environment.coredata.get_external_args(for_machine, self.language)
+ extra_flags = environment.coredata.get_external_args(self.for_machine, self.language)
if self.is_cross:
extra_flags += self.get_compile_only_args()
else:
- extra_flags += environment.coredata.get_external_link_args(for_machine, self.language)
+ extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
with self.cached_compile(code, environment.coredata, extra_args=extra_flags, mode='compile') as p:
if p.returncode != 0:
msg = 'Vala compiler {!r} can not compile programs' \
@@ -114,11 +110,7 @@ class ValaCompiler(Compiler):
# no extra dirs are specified.
if not extra_dirs:
code = 'class MesonFindLibrary : Object { }'
- if env.is_cross_build() and not self.is_cross:
- for_machine = MachineChoice.BUILD
- else:
- for_machine = MachineChoice.HOST
- args = env.coredata.get_external_args(for_machine, self.language)
+ args = env.coredata.get_external_args(self.for_machine, self.language)
vapi_args = ['--pkg', libname]
args += vapi_args
with self.cached_compile(code, env.coredata, extra_args=args, mode='compile') as p: