diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 619bf7c97cae..92d9bdd958eb 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2234,10 +2234,14 @@ 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') + 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): diff --git a/mesonbuild/compilers/cython.py b/mesonbuild/compilers/cython.py index 763279eb73c8..9bbfebeb0ef9 100644 --- a/mesonbuild/compilers/cython.py +++ b/mesonbuild/compilers/cython.py @@ -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: @@ -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: