Skip to content

Commit

Permalink
cython: wire up support for emitting and using depfiles
Browse files Browse the repository at this point in the history
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 mesonbuild#9049
  • Loading branch information
eli-schwartz committed Feb 9, 2023
1 parent 56e6118 commit 0a44f94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,10 +2234,17 @@ def generate_cython_compile_rules(self, compiler: 'Compiler') -> None:
description = 'Compiling Cython source $in'
command = compiler.get_exelist()

args = ['$ARGS', '$in']
depargs = compiler.get_dependency_gen_args('$out', '$DEPFILE')
if depargs:
depfile = '$out.dep'
else:
depfile = 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):
Expand Down
10 changes: 9 additions & 1 deletion mesonbuild/compilers/cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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:
Expand Down Expand Up @@ -40,6 +40,14 @@ def get_optimization_args(self, optimization_level: str) -> T.List[str]:
# 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:
Expand Down

0 comments on commit 0a44f94

Please sign in to comment.