Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating FFI bindings for dependent crates into one single Swift / Kotlin file? #2117

Closed
imWildCat opened this issue May 19, 2024 · 4 comments

Comments

@imWildCat
Copy link

Hello!

I'm wondering whether this can also be achieve using the current version of uniffi. If not, I would love to contribute.

I'd like to generate types from a dependency of my cargo workspace.

I notice that under the current fixtures folder, if I run

It will generate multiple swift files with same setup:

cargo run --features=uniffi/cli --bin uniffi-fixtures-futures generate  -l swift -o ./tmp --library 'path/to/uniffi-rs/target/debug/libuniffi_ext_types_lib.dylib' 
private extension RustBuffer {
    // Allocate a new buffer, copying the contents of a `UInt8` array.
    init(bytes: [UInt8]) {
        let rbuf = bytes.withUnsafeBufferPointer { ptr in
            RustBuffer.from(ptr)
        }
        self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
    }

    static func empty() -> RustBuffer {
        RustBuffer(capacity: 0, len: 0, data: nil)
    }
➜  tmp git:(main) ✗ ls
custom_types.swift                 ext_types_customFFI.h              imported_types_sublib.swift        uniffi_one_nsFFI.h
custom_typesFFI.h                  ext_types_customFFI.modulemap      imported_types_sublibFFI.h         uniffi_one_nsFFI.modulemap
custom_typesFFI.modulemap          imported_types_lib.swift           imported_types_sublibFFI.modulemap
customtypes                        imported_types_libFFI.h            uniffi
ext_types_custom.swift             imported_types_libFFI.modulemap    uniffi_one_ns.swift

this would be a conflict.

Is there any method to "merge" these generated files into a single Swift source file?

@mhammond
Copy link
Member

It's not currently possible, but on the latest main it would be much easier to make changes to allow that than on earlier versions.

It will generate multiple swift files with same setup:
this would be a conflict.

This shouldn't be a problem as RustBuffer is private - many of our fixtures (and production use) rely on this working, most notably ext-types

@imWildCat
Copy link
Author

thanks! how about Kotlin in this case?

@imWildCat imWildCat closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
@mhammond
Copy link
Member

thanks! how about Kotlin in this case?

Same. As mentioned above though, while things do work, there might be an opportunity to clean some of these things up - I don't think that the way swift generates things today is necessarily ideal - eg, I'm not sure we need one modulemap per generated source file etc.

@imWildCat
Copy link
Author

I see. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants