diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-08-24 09:20:03 -0700 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2021-09-24 22:56:46 +0300 |
commit | 68c23a61203fc35dd11c7a0b1cc13f7cc2c5cf8c (patch) | |
tree | 5afe315e41b55e8b12f3b1b56d75bfd766620cae /mesonbuild/build.py | |
parent | 524a95fa62a6e0cb77e53d7b38d5c2d59a75e449 (diff) | |
download | meson-68c23a61203fc35dd11c7a0b1cc13f7cc2c5cf8c.zip meson-68c23a61203fc35dd11c7a0b1cc13f7cc2c5cf8c.tar.gz meson-68c23a61203fc35dd11c7a0b1cc13f7cc2c5cf8c.tar.bz2 |
Add option to to transpile Cython to C++
This patch adds a new meson built-in option for cython, allowing it to
target C++ instead of C as the intermediate language. This can, of
course, be done on a per-target basis using the `override_options`
keyword argument, or for the entire project in the project function.
There are some things in this patch that are less than ideal. One of
them is that we have to add compilers in the build layer, but there
isn't a better place to do it because of per target override_options.
There's also some design differences between Meson and setuptools, in
that Meson only allows options on a per-target rather than a per-file
granularity.
Fixes #9015
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r-- | mesonbuild/build.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index b5fa8ea..1498415 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -37,7 +37,7 @@ from .mesonlib import ( ) from .compilers import ( Compiler, is_object, clink_langs, sort_clink, lang_suffixes, - is_known_suffix, detect_static_linker + is_known_suffix, detect_static_linker, detect_compiler_for ) from .linkers import StaticLinker from .interpreterbase import FeatureNew @@ -833,8 +833,40 @@ class BuildTarget(Target): # If all our sources are Vala, our target also needs the C compiler but # it won't get added above. - if ('vala' in self.compilers or 'cython' in self.compilers) and 'c' not in self.compilers: + if 'vala' in self.compilers and 'c' not in self.compilers: self.compilers['c'] = compilers['c'] + if 'cython' in self.compilers: + key = OptionKey('language', machine=self.for_machine, lang='cython') + if key in self.option_overrides_compiler: + value = self.option_overrides_compiler[key] + else: + value = self.environment.coredata.options[key].value + + try: + self.compilers[value] = compilers[value] + except KeyError: + # TODO: it would be nice to not have to do this here, but we + # have two problems to work around: + # 1. If this is set via an override we have no way to know + # before now that we need a compiler for the non-default language + # 2. Because Cython itself initializes the `cython_language` + # option, we have no good place to insert that you need it + # before now, so we just have to do it here. + comp = detect_compiler_for(self.environment, value, self.for_machine) + + # This is copied verbatim from the interpreter + if self.for_machine == MachineChoice.HOST or self.environment.is_cross_build(): + logger_fun = mlog.log + else: + logger_fun = mlog.debug + logger_fun(comp.get_display_language(), 'compiler for the', self.for_machine.get_lower_case_name(), 'machine:', + mlog.bold(' '.join(comp.get_exelist())), comp.get_version_string()) + if comp.linker is not None: + logger_fun(comp.get_display_language(), 'linker for the', self.for_machine.get_lower_case_name(), 'machine:', + mlog.bold(' '.join(comp.linker.get_exelist())), comp.linker.id, comp.linker.version) + if comp is None: + raise MesonException(f'Cannot find required compiler {value}') + self.compilers[value] = comp def validate_sources(self): if not self.sources: |