Skip to content

Unable to use external dependency with uniffi #2459

Open
@dignifiedquire

Description

@dignifiedquire

Bug Description

I am trying to use an external package in python bindings, and it almost works, but not quite unfortunately.

  • package a: iroh-ffi
  • package b: iroh-ffi-gossip
# iroh-ffi/Cargo.toml
[package]
name = "iroh-ffi"

# ..

[lib]
name = "iroh_ffi"
crate-type = ["staticlib", "cdylib", "rlib"]

[package.metadata.maturin]
name = "iroh"
# iroh-ffi/uniffi.toml
[bindings.python]
cdylib_name = "iroh_ffi"
# iroh-gossip/Cargo.toml

[package]
name = "iroh-ffi-gossip"

# ..

[package.metadata.maturin]
name = "iroh_gossip"

[lib]
name = "iroh_ffi_gossip"
crate-type = ["staticlib", "cdylib"]
# iroh-gossip/uniffi.toml
[bindings.python]
cdylib_name = "iroh_ffi_gossip"

[bindings.python.external_packages]
iroh_ffi = "iroh"

When I now generate the bindings using maturin, I end up with the following __init__.py

from .iroh_ffi import *  # NOQA
from .iroh_ffi_gossip import *  # NOQA

as well as the following files

ls .venv/lib/python3.13/site-packages/iroh_gossip/
__init__.py              iroh_ffi.py              libiroh_ffi_gossip.dylib
__pycache__              iroh_ffi_gossip.py

This will fail, because there is no matching dylib for iroh_ffi, so running this will explode. Commenting out the from .iroh_ffi import * fixes the issue, as all imports in iroh_ffi_gossip.py are correctly pointing to iroh.

Now what I would like to have is to simply depend on the iroh python package, but due to the unecessary inclusions of its ffi code the generation is currently broken

Your maturin version (maturin --version)

1.8.1

Your Python version (python -V)

3.13.1

Your pip version (pip -V)

24.3.1

What bindings you're using

uniffi

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bindings/uniffiuniffi bindingsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions