Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cython depfile support #11369

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
eli-schwartz committed Feb 10, 2023
commit 84dd78e80d7e9db1febf6a0016730e2ab6f7a352
6 changes: 5 additions & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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