Upgrading UniFFI¶
The generated Kotlin has to match the FFI conventions of one exact UniFFI version. Upgrading is mostly a matter of porting what changed in the upstream Kotlin generator to the templates here.
Checklist¶
- Bump the versions.
uniffi,uniffi_bindgen,uniffi_macrosanduniffi_metain the workspaceCargo.toml, thencargo update -p uniffi. The bindgen is installed withcargo install --locked, soCargo.lockmust be committed in a working state. -
Diff the upstream Kotlin generator between the old and the new version, in a checkout of uniffi-rs:
bash git diff v0.32.0..v0.33.0 -- uniffi_bindgen/src/bindings/kotlinMost upstream templates have a counterpart in
bindgen/src/templates/generic/or in the runtime. Port each change, and remember that the runtime has three copies (see Runtime). 3. Check the FFI types. New or changedFfiTypevariants need a mapping inKotlinCodeOraclefor Kotlin (ffi_type_label) and for the C headers. Run a native build to make sure both agree. 4. CheckFFI_BUILTINSinmod.rsagainst the renamed or new FFI definitions that are identical for every crate (see Bindgen). 5. Check struct layouts that Kotlin declares by hand: the callback vtable field order, theForeignFuture*structs,RustBuffer,RustCallStatus. JNA declares these in Kotlin, so a layout change upstream doesn't cause a compile error. It only shows up as a crash. 6. Port new upstream fixtures fromfixtures/in uniffi-rs totests/uniffi/, and update the existing ones. 7. Build everything:cargo test,./gradlew build, and at least one Apple target locally. 8. Document it: requirements in the docs, the README, and consumer-facing migration notes inCHANGELOG.md.
Things that changed in past upgrades¶
These are the kinds of changes to look out for. All of them happened between 0.28 and 0.32:
- Objects changed from raw pointers to opaque
u64handles (0.30). Type::Externalwas removed. External types became a query on theComponentInterface(0.29).module_pathbecame a full module path instead of the crate name (0.31).- External metadata is attached to every
RustBuffer, not only to external ones (0.32). - Vtables gained a
cloneentry, andfreemoved to the front (0.30). - Foreign-future types were renamed (
ForeignFutureFree→ForeignFutureDroppedCallback, …). - The custom type keys in
uniffi.tomlwere renamed frominto_custom/from_customtolift/lower(0.29.1). Both are still accepted. - Methods and trait exports on records and enums were added (0.31).