mozilla / uniffi-rs

a multi-language bindings generator for rust
https://mozilla.github.io/uniffi-rs/
Mozilla Public License 2.0
2.82k stars 231 forks source link

Config feature and Export macros don't get along #2122

Open pacu opened 5 months ago

pacu commented 5 months ago

uniffi = "0.27.0"

Problem: cfg(feature = ) and uniffi::export macros don't get along

context:

I'm working on this FROST signatures wrapper with uniffi. https://github.com/pacu/frost-mobile-sdk

I can build the FROST dependency with or without the redpallas feature flag. That would change some arguments on the FFI exposed to the client.

#[uniffi::export]
pub fn aggregate(
    signing_package: FrostSigningPackage, 
    signature_shares: Vec<FrostSignatureShare>,
    pubkey_package: FrostPublicKeyPackage,
    #[cfg(feature = "redpallas")]
    randomizer: FrostRandomizer,
) -> Result<FrostSignature, CoordinationError> 

This works fine if I build the project with the redpallas feature enabled. But it fails when I don't enable it.

error[E0061]: this function takes 3 arguments but 4 arguments were supplied
   --> frost-mobile-sdk/src/coordinator.rs:106:8
    |
105 | #[uniffi::export]
    | ----------------- unexpected argument
106 | pub fn aggregate(
    |        ^^^^^^^^^

Is this expected as a limitation of uniffi? or is it real problem?

possibly related:

https://github.com/mozilla/uniffi-rs/issues/2000

rafaelbeckel commented 5 months ago

It's not exactly related to the other issue. In my understanding, you are changing the function signature when you do not enable the feature (you remove the 4th parameter), so you have to add the same #[cfg()] annotation in the caller's 4th argument to remove it too.