Skip to content

Feature request: Build a published crate as a RustExtension (for use with ctypes or cffi directly) #575

@dhdaines

Description

@dhdaines

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions