-
Notifications
You must be signed in to change notification settings - Fork 263
Description
(@bendk asked me to create an issue )
Following up on my comment in 2087, using UniFFI with a Workspace works well in the land of Rust - especially with the new system for remote / custom / external types laid out in #2087.
However, when one generates Swift bindings, no cigar, the Swift code in each file tries to reference (file)private
symbols such as lift
/lower` on types in the other file - which are not visible. The Kotlin bindings, however, does seem to work. The Kotlin Bindgen test in my small UniFFI Workspace demo project Lemon Meringue Pie passes. I have not tried doing an actual Kotlin bindgen generation besides the bindgen test.
The Python bindings seems broken, for the small Python Bindgen tests in Lemon Meringue Pie, I get error:
from .common import Uuid
ImportError: attempted relative import with no known parent package
We cannot simply change the access modifier to internal
in the generated Swift code since each generated Swift file contains the same types, such as fileprivate protocol FfiConverterRustBuffer
.
In this issue I lay out a straightforward idea on how to fix the broken Swift bindings specifically. I do not know enough about Python to lay out a plan for it, but perhaps the say idea is viable also for Python?
Idea of solution for Swift bindings
My idea is to:
- All generated Converters will be placed in separate files, in lets call it
generated/
folder (as specified by--out-dir
), and only be generated once, i.e. the contents oftemplate/StringHelper.swift
will be putGenerated/ScaffoldingUniFFI
folder - The actual type -
fileprivate struct FfiConverterString: FfiConverter
- gets a changed visibility tointernal struct
instead offileprivate
. - All protocols, types, functions and methods in
RustBufferTemplate
(and similar templates) get changed visibility tointernal
too - Bindgen code for a single crate only contain the author written UniFFI code in one file per crate, places in
Generated/Foo
,Generated/Bar
,Generated/Buzz
, whereFoo
,Bar
, `Buzz are the names of each of the users UniFFI exported crates.
This is a straightforward solution which should not involve too much changes here in UniFFI.
The only downside of this solution I can think of is that some users of UniFFI might need to migrate their build scripts from mv $out/Foobar.swift
to `mv $out/Generated (or similar).