-
Notifications
You must be signed in to change notification settings - Fork 21
Support uniffi 0.32 #149
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
base: main
Are you sure you want to change the base?
Support uniffi 0.32 #149
Changes from all commits
68c673b
e03cb41
abfab4c
5877058
cff6510
b8f788d
da65f67
b9cfbae
50afc12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ edition = "2021" | |
| license = "Apache-2 or MIT" | ||
| homepage = "https://github.com/acterglobal/uniffi-dart" | ||
| description = "Dart Frontend for UniFFI" | ||
| rust-version = "1.85" | ||
| rust-version = "1.91" | ||
|
|
||
| [features] | ||
| defaults = [] | ||
|
|
@@ -38,7 +38,13 @@ uniffi_bindgen = { workspace = true } | |
| camino = "1" | ||
| cargo_metadata = "0.18" | ||
| serde = "1" | ||
| toml = ">=0.8, <=0.9" | ||
| # Match uniffi_bindgen 0.32's own toml: its `BindingGenerator::new_config` takes | ||
| # `&toml::Value`, so our impl must resolve the SAME toml version or the trait | ||
| # signature mismatches (E0053). uniffi_bindgen 0.32.0 declares `toml = ">=0.9, | ||
| # <2"` and resolves to 1.x, so pin `toml = "1"`; a looser pin lets the resolver | ||
| # put us on 0.9 while uniffi stays on 1.x (splitting the crate) — which has no | ||
| # committed Cargo.lock to stabilize it, so CI re-resolves and breaks. | ||
| toml = "1" | ||
| genco = "0.17.5" | ||
| proc-macro2 = "1.0.66" | ||
|
|
||
|
|
@@ -82,12 +88,13 @@ members = [ | |
| "fixtures/proc-macro", | ||
| "fixtures/proc-macro-no-implicit-prelude", | ||
| "fixtures/enum_variant_collision", | ||
| "fixtures/map_type", | ||
| #"fixtures/*", | ||
| ] | ||
|
|
||
| [workspace.dependencies] | ||
| uniffi = { version = "0.31.2" } | ||
| uniffi_bindgen = { version = "0.31.2" } | ||
| uniffi_build = { version = "0.31.2" } | ||
| uniffi_testing = { version = "0.31.2" } | ||
| uniffi = { version = "0.32" } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following up on BeyondTranslate: it tracks Just flagging the downstream impact here. We don't need to hold this PR for a change in their repo. After we merge, a follow-up PR pinning their generator to a compatible revision would be kind; then they can move to 0.32 separately. |
||
| uniffi_bindgen = { version = "0.32" } | ||
| uniffi_build = { version = "0.32" } | ||
| uniffi_testing = { version = "0.32" } | ||
| camino = { version = "1.1" } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [package] | ||
| name = "map_type" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [lib] | ||
| name = "map_type" | ||
| crate-type = ["lib", "cdylib"] | ||
|
|
||
| [dependencies] | ||
| uniffi = { workspace = true, features = [ | ||
| "build", | ||
| ] } | ||
|
|
||
| [build-dependencies] | ||
| uniffi-dart = { path = "../../", features = ["build"] } | ||
|
|
||
| [dev-dependencies] | ||
| uniffi-dart = { path = "../../", features = ["bindgen-tests"] } | ||
| uniffi = { workspace = true, features = [ | ||
| "bindgen-tests", | ||
| ] } | ||
| anyhow = "1" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| fn main() { | ||
| uniffi_dart::generate_scaffolding("./src/api.udl".into()).unwrap(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| namespace map_type { }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| use std::collections::HashMap; | ||
|
|
||
| // Minimal Map<K, V> round-trip surface. Mirrors how our qdrant-edge-ffi crate | ||
| // exposes payload/config maps: plain proc-macro exports over HashMap<String, _>. | ||
|
|
||
| #[uniffi::export] | ||
| pub fn roundtrip_map(m: HashMap<String, i32>) -> HashMap<String, i32> { | ||
| m | ||
| } | ||
|
|
||
| #[uniffi::export] | ||
| pub fn count_entries(m: HashMap<String, i32>) -> u32 { | ||
| m.len() as u32 | ||
| } | ||
|
|
||
| #[uniffi::export] | ||
| pub fn map_with_record_values(m: HashMap<String, Point>) -> HashMap<String, Point> { | ||
| m | ||
| } | ||
|
|
||
| // Variable-length value converters (nested Map, Option) are what stress the Map | ||
| // FfiConverter's offset arithmetic — a fixed-size value (i32/Point) can't reveal | ||
| // a drifting offset. These mirror real payload shapes: string -> nested/nullable. | ||
|
|
||
| #[uniffi::export] | ||
| pub fn roundtrip_nested_map( | ||
| m: HashMap<String, HashMap<String, i32>>, | ||
| ) -> HashMap<String, HashMap<String, i32>> { | ||
| m | ||
| } | ||
|
|
||
| #[uniffi::export] | ||
| pub fn roundtrip_optional_map(m: HashMap<String, Option<i32>>) -> HashMap<String, Option<i32>> { | ||
| m | ||
| } | ||
|
|
||
| #[derive(uniffi::Record, Clone)] | ||
| pub struct Point { | ||
| x: i64, | ||
| y: i64, | ||
| } | ||
|
|
||
| uniffi::include_scaffolding!("api"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import 'package:test/test.dart'; | ||
| import '../map_type.dart'; | ||
|
|
||
| void main() { | ||
| test('map roundtrip preserves entries', () { | ||
| final m = {'a': 1, 'b': 2}; | ||
| final out = roundtripMap(m: m); | ||
| expect(out['a'], 1); | ||
| expect(out['b'], 2); | ||
| expect(out.length, 2); | ||
| }); | ||
|
|
||
| test('map count', () { | ||
| expect(countEntries(m: {'x': 10, 'y': 20, 'z': 30}), 3); | ||
| }); | ||
|
|
||
| test('map with record values', () { | ||
| final out = mapWithRecordValues(m: {'origin': Point(x: 0, y: 0), 'unit': Point(x: 1, y: 1)}); | ||
| expect(out['unit']!.x, 1); | ||
| expect(out['unit']!.y, 1); | ||
| expect(out.length, 2); | ||
| }); | ||
|
|
||
| test('nested map round-trips (variable-length values)', () { | ||
| final out = roundtripNestedMap(m: { | ||
| 'a': {'x': 1, 'y': 2}, | ||
| 'b': {'z': 3}, | ||
| }); | ||
| expect(out['a']!['x'], 1); | ||
| expect(out['a']!['y'], 2); | ||
| expect(out['b']!['z'], 3); | ||
| expect(out.length, 2); | ||
| }); | ||
|
|
||
| test('map with optional values round-trips (null preserved, distinct from absent)', () { | ||
| final out = roundtripOptionalMap(m: {'present': 7, 'absent': null}); | ||
| expect(out['present'], 7); | ||
| expect(out['absent'], null); | ||
| expect(out.containsKey('absent'), true); | ||
| expect(out.length, 2); | ||
| }); | ||
|
|
||
| test('empty map round-trips at the length-0 boundary', () { | ||
| expect(roundtripMap(m: {}), isEmpty); | ||
| expect(countEntries(m: {}), 0); | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| use anyhow::Result; | ||
|
|
||
| #[test] | ||
| fn map_type() -> Result<()> { | ||
| uniffi_dart::testing::run_test("map_type", "src/api.udl", None) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current BDK script uses
cargo build --lockedandcargo run --locked, so deleting the lockfile here leaves it unable to run.Please regenerate the lockfile after applying the patches and before calling the script. I reproduced the failure without that step; with it, the unchanged script proceeds.