cython: wire up support for emitting and using depfiles

This solves rebuild issues when e.g. importing a .pxd header from a .pyx
file, just like C/C++ source headers. The transpiler needs to run again
in this case.

This functionality is present in the 3.0.0 alphas of cython, and is also
backported to 0.29.33.

Fixes #9049
pull/11369/head
Eli Schwartz 2 years ago
parent 6ea24ee9e2
commit 84dd78e80d
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 6
      mesonbuild/backend/ninjabackend.py
  2. 10
      mesonbuild/compilers/cython.py

@ -2234,10 +2234,14 @@ class NinjaBackend(backends.Backend):
description = 'Compiling Cython source $in'
command = compiler.get_exelist()
args = ['$ARGS', '$in']
depargs = compiler.get_dependency_gen_args('$out', '$DEPFILE')
depfile = '$out.dep' if depargs else None
args = depargs + ['$ARGS', '$in']
args += NinjaCommandArg.list(compiler.get_output_args('$out'), Quoting.none)
self.add_rule(NinjaRule(rule, command + args, [],
description,
depfile=depfile,
extra='restat = 1'))
def generate_rust_compile_rules(self, compiler):

@ -7,7 +7,7 @@ from __future__ import annotations
import typing as T
from .. import coredata
from ..mesonlib import EnvironmentException, OptionKey
from ..mesonlib import EnvironmentException, OptionKey, version_compare
from .compilers import Compiler
if T.TYPE_CHECKING:
@ -40,6 +40,14 @@ class CythonCompiler(Compiler):
# compiler might though
return []
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
if version_compare(self.version, '>=0.29.33'):
return ['-M']
return []
def get_depfile_suffix(self) -> str:
return 'dep'
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
code = 'print("hello world")'
with self.cached_compile(code, environment.coredata) as p:

Loading…
Cancel
Save