Skip to content

Comments

Add installation of data-files build artifacts into Python package#574

Open
jakelishman wants to merge 1 commit intoPyO3:mainfrom
jakelishman:data-files
Open

Add installation of data-files build artifacts into Python package#574
jakelishman wants to merge 1 commit intoPyO3:mainfrom
jakelishman:data-files

Conversation

@jakelishman
Copy link
Contributor

This allows a RustExtension to "own" some data files, produced programmatically as part of its build.rs script, and for these to be installed along with the built extension module somewhere into the Python package tree. The motivating example use is an extension module that provides a C API, and generates the header file needed to access it and a function-pointer table in a PyCapsule as part of its build script; the header file ideally should be installed as a regular file inside the Python wheel, so the package can be used as a build dependency.


I've written in a basic example to use as a test case because I didn't want to just to immediately writing something like the cbindgen-based setup that motivated this work from my side. I got repeatedly bitten by TOML 1.0 (what Python's tomllib stdlib library can handle) not supporting newlines in inline tables when trying to write the data-files key! But happily there's syntax that works, even with the array-of-tables form there.

I'm not convinced by the logic around universal2 handling, but I also can't entirely see the use case for generated files and universal2 other than only needing one copy, so maybe what I've done is overkill.

I was able to use this logic entirely successfully with my own downstream package (Qiskit/qiskit#15711, though the code there is much more involved).

Close #563.

This allows a `RustExtension` to "own" some data files, produced
programmatically as part of its `build.rs` script, and for these to be
installed along with the built extension module somewhere into the
Python package tree.  The motivating example use is an extension module
that provides a C API, and generates the header file needed to access
it and a function-pointer table in a `PyCapsule` as part of its build
script; the header file ideally should be installed as a regular file
inside the Python wheel, so the package can be used as a build
dependency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Options for extracting data files from a RustExtension's build-script OUT_DIR

1 participant