Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ description = "Dart Frontend for UniFFI"
[features]
defaults = []
binary = []
build = [
"dep:uniffi_build",
]
build = ["dep:uniffi_build"]
bindgen-tests = [
"dep:uniffi_testing",
"dep:camino-tempfile",
Expand All @@ -36,21 +34,24 @@ proc-macro2 = "1.0.66"
anyhow = "1"
paste = "1"
heck = "0.4.1"
uniffi = "0.23.0"
uniffi_bindgen = "0.23.0"
camino ="1"
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
"build",
] }
uniffi_bindgen = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6" }
camino = "1"
serde = "1"
toml = "0.5"
genco = "0.17.5"

# feature specific stuff
uniffi_build = { version = "0.23.0", optional = true }
uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", optional = true }

# optional for testint
uniffi_testing = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", optional = true }

# optional for testing
uniffi_testing = { version = "0.23.0", optional = true }
fs_extra = { version = "1.3.0", optional = true }
camino-tempfile = { version = "1.0.2", optional = true }
glob = { version = "0.3.1", optional = true}
glob = { version = "0.3.1", optional = true }

[workspace]

Expand All @@ -59,4 +60,4 @@ members = [

# for testing
"fixtures/*",
]
]
9 changes: 6 additions & 3 deletions fixtures/arithmetic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ name = "simple_arithmetic"
crate-type = ["lib", "cdylib"]

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

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

[dev-dependencies]
uniffi-dart = { path = "../../", features = ["bindgen-tests"] }
anyhow = "1"
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
"bindgen-tests",
] }
anyhow = "1"
59 changes: 37 additions & 22 deletions fixtures/arithmetic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,68 @@
use uniffi;

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

#[uniffi::export]
pub fn multiply(left: u32, right: u32) -> u32 {
left * right
pub fn multiply(left: u32, right: u32) -> Option<u32> {
Some(left * right)
}

// #[uniffi::export]
// pub fn devide(left: u32, right: u32) -> Option<u32> {
// left.checked_div(right)
// }
#[uniffi::export]
pub fn devide(left: u32, right: u32) -> Option<u32> {
Some(left / right)
}

#[uniffi::export]
pub fn devide_checked(left: u32, right: u32) -> Option<u32> {
left.checked_div(right)
}

#[uniffi::export]
pub fn add_u8(left: u8, right: u8) -> Option<u8> {
Some(left + right)
}

#[uniffi::export]
pub fn add_u16(left: u16, right: u16) -> Option<u16> {
Some(left + right)
}

#[uniffi::export]
pub fn add_u8(left: u8, right: u8) -> u8 {
left + right
pub fn add_u64(left: u64, right: u64) -> Option<u64> {
Some(left + right)
}

#[uniffi::export]
pub fn add_u16(left: u16, right: u16) -> u16 {
left + right
pub fn add_i8(left: i8, right: i8) -> Option<i8> {
Some(left + right)
}

#[uniffi::export]
pub fn add_u64(left: u64, right: u64) -> u64 {
left + right
pub fn add_i16(left: i16, right: i16) -> Option<i16> {
Some(left + right)
}

#[uniffi::export]
pub fn add_i8(left: i8, right: i8) -> i8 {
left + right
pub fn add_i32(left: i32, right: i32) -> Option<i32> {
Some(left + right)
}

#[uniffi::export]
pub fn add_i16(left: i16, right: i16) -> i16 {
left + right
pub fn add_i64(left: i64, right: i64) -> Option<i64> {
Some( left + right)
}

#[uniffi::export]
pub fn add_i32(left: i32, right: i32) -> i32 {
left + right
pub fn add_f32(left: f32, right: f32) -> Option<f32> {
Some(left + right)
}

#[uniffi::export]
pub fn add_i64(left: i64, right: i64) -> i64 {
left + right
pub fn add_f64(left: f64, right: f64) -> Option<f64> {
Some(left + right)
}

include!(concat!(env!("OUT_DIR"), "/api.uniffi.rs"));
15 changes: 15 additions & 0 deletions fixtures/arithmetic/test/simple_arithmetic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ void main() {
test('2 * 8 = 16', () {
expect(api.multiply(2, 8), 16);
});
test('2 / 8 = 0', () {
expect(api.devideChecked(2, 8), 0);
});
test('8 / 0 = null', () {
expect(api.devideChecked(8, 0), null);
});
test('8 / 2 = 4', () {
expect(api.devide(8, 2), 4);
});
test('u8', () {
expect(api.addU8(2, 2), 4);
});
Expand All @@ -31,4 +40,10 @@ void main() {
test('i64', () {
expect(api.addI64(2, 2), 4);
});
test('f32', () {
expect(api.addF32(2.0, 2.0), 4.0);
});
test('f64', () {
expect(api.addF64(2.0, 2.9), 4.9);
});
}
2 changes: 1 addition & 1 deletion fixtures/arithmetic/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use anyhow::Result;

#[test]
fn simple_arithmetic() -> Result<()> {
uniffi_dart::testing::run_test("simple_arithmetic")
uniffi_dart::testing::run_test("simple_arithmetic", "src/api.udl", None)
}
10 changes: 8 additions & 2 deletions fixtures/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ publish = false
name = "hello_world"
crate-type = ["lib", "cdylib"]


[dependencies]
uniffi = "0.23.0"
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
"build",
] }

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

[dev-dependencies]
uniffi-dart = { path = "../../", features = ["bindgen-tests"] }
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
"bindgen-tests",
] }
anyhow = "1"
2 changes: 1 addition & 1 deletion fixtures/hello_world/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use anyhow::Result;

#[test]
fn hello_world() -> Result<()> {
uniffi_dart::testing::run_test("hello_world")
uniffi_dart::testing::run_test("hello_world", "src/api.udl", None)
}
26 changes: 26 additions & 0 deletions fixtures/large_enum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "large_enum"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


[lib]
name = "large_enum"
crate-type = ["lib", "cdylib"]

[dependencies]
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
"build",
] }

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

[dev-dependencies]
uniffi-dart = { path = "../../", features = ["bindgen-tests"] }
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "8565b7f941e7967778efd39c5ab27551dfa23ec6", features = [
"bindgen-tests",
] }
anyhow = "1"
3 changes: 3 additions & 0 deletions fixtures/large_enum/build.rs
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();
}
1 change: 1 addition & 0 deletions fixtures/large_enum/src/api.udl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace large_enum {};
Loading