Add installation of data-files build artifacts into Python package#574
Open
jakelishman wants to merge 1 commit intoPyO3:mainfrom
Open
Add installation of data-files build artifacts into Python package#574jakelishman wants to merge 1 commit intoPyO3:mainfrom
jakelishman wants to merge 1 commit intoPyO3:mainfrom
Conversation
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.
This was referenced Feb 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows a
RustExtensionto "own" some data files, produced programmatically as part of itsbuild.rsscript, 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 aPyCapsuleas 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'stomllibstdlib library can handle) not supporting newlines in inline tables when trying to write thedata-fileskey! But happily there's syntax that works, even with the array-of-tables form there.I'm not convinced by the logic around
universal2handling, 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.