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
available in an unreleased maintenance branch of 0.29 -- see
cython/cython#5158
  • Loading branch information
eli-schwartz committed Dec 1, 2022
1 parent f6f3090 commit c5a764d
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 @@ -2216,10 +2216,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 @@ -6,7 +6,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 @@ -39,6 +39,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, '>=3.0.0'):

This comment has been minimized.

Copy link
@dnicolodi

dnicolodi Jan 11, 2023

depfile support has been releases in Cython 0.29.33, see cython/cython#5158. It would be nice to have this patch land in Meson!

This comment has been minimized.

Copy link
@eli-schwartz

eli-schwartz Jan 11, 2023

Author Owner

Thank you (great news!), I will take a look at this.

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 c5a764d

Please sign in to comment.