Skip to content

Commit

Permalink
Initial replacing *.udl with use of Uniffi proc macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Binlogo committed Jul 24, 2024
1 parent 375ea1a commit 2caee21
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 189 deletions.
3 changes: 0 additions & 3 deletions examples/hello_world/shared/build.rs

This file was deleted.

9 changes: 5 additions & 4 deletions examples/hello_world/shared/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
uniffi::setup_scaffolding!();

pub mod app; // not exposed so you can remove this in your project

use lazy_static::lazy_static;
Expand All @@ -7,24 +9,23 @@ pub use crux_core::{bridge::Bridge, Core, Request};

pub use app::*;

// TODO hide this plumbing

uniffi::include_scaffolding!("shared");

lazy_static! {
static ref CORE: Bridge<Effect, Hello> = Bridge::new(Core::new());
}

#[uniffi::export]
#[wasm_bindgen]
pub fn process_event(data: &[u8]) -> Vec<u8> {
CORE.process_event(data)
}

#[uniffi::export]
#[wasm_bindgen]
pub fn handle_response(id: u32, data: &[u8]) -> Vec<u8> {
CORE.handle_response(id, data)
}

#[uniffi::export]
#[wasm_bindgen]
pub fn view() -> Vec<u8> {
CORE.view()
Expand Down
5 changes: 0 additions & 5 deletions examples/hello_world/shared/src/shared.udl

This file was deleted.

3 changes: 3 additions & 0 deletions examples/simple_counter/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[alias]
uniffi-gen-swift = "run --bin uniffi-bindgen generate --library target/release/libshared.dylib --language swift --out-dir shared/generated/swift/SharedFFI"
uniffi-gen-java = "run --bin uniffi-bindgen generate --library target/release/libshared.dylib --language kotlin --out-dir shared/generated/java"
12 changes: 6 additions & 6 deletions examples/simple_counter/Android/shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ android {
}

sourceSets {
main.java.srcDirs += "${projectDir}/../../shared_types/generated/java"
main.java.srcDirs += "${projectDir}/../../shared/generated/java"
}
}

Expand Down Expand Up @@ -83,16 +83,16 @@ afterEvaluate {
}

tasks.register('bindGen', Exec) {
def outDir = "${projectDir}/../../shared_types/generated/java"
def outDir = "${projectDir}/../../shared/generated/java"
workingDir "../../"
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
commandLine("cmd", "/c",
"cargo build -p shared && " + "target\\debug\\uniffi-bindgen generate shared\\src\\shared.udl " + "--language kotlin " + "--out-dir " + outDir.replace('/', '\\'))
"cargo build -p shared && " + "target\\debug\\uniffi-bindgen generate --library target\\debug\\libshared.dylib " + "--language kotlin " + "--out-dir " + outDir.replace('/', '\\'))
} else {
commandLine("sh", "-c",
"""\
cargo build -p shared && \
target/debug/uniffi-bindgen generate shared/src/shared.udl \
target/debug/uniffi-bindgen generate --library target/debug/libshared.dylib \
--language kotlin \
--out-dir $outDir
""")
Expand All @@ -102,8 +102,8 @@ tasks.register('bindGen', Exec) {
tasks.register('typesGen', Exec) {
workingDir "../../"
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
commandLine("cmd", "/c", "cargo build -p shared_types")
commandLine("cmd", "/c", "cargo test -p shared --features typegen")
} else {
commandLine("sh", "-c", "cargo build -p shared_types")
commandLine("sh", "-c", "cargo test -p shared --features typegen")
}
}
65 changes: 18 additions & 47 deletions examples/simple_counter/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/simple_counter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["shared", "shared_types", "web-dioxus", "web-leptos", "web-yew"]
members = ["shared", "web-dioxus", "web-leptos", "web-yew"]
resolver = "1"

[workspace.package]
Expand All @@ -15,6 +15,7 @@ anyhow = "1.0.86"
crux_core = "0.8"
# crux_core = { path = "../../crux_core" }
serde = "1.0.203"
uniffi = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }

[workspace.metadata.bin]
cargo-xcode = { version = "=1.7.0" }
Loading

0 comments on commit 2caee21

Please sign in to comment.