Skip to content

Cython dependency handling in .pxd and .pxi files #9049

@ev-br

Description

@ev-br

Describe the bug

Cython has a notion of implementation source files (.pyx), declaration files (.pxd) and literal include files (.pxi). The distinction is similar to .c and .h files in C. The current syntax for tracking changes in declaration and include files is clumsy, especially for the cython->c++ transpile.

To Reproduce

In the current master branch, to specify a cython->c++ transile for a source with a .pyx and a .pxd file, depend_files argument to custom_target works (thanks to @rgommers for pointing this out). Here is an example where the implementation is split between observable.pxd and observable.pyx (https://github.com/ev-br/mc_lib/blob/master/mc_lib/meson.build):

# compile .cpp for the `observable` module
_observable_cpp = custom_target('observable_cpp',
  output : 'observable.cpp',
  input : 'observable.pyx',
  depend_files: 'observable.pxd',     # <---- this
  command : [cython, '--cplus', '-3', '--fast-fail', '@INPUT@', '-o', '@OUTPUT@']
)

# generate .so for observable
py3.extension_module(
  'observable', _observable_cpp,
  include_directories: inc_np,
  dependencies : [py3_dep],
  install: true,
  subdir: 'mc_lib'
)

With gh-9017, the syntax is greatly simplified:

# generate .so for the `observable` extension
py3.extension_module(
  'observable', 'observable.pyx',
  include_directories: inc_np,
  dependencies : py3_dep,
  override_options : ['cython_language=cpp'],   # <-----  no need for a custom_target, yay!
  install: true,
  subdir: 'mc_lib',
)

However, this does not track changes in observable.pxd. To reproduce the problem: compile once, introduce a syntax error into observable.pxd, try recompiling ( I did $ meson install -C build, but a direct ninja invocation would do) --- ninja does not see a syntax error:

ninja: Entering directory `/home/br/sweethome/proj/mc_lib/builddir'
ninja: no work to do.

Expected behavior

Expected behavior is that a change in a pxd or pxi file triggers a rebuild of a dependent extension module: similar to what happens for the .c / .h pairs. Either automatically, or via a simple meson.build syntax to declare a dependency.

system parameters

Native build on ubuntu focal, python 3.8.10,
$ meson --version
0.59.99
$ ninja --version
1.10.2.git.kitware.jobserver-1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions