maturin icon indicating copy to clipboard operation
maturin copied to clipboard

Compile UniFFI interfaces defined in sibling libraries

Open Nickersoft opened this issue 1 year ago • 5 comments

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.

Nickersoft avatar May 20 '24 21:05 Nickersoft

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.

messense avatar May 21 '24 11:05 messense

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?

Nickersoft avatar May 21 '24 16:05 Nickersoft

Can you try change this to odict as well?

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

messense avatar May 24 '24 01:05 messense

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 avatar May 24 '24 05:05 Nickersoft

@messense Any further suggestions? 🥺

Nickersoft avatar Jun 15 '24 21:06 Nickersoft