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

UniFFI Dart Binding Generator Refactor and Added Async Support #37

Merged
merged 67 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
6a7b32f
initial code structure
chavic Jun 29, 2024
237eda2
partial code moved
chavic Jun 29, 2024
c1d38f2
moved code to mod
chavic Jun 29, 2024
b24ff15
brinig back oracle methods
chavic Jun 29, 2024
b5b747c
moved and unified primitives code
chavic Jun 29, 2024
b18fb7c
bring funtion method with async
chavic Jun 29, 2024
ee42b5a
bring object with async
chavic Jun 29, 2024
636fc32
cleared types errors
chavic Jun 29, 2024
ef6e24b
bringing back futures test
chavic Jun 29, 2024
4c4e49d
build "Api api" removal
chavic Jun 29, 2024
e78dd47
prep for static methods
chavic Jun 29, 2024
b9c8f72
using static methods
chavic Jun 29, 2024
54f47a6
build api api removal
chavic Jun 29, 2024
ca12242
removed api
chavic Jun 29, 2024
f20a80f
added duration and record
chavic Jun 29, 2024
d34fa6c
renamed toIntList
chavic Jun 29, 2024
41c6495
using static for primitives
chavic Jun 29, 2024
59f0942
added map test
chavic Jun 29, 2024
eeb2193
removed api
chavic Jun 29, 2024
6e07adf
removed api
chavic Jun 29, 2024
238132b
direct converion
chavic Jun 29, 2024
266ca5e
removed api
chavic Jun 29, 2024
043afb1
removed comment error
chavic Jun 29, 2024
43e21d1
moved code
chavic Jun 29, 2024
69ed1b6
uncommented tests
chavic Jul 1, 2024
d332784
bringing back all tests
chavic Jul 1, 2024
33904ee
using all tests
chavic Jul 1, 2024
0d9d75f
removed unrequired code
chavic Jul 1, 2024
fe577f1
Minimal mergable futures example
chavic May 31, 2024
6c6ad72
additional tests
gnunicorn May 31, 2024
fa6de2a
Callable for methods, too
gnunicorn May 31, 2024
40a355e
Simplifications and cleaning up
gnunicorn May 31, 2024
e597797
fix lints
gnunicorn Jun 4, 2024
ae187f1
Minor docs and CI fixes
gnunicorn Jun 4, 2024
a7a6da5
fix overeagerness
gnunicorn Jun 4, 2024
05df85c
first merge attempt
chavic Jul 4, 2024
3ee0bce
minor fix for lookup function gen and error buffer
chavic Jul 4, 2024
17e694a
initial code structure
chavic Jun 29, 2024
56a7bd3
moved and unified primitives code
chavic Jun 29, 2024
43c67d0
bring funtion method with async
chavic Jun 29, 2024
c6daa4b
bring object with async
chavic Jun 29, 2024
a2c7408
cleared types errors
chavic Jun 29, 2024
9decbbe
added duration and record
chavic Jun 29, 2024
2338f31
using static for primitives
chavic Jun 29, 2024
3e21679
moved code
chavic Jun 29, 2024
5d19f43
fixed merge errors
chavic Jul 13, 2024
c6d2967
updated duration test
chavic Jul 13, 2024
5d4acdb
bringing back usefull comment
chavic Jul 15, 2024
a52d906
removed unused code
chavic Jul 15, 2024
0e4cf91
fixed string literal render
chavic Jul 15, 2024
5b40b9c
updated
chavic Jul 16, 2024
2ffceb6
deleted useless file
chavic Jul 15, 2024
588dde7
code unused comments
chavic Jul 15, 2024
38d7f4f
back fixme reminder comment
chavic Jul 30, 2024
8d15738
added test headsup
chavic Jul 30, 2024
f930128
first merge attempt
chavic Jul 4, 2024
9127884
minor fix for lookup function gen and error buffer
chavic Jul 4, 2024
0b5ab56
Merge branch 'merging-refactors-diverging-branches'
chavic Jul 30, 2024
77479a7
squashed histories to quickly update upstream
chavic Jul 30, 2024
9ec8e66
revered new buffer offset
chavic Aug 21, 2024
4f85c67
formatted code
chavic Aug 21, 2024
87d9836
commented out unused code
chavic Aug 21, 2024
3ce1c17
formatted
chavic Aug 21, 2024
4303237
changed to use version 1.75
chavic Aug 25, 2024
10355be
skipping
chavic Aug 25, 2024
0658365
cleaned up useless comments
chavic Aug 25, 2024
6f7baac
formatted
chavic Aug 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
rust:
- stable
- "1.74"
- "1.75"
- nightly
steps:
- name: Checkout sources
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
matrix:
rust:
- stable
- "1.74"
- "1.75"
- nightly
steps:
- name: Checkout sources
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Dart frontend for UniFFI bindings

Reference: [TODOs](./TODO.md)

## MSRV: 1.74
## MSRV: 1.75

This project must always work on latest stable rust + version before. We are also testing it against 1.1.70.0 , which we consider the Minimum Support Rust Version (MSRV) at this point. Rust lower than that will probably not compile the project.

Expand Down
41 changes: 20 additions & 21 deletions fixtures/arithmetic/test/simple_arithmetic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,67 @@ import 'package:test/test.dart';
import '../simple_arithmetic.dart';

void main() {
final api = Api.load();
test('2 + 2 = 4', () {
expect(api.add(2, 2), 4);
expect(add(2, 2), 4);
});
test('2 * 8 = 16', () {
expect(api.multiply(2, 8), 16);
expect(multiply(2, 8), 16);
});
test('2 / 8 = 0', () {
expect(api.divideChecked(2, 8), 0);
expect(divideChecked(2, 8), 0);
});
test('8 / 0 = null', () {
expect(api.divideChecked(8, 0), null);
expect(divideChecked(8, 0), null);
});
test('8 / 2 = 4', () {
expect(api.divide(8, 2), 4);
expect(divide(8, 2), 4);
});
test('u8', () {
expect(api.addU8(2, 2), 4);
expect(addU8(2, 2), 4);
});
test('u16', () {
expect(api.addU16(2, 2), 4);
expect(addU16(2, 2), 4);
});
test('u64', () {
expect(api.addU64(2, 2), 4);
expect(addU64(2, 2), 4);
});

test('i8', () {
expect(api.addI8(2, 2), 4);
expect(addI8(2, 2), 4);
});
test('i16', () {
expect(api.addI16(2, 2), 4);
expect(addI16(2, 2), 4);
});
test('i32', () {
expect(api.addI32(2, 2), 4);
expect(addI32(2, 2), 4);
});
test('i64', () {
expect(api.addI64(2, 2), 4);
expect(addI64(2, 2), 4);
});
test('f32', () {
expect(api.addF32(2.0, 2.0), 4.0);
expect(addF32(2.0, 2.0), 4.0);
});
test('f64', () {
expect(api.addF64(2.0, 2.9), 4.9);
expect(addF64(2.0, 2.9), 4.9);
});

test('get back u8', () {
expect(api.getBackU8(4), 4);
expect(getBackU8(4), 4);
});
test('get back u16', () {
expect(api.getBackU16(4), 4);
expect(getBackU16(4), 4);
});
test('get back u64', () {
expect(api.getBackU64(4), 4);
expect(getBackU64(4), 4);
});

test('get back i8', () {
expect(api.getBackI8(4), 4);
expect(getBackI8(4), 4);
});
test('get back f32', () {
expect(api.getBackF32(4.0), 4.0);
expect(getBackF32(4.0), 4.0);
});
test('get back f64', () {
expect(api.getBackF64(4.9), 4.9);
expect(getBackF64(4.9), 4.9);
});
}
23 changes: 11 additions & 12 deletions fixtures/duration_type_test/test/duration_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@ import 'package:test/test.dart';
import '../duration_type_test.dart';

void main() {
final api = Api.load();
test('rust return value seconds check', () {
final duration = api.makeDuration(5, 0);
final duration = makeDuration(5, 0);

expect(duration.inSeconds, 5);
expect(api.getSeconds(duration), 5);
expect(api.getNanos(duration), 0);
expect(getSeconds(duration), 5);
expect(getNanos(duration), 0);
});

test('seconds data check from dart', () {
final duration = Duration(seconds: 10);
expect(api.getSeconds(duration), 10);
expect(api.getNanos(duration), 0);
expect(getSeconds(duration), 10);
expect(getNanos(duration), 0);
});

test('check nanos/micros', () {
final duration = api.makeDuration(0, 3000);
final duration = makeDuration(0, 3000);
expect(duration.inSeconds, 0);
expect(duration.inMicroseconds, 3);
expect(api.getSeconds(duration), 0);
expect(api.getNanos(duration), 3000);
expect(getSeconds(duration), 0);
expect(getNanos(duration), 3000);
});

test('check large values', () {
final duration = api.makeDuration(123456789, 3000000);
final duration = makeDuration(123456789, 3000000);
expect(duration.inSeconds, 123456789);
expect(duration.inMicroseconds, 123456789003000);
expect(api.getSeconds(duration), 123456789);
expect(api.getNanos(duration), 3000000);
expect(getSeconds(duration), 123456789);
expect(getNanos(duration), 3000000);
});
}
1 change: 1 addition & 0 deletions fixtures/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ crate-type = ["lib", "cdylib"]
[dependencies]
uniffi = { workspace = true, features = ["tokio"]}
tokio = { version = "1.24.1", features = ["time"] }
thiserror = "1.0"

[build-dependencies]
uniffi-dart = { path = "../../", features = ["build"] }
Expand Down
34 changes: 17 additions & 17 deletions fixtures/futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl TimerFuture {
}
}

// /// Non-blocking timer future.
/// Non-blocking timer future.
pub struct BrokenTimerFuture {
shared_state: Arc<Mutex<SharedState>>,
}
Expand Down Expand Up @@ -152,29 +152,29 @@ pub async fn sleep(ms: u16) -> bool {
}

// Our error.
// #[derive(uniffi::Error, Debug)]
// pub enum MyError {
// Foo,
// }

// // An async function that can throw.
// // An async function that can throw.
// #[uniffi::export]
// pub async fn fallible_me(do_fail: bool) -> Result<u8, MyError> {
// if do_fail {
// Err(MyError::Foo)
// } else {
// Ok(42)
// }
// }
#[derive(thiserror::Error, uniffi::Error, Debug)]
pub enum MyError {
#[error("Foo")]
Foo,
}

// An async function that can throw.
#[uniffi::export]
pub async fn fallible_me(do_fail: bool) -> Result<u8, MyError> {
if do_fail {
Err(MyError::Foo)
} else {
Ok(42)
}
}

#[uniffi::export(async_runtime = "tokio")]
pub async fn say_after_with_tokio(ms: u16, who: String) -> String {
tokio::time::sleep(Duration::from_millis(ms.into())).await;
format!("Hello, {who} (with Tokio)!")
}

#[derive(uniffi::Record, Clone)]
#[derive(uniffi::Record)]
pub struct MyRecord {
pub a: String,
pub b: u32,
Expand Down
Loading
Loading