Feature request: Build a published crate as a RustExtension (for use with `ctypes` or `cffi` directly)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 680
- Forks
- 110
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 1
Description
Hopefully I haven't missed something and this isn't already possible (perhaps with some invocation of maturin that I didn't see in the documentation?)...
It would be nice to be able to create a Python package which contains no actual Rust code of its own but simply builds a publicly available crate (which exports a C interface) and calls into it with ctypes. This may be a bit of a niche use case? I am using it with https://crates.io/crates/rustfst-ffi/1.2.6 because the upstream mantainers, while they publish a Python package, don't publish it as a source distribution and so it can only be installed from PyPI on platforms for which a binary exists.
Now obviously you shouldn't do that. So, I've found a somewhat ugly hack, which is to simply create an empty library with the desired crate as a dependency, then copy the shared library for the dependency instead of the built library (which, obviously, exports none of its dependency's symbols). This is done by monkey-patching setuptools_rust.setuptools_ext.rust_extensions in an in-tree build backend: https://github.com/dhdaines/rustfst/blob/standalone_python/_backend/rustfst_backend/build_meta.py
Not being an expert in Rust I don't know if this works on all platforms or if there's a better way to do it. But I think it would be relatively easy to add this as an option to RustExtension, perhaps, source_package, which would do what the hack above does.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the cited _backend/rustfst_backend/build_meta.py hack and the setuptools_rust.setuptools_ext.rust_extensions entry point. Determine how a RustExtension could build a published dependency and expose its shared library across supported platforms, then define completion around a source_package option that supports the ctypes or cffi use case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100