Skip to content

Commit b914910

Browse files
authored
Merge pull request #4 from chavic/chavic/enums
small conflict with the UniFFI version resolved
2 parents 7da8279 + 7ba74b7 commit b914910

File tree

22 files changed

+483
-142
lines changed

22 files changed

+483
-142
lines changed

Cargo.toml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ description = "Dart Frontend for UniFFI"
99
[features]
1010
defaults = []
1111
binary = []
12-
build = [
13-
"dep:uniffi_build",
14-
]
12+
build = ["dep:uniffi_build"]
1513
bindgen-tests = [
1614
"dep:uniffi_testing",
1715
"dep:camino-tempfile",
@@ -36,21 +34,24 @@ proc-macro2 = "1.0.66"
3634
anyhow = "1"
3735
paste = "1"
3836
heck = "0.4.1"
39-
uniffi = "0.23.0"
40-
uniffi_bindgen = "0.23.0"
41-
camino ="1"
37+
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
38+
"build",
39+
] }
40+
uniffi_bindgen = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6" }
41+
camino = "1"
4242
serde = "1"
4343
toml = "0.5"
4444
genco = "0.17.5"
4545

4646
# feature specific stuff
47-
uniffi_build = { version = "0.23.0", optional = true }
47+
uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", optional = true }
48+
49+
# optional for testint
50+
uniffi_testing = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", optional = true }
4851

49-
# optional for testing
50-
uniffi_testing = { version = "0.23.0", optional = true }
5152
fs_extra = { version = "1.3.0", optional = true }
5253
camino-tempfile = { version = "1.0.2", optional = true }
53-
glob = { version = "0.3.1", optional = true}
54+
glob = { version = "0.3.1", optional = true }
5455

5556
[workspace]
5657

@@ -59,4 +60,4 @@ members = [
5960

6061
# for testing
6162
"fixtures/*",
62-
]
63+
]

fixtures/arithmetic/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ name = "simple_arithmetic"
1111
crate-type = ["lib", "cdylib"]
1212

1313
[dependencies]
14-
uniffi = "0.23.0"
14+
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6" }
1515

1616
[build-dependencies]
17-
uniffi-dart = { path = "../../", features = ["build"] }
17+
uniffi-dart = { path = "../../", features = ["build"] }
1818

1919
[dev-dependencies]
2020
uniffi-dart = { path = "../../", features = ["bindgen-tests"] }
21-
anyhow = "1"
21+
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
22+
"bindgen-tests",
23+
] }
24+
anyhow = "1"

fixtures/arithmetic/src/lib.rs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,68 @@
11
use uniffi;
22

33
#[uniffi::export]
4-
pub fn add(left: u32, right: u32) -> u32 {
5-
left + right
4+
pub fn add(left: u32, right: u32) -> Option<u32> {
5+
Some(left + right)
66
}
77

88
#[uniffi::export]
9-
pub fn multiply(left: u32, right: u32) -> u32 {
10-
left * right
9+
pub fn multiply(left: u32, right: u32) -> Option<u32> {
10+
Some(left * right)
1111
}
1212

13-
// #[uniffi::export]
14-
// pub fn devide(left: u32, right: u32) -> Option<u32> {
15-
// left.checked_div(right)
16-
// }
13+
#[uniffi::export]
14+
pub fn devide(left: u32, right: u32) -> Option<u32> {
15+
Some(left / right)
16+
}
17+
18+
#[uniffi::export]
19+
pub fn devide_checked(left: u32, right: u32) -> Option<u32> {
20+
left.checked_div(right)
21+
}
22+
23+
#[uniffi::export]
24+
pub fn add_u8(left: u8, right: u8) -> Option<u8> {
25+
Some(left + right)
26+
}
27+
28+
#[uniffi::export]
29+
pub fn add_u16(left: u16, right: u16) -> Option<u16> {
30+
Some(left + right)
31+
}
1732

1833
#[uniffi::export]
19-
pub fn add_u8(left: u8, right: u8) -> u8 {
20-
left + right
34+
pub fn add_u64(left: u64, right: u64) -> Option<u64> {
35+
Some(left + right)
2136
}
2237

2338
#[uniffi::export]
24-
pub fn add_u16(left: u16, right: u16) -> u16 {
25-
left + right
39+
pub fn add_i8(left: i8, right: i8) -> Option<i8> {
40+
Some(left + right)
2641
}
2742

2843
#[uniffi::export]
29-
pub fn add_u64(left: u64, right: u64) -> u64 {
30-
left + right
44+
pub fn add_i16(left: i16, right: i16) -> Option<i16> {
45+
Some(left + right)
3146
}
3247

3348
#[uniffi::export]
34-
pub fn add_i8(left: i8, right: i8) -> i8 {
35-
left + right
49+
pub fn add_i32(left: i32, right: i32) -> Option<i32> {
50+
Some(left + right)
3651
}
3752

3853
#[uniffi::export]
39-
pub fn add_i16(left: i16, right: i16) -> i16 {
40-
left + right
54+
pub fn add_i64(left: i64, right: i64) -> Option<i64> {
55+
Some( left + right)
4156
}
4257

4358
#[uniffi::export]
44-
pub fn add_i32(left: i32, right: i32) -> i32 {
45-
left + right
59+
pub fn add_f32(left: f32, right: f32) -> Option<f32> {
60+
Some(left + right)
4661
}
4762

4863
#[uniffi::export]
49-
pub fn add_i64(left: i64, right: i64) -> i64 {
50-
left + right
64+
pub fn add_f64(left: f64, right: f64) -> Option<f64> {
65+
Some(left + right)
5166
}
5267

5368
include!(concat!(env!("OUT_DIR"), "/api.uniffi.rs"));

fixtures/arithmetic/test/simple_arithmetic_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ void main() {
99
test('2 * 8 = 16', () {
1010
expect(api.multiply(2, 8), 16);
1111
});
12+
test('2 / 8 = 0', () {
13+
expect(api.devideChecked(2, 8), 0);
14+
});
15+
test('8 / 0 = null', () {
16+
expect(api.devideChecked(8, 0), null);
17+
});
18+
test('8 / 2 = 4', () {
19+
expect(api.devide(8, 2), 4);
20+
});
1221
test('u8', () {
1322
expect(api.addU8(2, 2), 4);
1423
});
@@ -31,4 +40,10 @@ void main() {
3140
test('i64', () {
3241
expect(api.addI64(2, 2), 4);
3342
});
43+
test('f32', () {
44+
expect(api.addF32(2.0, 2.0), 4.0);
45+
});
46+
test('f64', () {
47+
expect(api.addF64(2.0, 2.9), 4.9);
48+
});
3449
}

fixtures/arithmetic/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ use anyhow::Result;
22

33
#[test]
44
fn simple_arithmetic() -> Result<()> {
5-
uniffi_dart::testing::run_test("simple_arithmetic")
5+
uniffi_dart::testing::run_test("simple_arithmetic", "src/api.udl", None)
66
}

fixtures/hello_world/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ publish = false
1010
name = "hello_world"
1111
crate-type = ["lib", "cdylib"]
1212

13+
1314
[dependencies]
14-
uniffi = "0.23.0"
15+
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
16+
"build",
17+
] }
1518

1619
[build-dependencies]
17-
uniffi-dart = { path = "../../", features = ["build"] }
20+
uniffi-dart = { path = "../../", features = ["build"] }
1821

1922
[dev-dependencies]
2023
uniffi-dart = { path = "../../", features = ["bindgen-tests"] }
24+
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
25+
"bindgen-tests",
26+
] }
2127
anyhow = "1"

fixtures/hello_world/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ use anyhow::Result;
22

33
#[test]
44
fn hello_world() -> Result<()> {
5-
uniffi_dart::testing::run_test("hello_world")
5+
uniffi_dart::testing::run_test("hello_world", "src/api.udl", None)
66
}

fixtures/large_enum/Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "large_enum"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
9+
[lib]
10+
name = "large_enum"
11+
crate-type = ["lib", "cdylib"]
12+
13+
[dependencies]
14+
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
15+
"build",
16+
] }
17+
18+
[build-dependencies]
19+
uniffi-dart = { path = "../../", features = ["build"] }
20+
21+
[dev-dependencies]
22+
uniffi-dart = { path = "../../", features = ["bindgen-tests"] }
23+
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
24+
"bindgen-tests",
25+
] }
26+
anyhow = "1"

fixtures/large_enum/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
uniffi_dart::generate_scaffolding("./src/api.udl".into()).unwrap();
3+
}

fixtures/large_enum/src/api.udl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
namespace large_enum {};

0 commit comments

Comments
 (0)