diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2021-06-07 23:29:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-07 23:29:30 +0300 |
commit | 40e8a67a837c4184ef02fa90eae05ef39f4b2199 (patch) | |
tree | 1d408f46ab94e1b24cecc1b86f2513ccaa5e7da9 /mesonbuild/compilers/cython.py | |
parent | d53ea7da2d3f40ca2ddcce229c4db28b904832fe (diff) | |
parent | 0bc18f26a21ea0c1ad06e131e872cec2cc6022a4 (diff) | |
download | meson-40e8a67a837c4184ef02fa90eae05ef39f4b2199.zip meson-40e8a67a837c4184ef02fa90eae05ef39f4b2199.tar.gz meson-40e8a67a837c4184ef02fa90eae05ef39f4b2199.tar.bz2 |
Merge pull request #8706 from dcbaker/wip/2021-04/cython-language
1st class Cython language support
Diffstat (limited to 'mesonbuild/compilers/cython.py')
-rw-r--r-- | mesonbuild/compilers/cython.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/mesonbuild/compilers/cython.py b/mesonbuild/compilers/cython.py new file mode 100644 index 0000000..513f079 --- /dev/null +++ b/mesonbuild/compilers/cython.py @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright © 2021 Intel Corporation + +"""Abstraction for Cython language compilers.""" + +import typing as T + +from .. import coredata +from ..mesonlib import EnvironmentException, OptionKey +from .compilers import Compiler + +if T.TYPE_CHECKING: + from ..coredata import KeyedOptionDictType + from ..environment import Environment + + +class CythonCompiler(Compiler): + + """Cython Compiler.""" + + language = 'cython' + id = 'cython' + + def needs_static_linker(self) -> bool: + # We transpile into C, so we don't need any linker + return False + + def get_always_args(self) -> T.List[str]: + return ['--fast-fail'] + + def get_werror_args(self) -> T.List[str]: + return ['-Werror'] + + def get_output_args(self, outputname: str) -> T.List[str]: + return ['-o', outputname] + + def get_optimization_args(self, optimization_level: str) -> T.List[str]: + # Cython doesn't have optimization levels itself, the underlying + # compiler might though + return [] + + def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + code = 'print("hello world")' + with self.cached_compile(code, environment.coredata) as p: + if p.returncode != 0: + raise EnvironmentException(f'Cython compiler {self.id!r} cannot compile programs') + + def get_buildtype_args(self, buildtype: str) -> T.List[str]: + # Cython doesn't implement this, but Meson requires an implementation + return [] + + def get_pic_args(self) -> T.List[str]: + # We can lie here, it's fine + return [] + + def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], + build_dir: str) -> T.List[str]: + new: T.List[str] = [] + for i in parameter_list: + new.append(i) + + return new + + def get_options(self) -> 'KeyedOptionDictType': + opts = super().get_options() + opts.update({ + OptionKey('version', machine=self.for_machine, lang=self.language): coredata.UserComboOption( + 'Python version to target', + ['2', '3'], + '3', + ) + }) + return opts + + def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: + args: T.List[str] = [] + key = options[OptionKey('version', machine=self.for_machine, lang=self.language)] + args.append(f'-{key.value}') + return args |