From 89f4f7ebca3216d1dade77d1b3ebd47facc5eb66 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Sat, 21 Jan 2023 14:31:17 +0800 Subject: [PATCH] sparate android + ios build targets --- Cargo.lock | Bin 188854 -> 189050 bytes Cargo.toml | 2 +- apps/mobile/rust/Cargo.toml | 39 ------ apps/mobile/rust/android/Cargo.toml | 19 +++ apps/mobile/rust/android/src/lib.rs | 105 +++++++++++++++++ apps/mobile/rust/ios/Cargo.toml | 21 ++++ apps/mobile/rust/ios/src/lib.rs | 79 +++++++++++++ apps/mobile/rust/mobile/Cargo.toml | 26 ++++ apps/mobile/rust/mobile/src/lib.rs | 106 +++++++++++++++++ apps/mobile/rust/src/android.rs | 177 ---------------------------- apps/mobile/rust/src/ios.rs | 139 ---------------------- apps/mobile/rust/src/lib.rs | 31 ----- 12 files changed, 357 insertions(+), 387 deletions(-) delete mode 100644 apps/mobile/rust/Cargo.toml create mode 100644 apps/mobile/rust/android/Cargo.toml create mode 100644 apps/mobile/rust/android/src/lib.rs create mode 100644 apps/mobile/rust/ios/Cargo.toml create mode 100644 apps/mobile/rust/ios/src/lib.rs create mode 100644 apps/mobile/rust/mobile/Cargo.toml create mode 100644 apps/mobile/rust/mobile/src/lib.rs delete mode 100644 apps/mobile/rust/src/android.rs delete mode 100644 apps/mobile/rust/src/ios.rs delete mode 100644 apps/mobile/rust/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 81db9b4165ada53b84f21dbe2842c40d17026acd..af40c8c2f90f701891cb5fc5600161574124359b 100644 GIT binary patch delta 110 zcmdmXnETfe?uIRlHNV*t^HPfPGgBsi3>TR$|C3QzEGsWlNry{8sW?S9Ilm}XH#a{i zGbeR=Vg-{L7fdWOfBHc+Mp3Ya>5K0&YI4J5fU2hl+B3>dFZs>rxc%90#tTmYHwP-g delta 36 ucmV+<0Neli#0$2=3xKo%eEXMi`~f)wYHn$lp4|a1mo{(#4!5}c0m9`%l@S~O diff --git a/Cargo.toml b/Cargo.toml index 698c9a4d0..edd9b02ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ # "crates/p2p/tunnel/utils", "apps/cli", "apps/desktop/src-tauri", - "apps/mobile/rust", + "apps/mobile/rust/*", "apps/server", ] diff --git a/apps/mobile/rust/Cargo.toml b/apps/mobile/rust/Cargo.toml deleted file mode 100644 index c7cf918b0..000000000 --- a/apps/mobile/rust/Cargo.toml +++ /dev/null @@ -1,39 +0,0 @@ -[package] -name = "sd-core-mobile" -version = "0.1.0" -edition = "2021" -rust-version = "1.64.0" - -[lib] -crate-type = ["staticlib", "cdylib"] # staticlib for IOS and cdylib for Android - -[dependencies] -once_cell = "1.15.0" -sd-core = { path = "../../../core", features = [ - "mobile", - "p2p", -], default-features = false } -rspc = { workspace = true } -serde_json = "1.0.85" -tokio = "1.21.2" -openssl = { version = "0.10.42", features = [ - "vendored", -] } # Override features of transitive dependencies -openssl-sys = { version = "0.9.76", features = [ - "vendored", -] } # Override features of transitive dependencies to support IOS Simulator on M1 -futures = "0.3.24" -tracing = "0.1.37" - -[target.'cfg(target_os = "ios")'.dependencies] -objc = "0.2.7" -objc_id = "0.1.1" -objc-foundation = "0.1.1" - -# This is `not(ios)` instead of `android` because of https://github.com/mozilla/rust-android-gradle/issues/93 -[target.'cfg(not(target_os = "ios"))'.dependencies] -jni = "0.19.0" - -[target.'cfg(not(target_os = "ios"))'.features] -default = ["sd-core/android"] - diff --git a/apps/mobile/rust/android/Cargo.toml b/apps/mobile/rust/android/Cargo.toml new file mode 100644 index 000000000..01c488c76 --- /dev/null +++ b/apps/mobile/rust/android/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "sd-core-android" +version = "0.1.0" +edition = "2021" +rust-version = "1.64.0" + +[lib] +# Android can use dynamic linking since all FFI is done via JNI +crate-type = ["cdylib"] + +[dependencies] +# FFI +jni = "0.19.0" + +# Core mobile handling stuff +sd-core-mobile = { path = "../mobile", features = ["android"] } + +# Other +tracing = "0.1.37" diff --git a/apps/mobile/rust/android/src/lib.rs b/apps/mobile/rust/android/src/lib.rs new file mode 100644 index 000000000..b92d6b80a --- /dev/null +++ b/apps/mobile/rust/android/src/lib.rs @@ -0,0 +1,105 @@ +use std::panic; + +use jni::{ + objects::{JClass, JObject, JString}, + JNIEnv, +}; + +use sd_core_mobile::*; + +use tracing::error; + +#[no_mangle] +pub extern "system" fn Java_com_spacedrive_app_SDCore_registerCoreEventListener( + env: JNIEnv, + class: JClass, +) { + let result = panic::catch_unwind(|| { + let jvm = env.get_java_vm().unwrap(); + let class = env.new_global_ref(class).unwrap(); + + spawn_core_event_listener(move |data| { + let env = jvm.attach_current_thread().unwrap(); + env.call_method( + &class, + "sendCoreEvent", + "(Ljava/lang/String;)V", + &[env + .new_string(data) + .expect("Couldn't create java string!") + .into()], + ) + .unwrap(); + }) + }); + + if let Err(err) = result { + // TODO: Send rspc error or something here so we can show this in the UI. + // TODO: Maybe reinitialise the core cause it could be in an invalid state? + println!( + "Error in Java_com_spacedrive_app_SDCore_registerCoreEventListener: {:?}", + err + ); + } +} + +#[no_mangle] +pub extern "system" fn Java_com_spacedrive_app_SDCore_handleCoreMsg( + env: JNIEnv, + class: JClass, + query: JString, + callback: JObject, +) { + let result = panic::catch_unwind(|| { + let jvm = env.get_java_vm().unwrap(); + + let query: String = env + .get_string(query) + .expect("Couldn't get java string!") + .into(); + + let class = env.new_global_ref(class).unwrap(); + let callback = env.new_global_ref(callback).unwrap(); + + let data_directory = { + let env = jvm.attach_current_thread().unwrap(); + let data_dir = env + .call_method(&class, "getDataDirectory", "()Ljava/lang/String;", &[]) + .unwrap() + .l() + .unwrap(); + + env.get_string(data_dir.into()).unwrap().into() + }; + + handle_core_msg(query, data_directory, move |result| match result { + Ok(data) => { + let env = jvm.attach_current_thread().unwrap(); + env.call_method( + &callback, + "resolve", + "(Ljava/lang/Object;)V", + &[env + .new_string(data) + .expect("Couldn't create java string!") + .into()], + ) + .unwrap(); + } + Err(_) => { + // TODO: handle error + } + }); + }); + + if let Err(err) = result { + // TODO: Send rspc error or something here so we can show this in the UI. + // TODO: Maybe reinitialise the core cause it could be in an invalid state? + + // TODO: This log statement doesn't work. I recon the JNI env is being dropped before it's called. + error!( + "Error in Java_com_spacedrive_app_SDCore_registerCoreEventListener: {:?}", + err + ); + } +} diff --git a/apps/mobile/rust/ios/Cargo.toml b/apps/mobile/rust/ios/Cargo.toml new file mode 100644 index 000000000..db1732346 --- /dev/null +++ b/apps/mobile/rust/ios/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "sd-core-ios" +version = "0.1.0" +edition = "2021" + +rust-version = "1.64.0" + +[lib] +# iOS requires static linking +# Makes sense considering this lib needs to link against call_resolve and get_data_directory, +# which are only available when linking against the app's ObjC +crate-type = ["staticlib"] + +[dependencies] +# FFI +objc = "0.2.7" +objc_id = "0.1.1" +objc-foundation = "0.1.1" + +# Core mobile handling stuff +sd-core-mobile = { path = "../mobile" } diff --git a/apps/mobile/rust/ios/src/lib.rs b/apps/mobile/rust/ios/src/lib.rs new file mode 100644 index 000000000..f94531e5f --- /dev/null +++ b/apps/mobile/rust/ios/src/lib.rs @@ -0,0 +1,79 @@ +use std::{ + ffi::{CStr, CString}, + os::raw::{c_char, c_void}, + panic, +}; + +use objc::{msg_send, runtime::Object, sel, sel_impl}; +use objc_foundation::{INSString, NSString}; +use objc_id::Id; + +use sd_core_mobile::*; + +extern "C" { + fn get_data_directory() -> *const c_char; + fn call_resolve(resolve: *const c_void, result: *const c_char); +} + +// This struct wraps the function pointer which represent a Javascript Promise. We wrap the +// function pointers in a struct so we can unsafely assert to Rust that they are `Send`. +// We know they are send as we have ensured Objective-C won't deallocate the function pointer +// until `call_resolve` is called. +struct RNPromise(*const c_void); + +unsafe impl Send for RNPromise {} + +impl RNPromise { + // resolve the promise + unsafe fn resolve(self, result: CString) { + call_resolve(self.0, result.as_ptr()); + } +} + +#[no_mangle] +pub unsafe extern "C" fn register_core_event_listener(id: *mut Object) { + let result = panic::catch_unwind(|| { + let id = Id::::from_ptr(id); + + spawn_core_event_listener(move |data| { + let data = NSString::from_str(&data); + let _: () = msg_send![id, sendCoreEvent: data]; + }); + }); + + if let Err(err) = result { + // TODO: Send rspc error or something here so we can show this in the UI. + // TODO: Maybe reinitialise the core cause it could be in an invalid state? + println!("Error in register_core_event_listener: {:?}", err); + } +} + +#[no_mangle] +pub unsafe extern "C" fn sd_core_msg(query: *const c_char, resolve: *const c_void) { + let result = panic::catch_unwind(|| { + // This string is cloned to the Rust heap. This is important as Objective-C may remove the query once this function completions but prior to the async block finishing. + let query = CStr::from_ptr(query).to_str().unwrap().to_string(); + + let resolve = RNPromise(resolve); + + let data_directory = CStr::from_ptr(get_data_directory()) + .to_str() + .unwrap() + .to_string(); + + handle_core_msg(query, data_directory, |result| { + match result { + Ok(data) => resolve.resolve(CString::new(data).unwrap()), + Err(_) => { + // TODO: handle error + } + } + }); + }); + + if let Err(err) = result { + // TODO: Send rspc error or something here so we can show this in the UI. + // TODO: Maybe reinitialise the core cause it could be in an invalid state? + println!("Error in sd_core_msg: {:?}", err); + } +} diff --git a/apps/mobile/rust/mobile/Cargo.toml b/apps/mobile/rust/mobile/Cargo.toml new file mode 100644 index 000000000..6a755d243 --- /dev/null +++ b/apps/mobile/rust/mobile/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "sd-core-mobile" +version = "0.1.0" +edition = "2021" +rust-version = "1.64.0" + +[features] +android = ["sd-core/android"] + +[dependencies] +once_cell = "1.15.0" +sd-core = { path = "../../../../core", features = [ + "mobile", + "p2p", +], default-features = false } +rspc.workspace= true +serde_json = "1.0.85" +tokio = "1.21.2" +openssl = { version = "0.10.42", features = [ + "vendored", +] } # Override features of transitive dependencies +openssl-sys = { version = "0.9.76", features = [ + "vendored", +] } # Override features of transitive dependencies to support IOS Simulator on M1 +futures = "0.3.24" +tracing = "0.1.37" diff --git a/apps/mobile/rust/mobile/src/lib.rs b/apps/mobile/rust/mobile/src/lib.rs new file mode 100644 index 000000000..362475845 --- /dev/null +++ b/apps/mobile/rust/mobile/src/lib.rs @@ -0,0 +1,106 @@ +use futures::future::join_all; +use once_cell::sync::{Lazy, OnceCell}; +use rspc::internal::jsonrpc::*; +use sd_core::{api::Router, Node}; +use serde_json::{from_str, from_value, to_string, Value}; +use std::{collections::HashMap, marker::Send, sync::Arc}; +use tokio::{ + runtime::Runtime, + sync::{ + mpsc::{unbounded_channel, UnboundedSender}, + oneshot, Mutex, + }, +}; +use tracing::error; + +pub static RUNTIME: Lazy = Lazy::new(|| Runtime::new().unwrap()); + +pub type NodeType = Lazy, Arc)>>>; + +pub static NODE: NodeType = Lazy::new(|| Mutex::new(None)); + +pub static SUBSCRIPTIONS: Lazy>>> = + Lazy::new(Default::default); + +pub static EVENT_SENDER: OnceCell> = OnceCell::new(); + +pub fn handle_core_msg( + query: String, + data_dir: String, + callback: impl FnOnce(Result) + Send + 'static, +) { + RUNTIME.spawn(async move { + let (node, router) = { + let node = &mut *NODE.lock().await; + match node { + Some(node) => node.clone(), + None => { + // TODO: probably don't unwrap + let new_node = Node::new(data_dir).await.unwrap(); + node.replace(new_node.clone()); + new_node + } + } + }; + + let reqs = match from_str::(&query).and_then(|v| match v.is_array() { + true => from_value::>(v), + false => from_value::(v).map(|v| vec![v]), + }) { + Ok(v) => v, + Err(err) => { + error!("failed to decode JSON-RPC request: {}", err); // Don't use tracing here because it's before the `Node` is initialised which sets that config! + callback(Err(query)); + return; + } + }; + + let responses = join_all(reqs.into_iter().map(|request| { + let node = node.clone(); + let router = router.clone(); + async move { + let mut channel = EVENT_SENDER.get().unwrap().clone(); + let mut resp = Sender::ResponseAndChannel(None, &mut channel); + + handle_json_rpc( + node.get_request_context(), + request, + &router, + &mut resp, + &mut SubscriptionMap::Mutex(&SUBSCRIPTIONS), + ) + .await; + + match resp { + Sender::ResponseAndChannel(resp, _) => resp, + _ => unreachable!(), + } + } + })) + .await; + + callback(Ok(serde_json::to_string( + &responses.into_iter().flatten().collect::>(), + ) + .unwrap())); + }); +} + +pub fn spawn_core_event_listener(callback: impl Fn(String) + Send + 'static) { + let (tx, mut rx) = unbounded_channel(); + let _ = EVENT_SENDER.set(tx); + + RUNTIME.spawn(async move { + while let Some(event) = rx.recv().await { + let data = match to_string(&event) { + Ok(json) => json, + Err(err) => { + println!("Failed to serialize event: {}", err); + continue; + } + }; + + callback(data); + } + }); +} diff --git a/apps/mobile/rust/src/android.rs b/apps/mobile/rust/src/android.rs deleted file mode 100644 index 228dba91c..000000000 --- a/apps/mobile/rust/src/android.rs +++ /dev/null @@ -1,177 +0,0 @@ -use std::panic; - -use crate::{EVENT_SENDER, NODE, RUNTIME, SUBSCRIPTIONS}; -use futures::future::join_all; -use jni::objects::{JClass, JObject, JString}; -use jni::JNIEnv; -use rspc::internal::jsonrpc::{handle_json_rpc, Request, Sender, SubscriptionMap}; -use sd_core::Node; -use serde_json::Value; -use tokio::sync::mpsc::unbounded_channel; -use tracing::{error, info}; - -#[no_mangle] -pub extern "system" fn Java_com_spacedrive_app_SDCore_registerCoreEventListener( - env: JNIEnv, - class: JClass, -) { - let result = panic::catch_unwind(|| { - let jvm = env.get_java_vm().unwrap(); - let class = env.new_global_ref(class).unwrap(); - let (tx, mut rx) = unbounded_channel(); - let _ = EVENT_SENDER.set(tx); - - RUNTIME.spawn(async move { - while let Some(event) = rx.recv().await { - let data = match serde_json::to_string(&event) { - Ok(json) => json, - Err(err) => { - println!("Failed to serialize event: {}", err); - continue; - } - }; - - let env = jvm.attach_current_thread().unwrap(); - env.call_method( - &class, - "sendCoreEvent", - "(Ljava/lang/String;)V", - &[env - .new_string(data) - .expect("Couldn't create java string!") - .into()], - ) - .unwrap(); - } - }); - }); - - if let Err(err) = result { - // TODO: Send rspc error or something here so we can show this in the UI. - // TODO: Maybe reinitialise the core cause it could be in an invalid state? - println!( - "Error in Java_com_spacedrive_app_SDCore_registerCoreEventListener: {:?}", - err - ); - } -} - -#[no_mangle] -pub extern "system" fn Java_com_spacedrive_app_SDCore_handleCoreMsg( - env: JNIEnv, - class: JClass, - query: JString, - callback: JObject, -) { - let result = panic::catch_unwind(|| { - let jvm = env.get_java_vm().unwrap(); - let query: String = env - .get_string(query) - .expect("Couldn't get java string!") - .into(); - let class = env.new_global_ref(class).unwrap(); - let callback = env.new_global_ref(callback).unwrap(); - - RUNTIME.spawn(async move { - let (node, router) = { - let node = &mut *NODE.lock().await; - match node { - Some(node) => node.clone(), - None => { - let data_dir: String = { - let env = jvm.attach_current_thread().unwrap(); - let data_dir = env - .call_method( - &class, - "getDataDirectory", - "()Ljava/lang/String;", - &[], - ) - .unwrap() - .l() - .unwrap(); - - env.get_string(data_dir.into()).unwrap().into() - }; - - let new_node = Node::new(data_dir).await; - let new_node = match new_node { - Ok(new_node) => new_node, - Err(err) => { - info!("677 {:?}", err); - - // TODO: Android return? - return; - } - }; - - node.replace(new_node.clone()); - new_node - } - } - }; - - let reqs = - match serde_json::from_str::(&query).and_then(|v| match v.is_array() { - true => serde_json::from_value::>(v), - false => serde_json::from_value::(v).map(|v| vec![v]), - }) { - Ok(v) => v, - Err(err) => { - error!("failed to decode JSON-RPC request: {}", err); // Don't use tracing here because it's before the `Node` is initialised which sets that config! - return; - } - }; - - let resps = join_all(reqs.into_iter().map(|request| { - let node = node.clone(); - let router = router.clone(); - async move { - let mut channel = EVENT_SENDER.get().unwrap().clone(); - let mut resp = Sender::ResponseAndChannel(None, &mut channel); - - handle_json_rpc( - node.get_request_context(), - request, - &router, - &mut resp, - &mut SubscriptionMap::Mutex(&SUBSCRIPTIONS), - ) - .await; - - match resp { - Sender::ResponseAndChannel(resp, _) => resp, - _ => unreachable!(), - } - } - })) - .await; - - let env = jvm.attach_current_thread().unwrap(); - env.call_method( - &callback, - "resolve", - "(Ljava/lang/Object;)V", - &[env - .new_string( - serde_json::to_string(&resps.into_iter().flatten().collect::>()) - .unwrap(), - ) - .expect("Couldn't create java string!") - .into()], - ) - .unwrap(); - }); - }); - - if let Err(err) = result { - // TODO: Send rspc error or something here so we can show this in the UI. - // TODO: Maybe reinitialise the core cause it could be in an invalid state? - - // TODO: This log statement doesn't work. I recon the JNI env is being dropped before it's called. - error!( - "Error in Java_com_spacedrive_app_SDCore_registerCoreEventListener: {:?}", - err - ); - } -} diff --git a/apps/mobile/rust/src/ios.rs b/apps/mobile/rust/src/ios.rs deleted file mode 100644 index d17df064e..000000000 --- a/apps/mobile/rust/src/ios.rs +++ /dev/null @@ -1,139 +0,0 @@ -use crate::{EVENT_SENDER, NODE, RUNTIME, SUBSCRIPTIONS}; -use futures::future::join_all; -use objc::{msg_send, runtime::Object, sel, sel_impl}; -use objc_foundation::{INSString, NSString}; -use objc_id::Id; -use rspc::internal::jsonrpc::{handle_json_rpc, Request, Sender, SubscriptionMap}; -use sd_core::Node; -use serde_json::Value; -use std::{ - ffi::{CStr, CString}, - os::raw::{c_char, c_void}, - panic, -}; -use tokio::sync::mpsc::unbounded_channel; - -extern "C" { - fn get_data_directory() -> *const c_char; - fn call_resolve(resolve: *const c_void, result: *const c_char); -} - -// This struct wraps the function pointer which represent a Javascript Promise. We wrap the -// function pointers in a struct so we can unsafely assert to Rust that they are `Send`. -// We know they are send as we have ensured Objective-C won't deallocate the function pointer -// until `call_resolve` is called. -struct RNPromise(*const c_void); - -unsafe impl Send for RNPromise {} - -impl RNPromise { - // resolve the promise - unsafe fn resolve(self, result: CString) { - call_resolve(self.0, result.as_ptr()); - } -} - -#[no_mangle] -pub unsafe extern "C" fn register_core_event_listener(id: *mut Object) { - let result = panic::catch_unwind(|| { - let id = Id::::from_ptr(id); - - let (tx, mut rx) = unbounded_channel(); - let _ = EVENT_SENDER.set(tx); - - RUNTIME.spawn(async move { - while let Some(event) = rx.recv().await { - let data = match serde_json::to_string(&event) { - Ok(json) => json, - Err(err) => { - println!("Failed to serialize event: {}", err); - continue; - } - }; - let data = NSString::from_str(&data); - let _: () = msg_send![id, sendCoreEvent: data]; - } - }); - }); - - if let Err(err) = result { - // TODO: Send rspc error or something here so we can show this in the UI. - // TODO: Maybe reinitialise the core cause it could be in an invalid state? - println!("Error in register_core_event_listener: {:?}", err); - } -} - -#[no_mangle] -pub unsafe extern "C" fn sd_core_msg(query: *const c_char, resolve: *const c_void) { - let result = panic::catch_unwind(|| { - // This string is cloned to the Rust heap. This is important as Objective-C may remove the query once this function completions but prior to the async block finishing. - let query = CStr::from_ptr(query).to_str().unwrap().to_string(); - - let resolve = RNPromise(resolve); - RUNTIME.spawn(async move { - let reqs = - match serde_json::from_str::(&query).and_then(|v| match v.is_array() { - true => serde_json::from_value::>(v), - false => serde_json::from_value::(v).map(|v| vec![v]), - }) { - Ok(v) => v, - Err(err) => { - println!("failed to decode JSON-RPC request: {}", err); // Don't use tracing here because it's before the `Node` is initialised which sets that config! - - resolve.resolve( - CString::new(serde_json::to_vec(&(vec![] as Vec)).unwrap()) - .unwrap(), - ); // TODO: Proper error handling - return; - } - }; - - let resps = join_all(reqs.into_iter().map(|request| async move { - let node = &mut *NODE.lock().await; - let (node, router) = match node { - Some(node) => node.clone(), - None => { - let data_dir = CStr::from_ptr(get_data_directory()) - .to_str() - .unwrap() - .to_string(); - let new_node = Node::new(data_dir).await.unwrap(); - node.replace(new_node.clone()); - new_node - } - }; - - let mut channel = EVENT_SENDER.get().unwrap().clone(); - let mut resp = Sender::ResponseAndChannel(None, &mut channel); - handle_json_rpc( - node.get_request_context(), - request, - &router, - &mut resp, - &mut SubscriptionMap::Mutex(&SUBSCRIPTIONS), - ) - .await; - - match resp { - Sender::ResponseAndChannel(resp, _) => resp, - _ => unreachable!(), - } - })) - .await; - - resolve.resolve( - CString::new( - serde_json::to_vec(&resps.into_iter().filter_map(|v| v).collect::>()) - .unwrap(), - ) - .unwrap(), - ); - }); - }); - - if let Err(err) = result { - // TODO: Send rspc error or something here so we can show this in the UI. - // TODO: Maybe reinitialise the core cause it could be in an invalid state? - println!("Error in sd_core_msg: {:?}", err); - } -} diff --git a/apps/mobile/rust/src/lib.rs b/apps/mobile/rust/src/lib.rs deleted file mode 100644 index b887d887e..000000000 --- a/apps/mobile/rust/src/lib.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::{collections::HashMap, sync::Arc}; - -use once_cell::sync::{Lazy, OnceCell}; -use rspc::internal::jsonrpc::{RequestId, Response}; -use sd_core::{api::Router, Node}; -use tokio::{ - runtime::Runtime, - sync::{mpsc::UnboundedSender, oneshot, Mutex}, -}; - -#[allow(dead_code)] -pub(crate) static RUNTIME: Lazy = Lazy::new(|| Runtime::new().unwrap()); - -type NodeType = Lazy, Arc)>>>; - -#[allow(dead_code)] -pub(crate) static NODE: NodeType = Lazy::new(|| Mutex::new(None)); - -#[allow(dead_code)] -pub(crate) static SUBSCRIPTIONS: Lazy>>> = - Lazy::new(Default::default); - -#[allow(dead_code)] -pub(crate) static EVENT_SENDER: OnceCell> = OnceCell::new(); - -#[cfg(target_os = "ios")] -mod ios; - -/// This is `not(ios)` instead of `android` because of https://github.com/mozilla/rust-android-gradle/issues/93 -#[cfg(not(target_os = "ios"))] -mod android;