aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/compilers.py39
-rw-r--r--mesonbuild/compilers/cpp.py15
-rw-r--r--mesonbuild/compilers/cs.py5
-rw-r--r--mesonbuild/compilers/cuda.py27
-rw-r--r--mesonbuild/compilers/d.py10
-rw-r--r--mesonbuild/compilers/detect.py2
-rw-r--r--mesonbuild/compilers/fortran.py15
-rw-r--r--mesonbuild/compilers/java.py5
-rw-r--r--mesonbuild/compilers/mixins/clang.py5
-rw-r--r--mesonbuild/compilers/mixins/clike.py33
-rw-r--r--mesonbuild/compilers/mixins/emscripten.py2
-rw-r--r--mesonbuild/compilers/mixins/gnu.py2
-rw-r--r--mesonbuild/compilers/mixins/pgi.py6
-rw-r--r--mesonbuild/compilers/rust.py26
-rw-r--r--mesonbuild/compilers/swift.py22
-rw-r--r--mesonbuild/compilers/vala.py2
16 files changed, 115 insertions, 101 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 3c1d58b..0376922 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -749,7 +749,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
return args.copy()
def find_library(self, libname: str, env: 'Environment', extra_dirs: T.List[str],
- libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True) -> T.Optional[T.List[str]]:
+ libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True, ignore_system_dirs: bool = False) -> T.Optional[T.List[str]]:
raise EnvironmentException(f'Language {self.get_display_language()} does not support library finding.')
def get_library_naming(self, env: 'Environment', libtype: LibType,
@@ -1119,6 +1119,9 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def get_compile_only_args(self) -> T.List[str]:
return []
+ def get_cxx_interoperability_args(self, lang: T.Dict[str, Compiler]) -> T.List[str]:
+ raise EnvironmentException('This compiler does not support CXX interoperability')
+
def get_preprocess_only_args(self) -> T.List[str]:
raise EnvironmentException('This compiler does not have a preprocessor')
@@ -1200,6 +1203,23 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
is good enough here.
"""
+ def run_sanity_check(self, environment: Environment, cmdlist: T.List[str], work_dir: str, use_exe_wrapper_for_cross: bool = True) -> T.Tuple[str, str]:
+ # Run sanity check
+ if self.is_cross and use_exe_wrapper_for_cross:
+ if not environment.has_exe_wrapper():
+ # Can't check if the binaries run so we have to assume they do
+ return ('', '')
+ cmdlist = environment.exe_wrapper.get_command() + cmdlist
+ mlog.debug('Running test binary command: ', mesonlib.join_args(cmdlist))
+ try:
+ pe, stdo, stde = Popen_safe_logged(cmdlist, 'Sanity check', cwd=work_dir)
+ except Exception as e:
+ raise mesonlib.EnvironmentException(f'Could not invoke sanity check executable: {e!s}.')
+
+ if pe.returncode != 0:
+ raise mesonlib.EnvironmentException(f'Executables created by {self.language} compiler {self.name_string()} are not runnable.')
+ return stdo, stde
+
def split_shlib_to_parts(self, fname: str) -> T.Tuple[T.Optional[str], str]:
return None, fname
@@ -1407,12 +1427,19 @@ def get_global_options(lang: str,
description = f'Extra arguments passed to the {lang}'
argkey = OptionKey(f'{lang}_args', machine=for_machine)
largkey = OptionKey(f'{lang}_link_args', machine=for_machine)
- envkey = OptionKey(f'{lang}_env_args', machine=for_machine)
- comp_key = argkey if argkey in env.options else envkey
+ comp_args_from_envvar = False
+ comp_options = env.coredata.optstore.get_pending_value(argkey)
+ if comp_options is None:
+ comp_args_from_envvar = True
+ comp_options = env.env_opts.get(argkey, [])
+
+ link_args_from_envvar = False
+ link_options = env.coredata.optstore.get_pending_value(largkey)
+ if link_options is None:
+ link_args_from_envvar = True
+ link_options = env.env_opts.get(largkey, [])
- comp_options = env.options.get(comp_key, [])
- link_options = env.options.get(largkey, [])
assert isinstance(comp_options, (str, list)), 'for mypy'
assert isinstance(link_options, (str, list)), 'for mypy'
@@ -1426,7 +1453,7 @@ def get_global_options(lang: str,
description + ' linker',
link_options, split_args=True, allow_dups=True)
- if comp.INVOKES_LINKER and comp_key == envkey:
+ if comp.INVOKES_LINKER and comp_args_from_envvar and link_args_from_envvar:
# If the compiler acts as a linker driver, and we're using the
# environment variable flags for both the compiler and linker
# arguments, then put the compiler flags in the linker flags as well.
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 01b9bb9..ed8d1cf 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -311,6 +311,9 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCPPStds, ClangCompiler, CPPCompiler
return libs
return []
+ def is_libcpp_enable_assertions_deprecated(self) -> bool:
+ return version_compare(self.version, ">=18")
+
def get_assert_args(self, disable: bool, env: 'Environment') -> T.List[str]:
if disable:
return ['-DNDEBUG']
@@ -323,7 +326,7 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCPPStds, ClangCompiler, CPPCompiler
if self.language_stdlib_provider(env) == 'stdc++':
return ['-D_GLIBCXX_ASSERTIONS=1']
else:
- if version_compare(self.version, '>=18'):
+ if self.is_libcpp_enable_assertions_deprecated():
return ['-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST']
elif version_compare(self.version, '>=15'):
return ['-D_LIBCPP_ENABLE_ASSERTIONS=1']
@@ -343,7 +346,12 @@ class ArmLtdClangCPPCompiler(ClangCPPCompiler):
class AppleClangCPPCompiler(AppleCompilerMixin, AppleCPPStdsMixin, ClangCPPCompiler):
- pass
+ def is_libcpp_enable_assertions_deprecated(self) -> bool:
+ # Upstream libc++ deprecated _LIBCPP_ENABLE_ASSERTIONS
+ # in favor of _LIBCPP_HARDENING_MODE from version 18 onwards,
+ # but Apple Clang 17's libc++ has back-ported that change.
+ # See: https://github.com/mesonbuild/meson/issues/14440
+ return version_compare(self.version, ">=17")
class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler):
@@ -872,8 +880,7 @@ class CPP11AsCPP14Mixin(CompilerMixinBase):
'attempting best effort; setting the standard to C++14',
once=True, fatal=False)
original_args = super().get_option_std_args(target, env, subproject)
- std_mapping = {'/std:c++11': '/std:c++14',
- '/std:c++14': '/std:vc++14'}
+ std_mapping = {'/std:c++11': '/std:c++14'}
processed_args = [std_mapping.get(x, x) for x in original_args]
return processed_args
diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py
index 38bb338..4bbddeb 100644
--- a/mesonbuild/compilers/cs.py
+++ b/mesonbuild/compilers/cs.py
@@ -102,10 +102,7 @@ class CsCompiler(BasicLinkerIsCompilerMixin, Compiler):
cmdlist = [self.runner, obj]
else:
cmdlist = [os.path.join(work_dir, obj)]
- pe = subprocess.Popen(cmdlist, cwd=work_dir)
- pe.wait()
- if pe.returncode != 0:
- raise EnvironmentException('Executables created by Mono compiler %s are not runnable.' % self.name_string())
+ self.run_sanity_check(environment, cmdlist, work_dir, use_exe_wrapper_for_cross=False)
def needs_static_linker(self) -> bool:
return False
diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py
index 6cc6f96..fd747d1 100644
--- a/mesonbuild/compilers/cuda.py
+++ b/mesonbuild/compilers/cuda.py
@@ -577,21 +577,12 @@ class CudaCompiler(Compiler):
# Run sanity check (if possible)
if self.is_cross:
- if not env.has_exe_wrapper():
- return
- else:
- cmdlist = env.exe_wrapper.get_command() + [binary_name]
- else:
- cmdlist = self.exelist + ['--run', '"' + binary_name + '"']
- mlog.debug('Sanity check run command line: ', ' '.join(cmdlist))
- pe, stdo, stde = Popen_safe(cmdlist, cwd=work_dir)
- mlog.debug('Sanity check run stdout: ')
- mlog.debug(stdo)
- mlog.debug('-----\nSanity check run stderr:')
- mlog.debug(stde)
- mlog.debug('-----')
- pe.wait()
- if pe.returncode != 0:
+ return
+
+ cmdlist = self.exelist + ['--run', f'"{binary_name}"']
+ try:
+ stdo, stde = self.run_sanity_check(env, cmdlist, work_dir)
+ except EnvironmentException:
raise EnvironmentException(f'Executables created by {self.language} compiler {self.name_string()} are not runnable.')
# Interpret the result of the sanity test.
@@ -599,8 +590,6 @@ class CudaCompiler(Compiler):
# architecture detection test.
if stde == '':
self.detected_cc = stdo
- else:
- mlog.debug('cudaGetDeviceCount() returned ' + stde)
def has_header_symbol(self, hname: str, symbol: str, prefix: str,
env: 'Environment', *,
@@ -774,8 +763,8 @@ class CudaCompiler(Compiler):
return self._to_host_flags(self.host_compiler.get_std_exe_link_args(), Phase.LINKER)
def find_library(self, libname: str, env: 'Environment', extra_dirs: T.List[str],
- libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True) -> T.Optional[T.List[str]]:
- return self.host_compiler.find_library(libname, env, extra_dirs, libtype, lib_prefix_warning)
+ libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True, ignore_system_dirs: bool = False) -> T.Optional[T.List[str]]:
+ return self.host_compiler.find_library(libname, env, extra_dirs, libtype, lib_prefix_warning, ignore_system_dirs)
def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]:
return self._to_host_flags(self.host_compiler.get_crt_compile_args(crt_val, buildtype))
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 8ee6ebf..51f2436 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -456,15 +456,7 @@ class DCompiler(Compiler):
if pc.returncode != 0:
raise EnvironmentException('D compiler %s cannot compile programs.' % self.name_string())
- if self.is_cross:
- if not environment.has_exe_wrapper():
- # Can't check if the binaries run so we have to assume they do
- return
- cmdlist = environment.exe_wrapper.get_command() + [output_name]
- else:
- cmdlist = [output_name]
- if subprocess.call(cmdlist) != 0:
- raise EnvironmentException('Executables created by D compiler %s are not runnable.' % self.name_string())
+ stdo, stde = self.run_sanity_check(environment, [output_name], work_dir)
def needs_static_linker(self) -> bool:
return True
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index 53bdd85..040c42f 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -107,7 +107,7 @@ def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoic
if comp is None:
return comp
assert comp.for_machine == for_machine
- env.coredata.process_compiler_options(lang, comp, env, subproject)
+ env.coredata.process_compiler_options(lang, comp, subproject)
if not skip_sanity_check:
comp.sanity_check(env.get_scratch_dir(), env)
env.coredata.compilers[comp.for_machine][lang] = comp
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index 5794db0..6f4f3d2 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -104,9 +104,9 @@ class FortranCompiler(CLikeCompiler, Compiler):
return filename
def find_library(self, libname: str, env: 'Environment', extra_dirs: T.List[str],
- libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True) -> T.Optional[T.List[str]]:
+ libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True, ignore_system_dirs: bool = False) -> T.Optional[T.List[str]]:
code = 'stop; end program'
- return self._find_library_impl(libname, env, extra_dirs, code, libtype, lib_prefix_warning)
+ return self._find_library_impl(libname, env, extra_dirs, code, libtype, lib_prefix_warning, ignore_system_dirs)
def has_multi_arguments(self, args: T.List[str], env: 'Environment') -> T.Tuple[bool, bool]:
return self._has_multi_arguments(args, env, 'stop; end program')
@@ -446,6 +446,11 @@ class IntelLLVMFortranCompiler(IntelFortranCompiler):
id = 'intel-llvm'
+ def get_preprocess_only_args(self) -> T.List[str]:
+ return ['-preprocess-only']
+
+ def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
+ return []
class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
@@ -643,7 +648,11 @@ class LlvmFlangFortranCompiler(ClangCompiler, FortranCompiler):
# https://github.com/llvm/llvm-project/commit/8d5386669ed63548daf1bee415596582d6d78d7d;
# it seems flang 18 doesn't work if something accidentally includes a program unit, see
# https://github.com/llvm/llvm-project/issues/92496
- return search_dirs + ['-lFortranRuntime', '-lFortranDecimal']
+ # Only link FortranRuntime and FortranDecimal for flang < 19, see
+ # https://github.com/scipy/scipy/issues/21562#issuecomment-2942938509
+ if version_compare(self.version, '<19'):
+ search_dirs += ['-lFortranRuntime', '-lFortranDecimal']
+ return search_dirs
class Open64FortranCompiler(FortranCompiler):
diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py
index 540e2aa..47d2ac9 100644
--- a/mesonbuild/compilers/java.py
+++ b/mesonbuild/compilers/java.py
@@ -91,10 +91,7 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler):
runner = shutil.which(self.javarunner)
if runner:
cmdlist = [runner, '-cp', '.', obj]
- pe = subprocess.Popen(cmdlist, cwd=work_dir)
- pe.wait()
- if pe.returncode != 0:
- raise EnvironmentException(f'Executables created by Java compiler {self.name_string()} are not runnable.')
+ self.run_sanity_check(environment, cmdlist, work_dir, use_exe_wrapper_for_cross=False)
else:
m = "Java Virtual Machine wasn't found, but it's needed by Meson. " \
"Please install a JRE.\nIf you have specific needs where this " \
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index ae5ab63..72b987a 100644
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -155,7 +155,10 @@ class ClangCompiler(GnuLikeCompiler):
# llvm based) is retargetable, while GCC is not.
#
- # qcld: Qualcomm Snapdragon linker, based on LLVM
+ # eld: Qualcomm's opensource embedded linker
+ if linker == 'eld':
+ return ['-fuse-ld=eld']
+ # qcld: Qualcomm's deprecated linker
if linker == 'qcld':
return ['-fuse-ld=qcld']
if linker == 'mold':
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index b163407..1c875a3 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -128,7 +128,7 @@ class CLikeCompiler(Compiler):
warn_args: T.Dict[str, T.List[str]] = {}
# TODO: Replace this manual cache with functools.lru_cache
- find_library_cache: T.Dict[T.Tuple[T.Tuple[str, ...], str, T.Tuple[str, ...], str, LibType], T.Optional[T.List[str]]] = {}
+ find_library_cache: T.Dict[T.Tuple[T.Tuple[str, ...], str, T.Tuple[str, ...], str, LibType, bool], T.Optional[T.List[str]]] = {}
find_framework_cache: T.Dict[T.Tuple[T.Tuple[str, ...], str, T.Tuple[str, ...], bool], T.Optional[T.List[str]]] = {}
internal_libs = arglist.UNIXY_COMPILER_INTERNAL_LIBS
@@ -307,22 +307,7 @@ class CLikeCompiler(Compiler):
mlog.debug('-----')
if pc.returncode != 0:
raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
- # Run sanity check
- if self.is_cross:
- if not environment.has_exe_wrapper():
- # Can't check if the binaries run so we have to assume they do
- return
- cmdlist = environment.exe_wrapper.get_command() + [binary_name]
- else:
- cmdlist = [binary_name]
- mlog.debug('Running test binary command: ', mesonlib.join_args(cmdlist))
- try:
- # fortran code writes to stdout
- pe = subprocess.run(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
- except Exception as e:
- raise mesonlib.EnvironmentException(f'Could not invoke sanity test executable: {e!s}.')
- if pe.returncode != 0:
- raise mesonlib.EnvironmentException(f'Executables created by {self.language} compiler {self.name_string()} are not runnable.')
+ self.run_sanity_check(environment, [binary_name], work_dir)
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
code = 'int main(void) { int class=0; return class; }\n'
@@ -1128,7 +1113,7 @@ class CLikeCompiler(Compiler):
'''
return self.sizeof('void *', '', env)[0] == 8
- def _find_library_real(self, libname: str, env: 'Environment', extra_dirs: T.List[str], code: str, libtype: LibType, lib_prefix_warning: bool) -> T.Optional[T.List[str]]:
+ def _find_library_real(self, libname: str, env: 'Environment', extra_dirs: T.List[str], code: str, libtype: LibType, lib_prefix_warning: bool, ignore_system_dirs: bool) -> T.Optional[T.List[str]]:
# First try if we can just add the library as -l.
# Gcc + co seem to prefer builtin lib dirs to -L dirs.
# Only try to find std libs if no extra dirs specified.
@@ -1159,7 +1144,7 @@ class CLikeCompiler(Compiler):
except (mesonlib.MesonException, KeyError): # TODO evaluate if catching KeyError is wanted here
elf_class = 0
# Search in the specified dirs, and then in the system libraries
- for d in itertools.chain(extra_dirs, self.get_library_dirs(env, elf_class)):
+ for d in itertools.chain(extra_dirs, [] if ignore_system_dirs else self.get_library_dirs(env, elf_class)):
for p in patterns:
trials = self._get_trials_from_pattern(p, d, libname)
if not trials:
@@ -1173,15 +1158,15 @@ class CLikeCompiler(Compiler):
return None
def _find_library_impl(self, libname: str, env: 'Environment', extra_dirs: T.List[str],
- code: str, libtype: LibType, lib_prefix_warning: bool) -> T.Optional[T.List[str]]:
+ code: str, libtype: LibType, lib_prefix_warning: bool, ignore_system_dirs: bool) -> T.Optional[T.List[str]]:
# These libraries are either built-in or invalid
if libname in self.ignore_libs:
return []
if isinstance(extra_dirs, str):
extra_dirs = [extra_dirs]
- key = (tuple(self.exelist), libname, tuple(extra_dirs), code, libtype)
+ key = (tuple(self.exelist), libname, tuple(extra_dirs), code, libtype, ignore_system_dirs)
if key not in self.find_library_cache:
- value = self._find_library_real(libname, env, extra_dirs, code, libtype, lib_prefix_warning)
+ value = self._find_library_real(libname, env, extra_dirs, code, libtype, lib_prefix_warning, ignore_system_dirs)
self.find_library_cache[key] = value
else:
value = self.find_library_cache[key]
@@ -1190,9 +1175,9 @@ class CLikeCompiler(Compiler):
return value.copy()
def find_library(self, libname: str, env: 'Environment', extra_dirs: T.List[str],
- libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True) -> T.Optional[T.List[str]]:
+ libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True, ignore_system_dirs: bool = False) -> T.Optional[T.List[str]]:
code = 'int main(void) { return 0; }\n'
- return self._find_library_impl(libname, env, extra_dirs, code, libtype, lib_prefix_warning)
+ return self._find_library_impl(libname, env, extra_dirs, code, libtype, lib_prefix_warning, ignore_system_dirs)
def find_framework_paths(self, env: 'Environment') -> T.List[str]:
'''
diff --git a/mesonbuild/compilers/mixins/emscripten.py b/mesonbuild/compilers/mixins/emscripten.py
index 91b25e8..83534e1 100644
--- a/mesonbuild/compilers/mixins/emscripten.py
+++ b/mesonbuild/compilers/mixins/emscripten.py
@@ -76,7 +76,7 @@ class EmscriptenMixin(Compiler):
return wrap_js_includes(super().get_dependency_link_args(dep))
def find_library(self, libname: str, env: 'Environment', extra_dirs: T.List[str],
- libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True) -> T.Optional[T.List[str]]:
+ libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True, ignore_system_dirs: bool = False) -> T.Optional[T.List[str]]:
if not libname.endswith('.js'):
return super().find_library(libname, env, extra_dirs, libtype, lib_prefix_warning)
if os.path.isabs(libname):
diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py
index 9ea591e..ddcd14a 100644
--- a/mesonbuild/compilers/mixins/gnu.py
+++ b/mesonbuild/compilers/mixins/gnu.py
@@ -534,6 +534,8 @@ class GnuLikeCompiler(Compiler, metaclass=abc.ABCMeta):
# We want to allow preprocessing files with any extension, such as
# foo.c.in. In that case we need to tell GCC/CLANG to treat them as
# assembly file.
+ if self.language == 'fortran':
+ return self.get_preprocess_only_args()
lang = gnu_lang_map.get(self.language, 'assembler-with-cpp')
return self.get_preprocess_only_args() + [f'-x{lang}']
diff --git a/mesonbuild/compilers/mixins/pgi.py b/mesonbuild/compilers/mixins/pgi.py
index 50335c8..fddc837 100644
--- a/mesonbuild/compilers/mixins/pgi.py
+++ b/mesonbuild/compilers/mixins/pgi.py
@@ -54,6 +54,12 @@ class PGICompiler(Compiler):
def openmp_flags(self, env: Environment) -> T.List[str]:
return ['-mp']
+ def get_preprocess_only_args(self) -> T.List[str]:
+ return ['-E', '-P', '-o', '-']
+
+ def get_preprocess_to_file_args(self) -> T.List[str]:
+ return ['-E', '-P']
+
def get_optimization_args(self, optimization_level: str) -> T.List[str]:
return clike_optimization_args[optimization_level]
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index d0d2e69..5ebb093 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -5,7 +5,7 @@
from __future__ import annotations
import functools
-import subprocess, os.path
+import os.path
import textwrap
import re
import typing as T
@@ -141,17 +141,7 @@ class RustCompiler(Compiler):
if pc.returncode != 0:
raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.')
self._native_static_libs(work_dir, source_name)
- if self.is_cross:
- if not environment.has_exe_wrapper():
- # Can't check if the binaries run so we have to assume they do
- return
- cmdlist = environment.exe_wrapper.get_command() + [output_name]
- else:
- cmdlist = [output_name]
- pe = subprocess.Popen(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
- pe.wait()
- if pe.returncode != 0:
- raise EnvironmentException(f'Executables created by Rust compiler {self.name_string()} are not runnable.')
+ self.run_sanity_check(environment, [output_name], work_dir)
def _native_static_libs(self, work_dir: str, source_name: str) -> None:
# Get libraries needed to link with a Rust staticlib
@@ -192,10 +182,14 @@ class RustCompiler(Compiler):
return stdo.split('\n', maxsplit=1)[0]
@functools.lru_cache(maxsize=None)
- def get_crt_static(self) -> bool:
+ def get_cfgs(self) -> T.List[str]:
cmd = self.get_exelist(ccache=False) + ['--print', 'cfg']
p, stdo, stde = Popen_safe_logged(cmd)
- return bool(re.search('^target_feature="crt-static"$', stdo, re.MULTILINE))
+ return stdo.splitlines()
+
+ @functools.lru_cache(maxsize=None)
+ def get_crt_static(self) -> bool:
+ return 'target_feature="crt-static"' in self.get_cfgs()
def get_debug_args(self, is_debug: bool) -> T.List[str]:
return clike_debug_args[is_debug]
@@ -327,11 +321,11 @@ class RustCompiler(Compiler):
return exelist + args
def has_multi_arguments(self, args: T.List[str], env: Environment) -> T.Tuple[bool, bool]:
- return self.compiles('fn main { std::process::exit(0) };\n', env, extra_args=args, mode=CompileCheckMode.COMPILE)
+ return self.compiles('fn main() { std::process::exit(0) }\n', env, extra_args=args, mode=CompileCheckMode.COMPILE)
def has_multi_link_arguments(self, args: T.List[str], env: Environment) -> T.Tuple[bool, bool]:
args = self.linker.fatal_warnings() + args
- return self.compiles('fn main { std::process::exit(0) };\n', env, extra_args=args, mode=CompileCheckMode.LINK)
+ return self.compiles('fn main() { std::process::exit(0) }\n', env, extra_args=args, mode=CompileCheckMode.LINK)
@functools.lru_cache(maxsize=None)
def get_rustdoc(self, env: 'Environment') -> T.Optional[RustdocTestCompiler]:
diff --git a/mesonbuild/compilers/swift.py b/mesonbuild/compilers/swift.py
index 8410fbb..47d254b 100644
--- a/mesonbuild/compilers/swift.py
+++ b/mesonbuild/compilers/swift.py
@@ -8,7 +8,7 @@ import subprocess, os.path
import typing as T
from .. import mlog, options
-from ..mesonlib import EnvironmentException, MesonException, version_compare
+from ..mesonlib import first, MesonException, version_compare
from .compilers import Compiler, clike_debug_args
@@ -139,6 +139,12 @@ class SwiftCompiler(Compiler):
if std != 'none':
args += ['-swift-version', std]
+ # Pass C compiler -std=... arg to swiftc
+ c_lang = first(['objc', 'c'], lambda x: x in target.compilers)
+ if c_lang is not None:
+ cc = target.compilers[c_lang]
+ args.extend(arg for c_arg in cc.get_option_std_args(target, env, subproject) for arg in ['-Xcc', c_arg])
+
return args
def get_working_directory_args(self, path: str) -> T.Optional[T.List[str]]:
@@ -147,6 +153,12 @@ class SwiftCompiler(Compiler):
return ['-working-directory', path]
+ def get_cxx_interoperability_args(self, lang: T.Dict[str, Compiler]) -> T.List[str]:
+ if 'cpp' in lang or 'objcpp' in lang:
+ return ['-cxx-interoperability-mode=default']
+ else:
+ return ['-cxx-interoperability-mode=off']
+
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
build_dir: str) -> T.List[str]:
for idx, i in enumerate(parameter_list):
@@ -170,13 +182,7 @@ class SwiftCompiler(Compiler):
''')
pc = subprocess.Popen(self.exelist + extra_flags + ['-emit-executable', '-o', output_name, src], cwd=work_dir)
pc.wait()
- if pc.returncode != 0:
- raise EnvironmentException('Swift compiler %s cannot compile programs.' % self.name_string())
- if self.is_cross:
- # Can't check if the binaries run so we have to assume they do
- return
- if subprocess.call(output_name) != 0:
- raise EnvironmentException('Executables created by Swift compiler %s are not runnable.' % self.name_string())
+ self.run_sanity_check(environment, [output_name], work_dir)
def get_debug_args(self, is_debug: bool) -> T.List[str]:
return clike_debug_args[is_debug]
diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py
index 28861a6..bbaefed 100644
--- a/mesonbuild/compilers/vala.py
+++ b/mesonbuild/compilers/vala.py
@@ -113,7 +113,7 @@ class ValaCompiler(Compiler):
raise EnvironmentException(msg)
def find_library(self, libname: str, env: 'Environment', extra_dirs: T.List[str],
- libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True) -> T.Optional[T.List[str]]:
+ libtype: LibType = LibType.PREFER_SHARED, lib_prefix_warning: bool = True, ignore_system_dirs: bool = False) -> T.Optional[T.List[str]]:
if extra_dirs and isinstance(extra_dirs, str):
extra_dirs = [extra_dirs]
# Valac always looks in the default vapi dir, so only search there if