PyO3 / maturin

Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages
https://maturin.rs
Apache License 2.0
3.66k stars 249 forks source link

Compile UniFFI interfaces defined in sibling libraries #2090

Open Nickersoft opened 3 months ago

Nickersoft commented 3 months ago

Hey folks,

I'm currently trying to adopt Maturin in my monorepo, which is attempting to use UniFFI to export FFI interfaces for Kotlin and Python from a shared Rust crate (odict). The core library is setup to use FFI, and upon compiling will produce a .py file in the target directory:

CleanShot 2024-05-20 at 14 46 38@2x

However, because Maturin expects you to be building your UniFFI interface from the current project, it's looking for pyodict.py (the Python library/binding where I'm using Maturin).

This file doesn't exist and causes an error:

CleanShot 2024-05-20 at 14 48 10@2x

I'd love it if Maturin would allow you to create wheels from shared FFIs like this, instead of forcing you to keep it all in a single project. I combed the docs but couldn't find a way to do this. Hopefully I'm not missing something.

messense commented 3 months ago

Unfortunately the generated python file name can only be inferred from cdylib_name config in uniffi.toml so you'd need to change it to odict to match the .py file.

Nickersoft commented 3 months ago

Hey @messense, thanks for the response. I had a uniffi.toml, but I think I had my config wrong. That said, I just replaced it (python/uniffi.toml) with this:

[bindings.python]
cdylib_name = "odict"

and running Maturin it's still looking for pyodict. Is there something else I need to do?

messense commented 3 months ago

Can you try change this to odict as well?

https://github.com/TheOpenDictionary/odict/blob/ffbfacb6e531421ef6a9cafbe852e321e2b666ce/python/Cargo.toml#L7

Nickersoft commented 3 months ago

So I actually tried that, and I believe Rust complains if there are two crates that produce libraries with the same name. Away from my keyboard at the moment, but I can safely say it errored and failed to build when I tried that :/

Nickersoft commented 2 months ago

@messense Any further suggestions? 🥺