Compare commits

..

No commits in common. "main" and "v0.1.0" have entirely different histories.
main ... v0.1.0

74 changed files with 235 additions and 813 deletions

View file

@ -1,5 +1,5 @@
[package] [package]
name = "caretta-sync" name = "caretta"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -7,26 +7,21 @@ license.workspace = true
repository.workspace = true repository.workspace = true
[features] [features]
default = ["macros"] default = []
bevy = ["dep:caretta-sync-bevy"] mobile = ["dep:caretta-mobile"]
mobile = ["dep:caretta-sync-mobile"] desktop = ["dep:caretta-desktop"]
cli = ["dep:caretta-sync-cli"] test = ["caretta-core/test"]
desktop = ["cli", "bevy"]
macros = ["dep:caretta-sync-macros"]
test = ["caretta-sync-core/test"]
[dependencies] [dependencies]
caretta-sync-bevy = { path = "bevy", optional = true } caretta-core.workspace = true
caretta-sync-core.workspace = true caretta-desktop = { path="desktop", optional = true }
caretta-sync-cli = { path="cli", optional = true } caretta-mobile = { path = "mobile", optional = true }
caretta-sync-mobile = { path = "mobile", optional = true }
caretta-sync-macros = { path="macros", optional = true}
[dev-dependencies] [dev-dependencies]
caretta-sync-core = {workspace = true, features = ["test"]} caretta-core = {workspace = true, features = ["test"]}
[workspace] [workspace]
members = [ ".", "core", "macros", "cli", "mobile", "examples/*" , "bevy"] members = [ ".", "core", "core/macros", "desktop", "mobile", "examples/*" ]
resolver = "3" resolver = "3"
[workspace.package] [workspace.package]
@ -37,12 +32,11 @@ license = "MIT OR Apache-2.0"
repository = "https://forgejo.fireturlte.net/lazy-supplements" repository = "https://forgejo.fireturlte.net/lazy-supplements"
[workspace.dependencies] [workspace.dependencies]
bevy = { git = "https://github.com/bevyengine/bevy.git", rev="16ffdaea0daec11e4347d965f56c9c8e1122a488" }
chrono = "0.4.41" chrono = "0.4.41"
ciborium = "0.2.2" ciborium = "0.2.2"
clap = { version = "4.5.38", features = ["derive"] } clap = { version = "4.5.38", features = ["derive"] }
caretta-sync-core.path = "core" dioxus = { version = "0.6.0", features = [] }
futures = { version = "0.3.31", features = ["executor"] } caretta-core.path = "core"
libp2p = { version = "0.55.0", features = ["macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux" ] } libp2p = { version = "0.55.0", features = ["macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux" ] }
sea-orm = { version = "1.1.11", features = ["sqlx-sqlite", "runtime-tokio-native-tls", "macros", "with-chrono", "with-uuid"] } sea-orm = { version = "1.1.11", features = ["sqlx-sqlite", "runtime-tokio-native-tls", "macros", "with-chrono", "with-uuid"] }
sea-orm-migration = { version = "1.1.0", features = ["runtime-tokio-rustls", "sqlx-postgres"] } sea-orm-migration = { version = "1.1.0", features = ["runtime-tokio-rustls", "sqlx-postgres"] }
@ -52,12 +46,3 @@ tokio = { version = "1.45.0", features = ["macros", "rt", "rt-multi-thread"] }
tonic = "0.14.0" tonic = "0.14.0"
uuid = { version = "1.17.0", features = ["v7"] } uuid = { version = "1.17.0", features = ["v7"] }
[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3
[profile.release]
codegen-units = 1
lto = "thin"

View file

@ -1,15 +0,0 @@
[package]
name = "caretta-sync-bevy"
edition.workspace = true
version.workspace = true
description.workspace = true
license.workspace = true
repository.workspace = true
[dependencies]
bevy.workspace = true
caretta-sync-core.workspace = true
futures.workspace = true
sea-orm.workspace = true
tokio.workspace = true
tonic.workspace = true

View file

@ -1,4 +0,0 @@
use bevy::{asset::uuid::Uuid, ecs::component::Component};
#[derive(Component)]
struct Id(Uuid);

View file

@ -1,2 +0,0 @@
pub mod global;
pub mod peer;

View file

@ -1,47 +0,0 @@
use bevy::{app::{App, Plugin, Startup, Update}, ecs::{component::Component, query::With, system::{Commands, Query}}, tasks::TaskPool};
use caretta_sync_core::{cache::entity::{CachedPeerEntity, CachedPeerModel}, global::{CONFIG, DATABASE_CONNECTIONS}};
use caretta_sync_core::{
proto::*,
};
use sea_orm::EntityTrait;
#[derive(Component)]
pub struct Peer;
#[derive(Component)]
pub struct PeerId(String);
#[derive(Component)]
pub struct PeerAddress(String);
#[tokio::main]
async fn add_cached_peers(mut commands: Commands) {
let config = CONFIG.get_unchecked();
let path = String::from("unix://") + config.rpc.socket_path.as_os_str().to_str().expect("Invalid string");
let mut client = caretta_sync_core::proto::cached_peer_service_client::CachedPeerServiceClient::connect(path).await.expect("Unix socket should be accessible");
let request = tonic::Request::new(CachedPeerListRequest {});
let response = client.list(request).await.expect("Faild to request/response");
let peers = response.into_inner().peers;
for model in peers.into_iter() {
commands.spawn((Peer, PeerId(model.peer_id.to_string())));
}
}
fn print_peer(query: Query<&PeerId, With<Peer>>) {
for peer_id in &query {
println!("Hello {}!", peer_id.0);
}
}
fn hello_world() {
println!("hello world!");
}
pub struct PeerPlugin;
impl Plugin for PeerPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, add_cached_peers);
app.add_systems(Update, (hello_world, print_peer));
}
}

View file

@ -1,5 +1,5 @@
[package] [package]
name = "caretta-sync-core" name = "caretta-core"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -8,17 +8,20 @@ repository.workspace = true
[features] [features]
default = [] default = []
cli = ["dep:clap"] desktop = ["dep:clap", "macros"]
test = ["dep:tempfile", ] mobile = ["macros"]
macros = ["dep:caretta-macros"]
test = ["dep:tempfile", "macros"]
[dependencies] [dependencies]
base64 = "0.22.1" base64 = "0.22.1"
caretta-macros = { path = "macros", optional = true }
chrono.workspace = true chrono.workspace = true
chrono-tz = "0.10.3" chrono-tz = "0.10.3"
ciborium.workspace = true ciborium.workspace = true
clap = {workspace = true, optional = true} clap = {workspace = true, optional = true}
dirs = "6.0.0" dirs = "6.0.0"
futures.workspace = true futures = "0.3.31"
libp2p.workspace = true libp2p.workspace = true
libp2p-core = { version = "0.43.0", features = ["serde"] } libp2p-core = { version = "0.43.0", features = ["serde"] }
libp2p-identity = { version = "0.2.11", features = ["ed25519", "peerid", "rand", "serde"] } libp2p-identity = { version = "0.2.11", features = ["ed25519", "peerid", "rand", "serde"] }

View file

@ -1,4 +1,4 @@
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_prost_build::compile_protos("proto/caretta_sync.proto")?; tonic_prost_build::compile_protos("proto/caretta.proto")?;
Ok(()) Ok(())
} }

View file

@ -1,5 +1,5 @@
[package] [package]
name = "caretta-sync-macros" name = "caretta-macros"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -17,7 +17,7 @@ syn = { version = "2.0.104", features = ["full"] }
[dev-dependencies] [dev-dependencies]
chrono.workspace = true chrono.workspace = true
caretta-sync-core.workspace = true caretta-core.workspace = true
sea-orm.workspace = true sea-orm.workspace = true
tokio.workspace = true tokio.workspace = true
uuid.workspace = true uuid.workspace = true

View file

@ -206,8 +206,8 @@ pub fn runnable(input: TokenStream) -> TokenStream {
quote!{ quote!{
impl Runnable for #type_ident { impl Runnable for #type_ident {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
<#field_type as Runnable>::run(self.#field_ident, app_name) <#field_type as Runnable>::run(self.#field_ident, app_name).await
} }
} }
}.into() }.into()
@ -216,12 +216,12 @@ pub fn runnable(input: TokenStream) -> TokenStream {
let quote_vec = extract_idents_and_types_from_enum_struct(&variants); let quote_vec = extract_idents_and_types_from_enum_struct(&variants);
let quote_iter = quote_vec.iter().map(|(variant_ident, variant_type)|{ let quote_iter = quote_vec.iter().map(|(variant_ident, variant_type)|{
quote!{ quote!{
Self::#variant_ident(x) => <#variant_type as Runnable>::run(x, app_name), Self::#variant_ident(x) => <#variant_type as Runnable>::run(x, app_name).await,
} }
}); });
quote!{ quote!{
impl Runnable for #type_ident { impl Runnable for #type_ident {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
match self { match self {
#(#quote_iter)* #(#quote_iter)*
} }

View file

@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use caretta_sync_core::utils::emptiable::Emptiable; use caretta_core::utils::emptiable::Emptiable;
use caretta_sync_macros::Emptiable; use caretta_macros::Emptiable;
#[derive(Debug, PartialEq, Emptiable)] #[derive(Debug, PartialEq, Emptiable)]
struct EmptiableStruct{ struct EmptiableStruct{

View file

@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use caretta_sync_core::utils::mergeable::Mergeable; use caretta_core::utils::mergeable::Mergeable;
use caretta_sync_macros::Mergeable; use caretta_macros::Mergeable;
#[derive(Clone, Debug, PartialEq, Mergeable)] #[derive(Clone, Debug, PartialEq, Mergeable)]
struct MergeableStruct { struct MergeableStruct {

View file

@ -1,5 +1,5 @@
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use caretta_sync_macros::Runnable; use caretta_macros::Runnable;
struct RunnableStruct1; struct RunnableStruct1;

View file

@ -6,8 +6,8 @@ use sea_orm::{
prelude::* prelude::*
} }
}; };
use caretta_sync_core::data::syncable::*; use caretta_core::data::syncable::*;
use caretta_sync_macros::SyncableModel; use caretta_macros::SyncableModel;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, SyncableModel)] #[derive(Clone, Debug, PartialEq, DeriveEntityModel, SyncableModel)]
#[sea_orm(table_name = "syncable")] #[sea_orm(table_name = "syncable")]

View file

@ -1,5 +1,5 @@
syntax = "proto3"; syntax = "proto3";
package caretta_sync; package caretta;
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
enum PeerListOrderBy { enum PeerListOrderBy {

View file

@ -13,7 +13,7 @@ pub use storage::{StorageConfig, PartialStorageConfig};
pub use p2p::{P2pConfig, PartialP2pConfig}; pub use p2p::{P2pConfig, PartialP2pConfig};
pub use rpc::*; pub use rpc::*;
#[cfg(feature="cli")] #[cfg(feature="desktop")]
use clap::Args; use clap::Args;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -52,14 +52,14 @@ impl TryFrom<PartialConfig> for Config {
} }
} }
#[cfg_attr(feature="cli", derive(Args))] #[cfg_attr(feature="desktop", derive(Args))]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct PartialConfig { pub struct PartialConfig {
#[cfg_attr(feature="cli", command(flatten))] #[cfg_attr(feature="desktop", command(flatten))]
pub p2p: Option<PartialP2pConfig>, pub p2p: Option<PartialP2pConfig>,
#[cfg_attr(feature="cli", command(flatten))] #[cfg_attr(feature="desktop", command(flatten))]
pub storage: Option<PartialStorageConfig>, pub storage: Option<PartialStorageConfig>,
#[cfg_attr(feature="cli", command(flatten))] #[cfg_attr(feature="desktop", command(flatten))]
pub rpc: Option<PartialRpcConfig>, pub rpc: Option<PartialRpcConfig>,
} }

View file

@ -1,7 +1,7 @@
use std::{net::{IpAddr, Ipv4Addr}, ops, path::{Path, PathBuf}}; use std::{net::{IpAddr, Ipv4Addr}, ops, path::{Path, PathBuf}};
use base64::{prelude::BASE64_STANDARD, Engine}; use base64::{prelude::BASE64_STANDARD, Engine};
#[cfg(feature="cli")] #[cfg(feature="desktop")]
use clap::Args; use clap::Args;
use futures::StreamExt; use futures::StreamExt;
use libp2p::{identity::{self, DecodingError, Keypair}, noise, ping, swarm::SwarmEvent, tcp, yamux, Swarm}; use libp2p::{identity::{self, DecodingError, Keypair}, noise, ping, swarm::SwarmEvent, tcp, yamux, Swarm};
@ -81,14 +81,14 @@ impl TryFrom<PartialP2pConfig> for P2pConfig {
} }
} }
#[cfg_attr(feature="cli",derive(Args))] #[cfg_attr(feature="desktop",derive(Args))]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct PartialP2pConfig { pub struct PartialP2pConfig {
#[cfg_attr(feature="cli",arg(long))] #[cfg_attr(feature="desktop",arg(long))]
pub private_key: Option<String>, pub private_key: Option<String>,
#[cfg_attr(feature="cli",arg(long))] #[cfg_attr(feature="desktop",arg(long))]
pub listen_ips: Option<Vec<IpAddr>>, pub listen_ips: Option<Vec<IpAddr>>,
#[cfg_attr(feature="cli",arg(long))] #[cfg_attr(feature="desktop",arg(long))]
pub port: Option<u16>, pub port: Option<u16>,
} }
impl PartialP2pConfig { impl PartialP2pConfig {

View file

@ -1,5 +1,5 @@
use std::{net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener}, path::PathBuf, str::FromStr}; use std::{net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener}, path::PathBuf, str::FromStr};
#[cfg(feature="cli")] #[cfg(feature="desktop")]
use clap::Args; use clap::Args;
use crate::{config::PartialConfig, utils::{emptiable::Emptiable, mergeable::Mergeable}}; use crate::{config::PartialConfig, utils::{emptiable::Emptiable, mergeable::Mergeable}};
use libp2p::mdns::Config; use libp2p::mdns::Config;
@ -24,7 +24,7 @@ impl TryFrom<PartialRpcConfig> for RpcConfig {
} }
} }
#[cfg_attr(feature="cli", derive(Args))] #[cfg_attr(feature="desktop", derive(Args))]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct PartialRpcConfig { pub struct PartialRpcConfig {
pub socket_path: Option<PathBuf>, pub socket_path: Option<PathBuf>,

View file

@ -1,6 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
#[cfg(feature="cli")] #[cfg(feature="desktop")]
use clap::Args; use clap::Args;
#[cfg(any(test, feature="test"))] #[cfg(any(test, feature="test"))]
@ -25,12 +25,12 @@ impl TryFrom<PartialStorageConfig> for StorageConfig {
}) })
} }
} }
#[cfg_attr(feature="cli", derive(Args))] #[cfg_attr(feature="desktop", derive(Args))]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct PartialStorageConfig { pub struct PartialStorageConfig {
#[cfg_attr(feature="cli", arg(long))] #[cfg_attr(feature="desktop", arg(long))]
pub data_directory: Option<PathBuf>, pub data_directory: Option<PathBuf>,
#[cfg_attr(feature="cli", arg(long))] #[cfg_attr(feature="desktop", arg(long))]
pub cache_directory: Option<PathBuf>, pub cache_directory: Option<PathBuf>,
} }
@ -66,7 +66,7 @@ impl PartialStorageConfig {
Ok(cache_dir.to_string()) Ok(cache_dir.to_string())
} }
#[cfg(false)] #[cfg(target_os="ios")]
fn default_ios(){ fn default_ios(){
unsafe { unsafe {
let file_manager: *mut Object = msg_send![Class::get("NSFileManager").unwrap(), defaultManager]; let file_manager: *mut Object = msg_send![Class::get("NSFileManager").unwrap(), defaultManager];

View file

@ -1,6 +1,6 @@
use sea_orm::{prelude::*, query::*, sea_query::SimpleExpr, *}; use sea_orm::{prelude::*, query::*, sea_query::SimpleExpr, *};
#[cfg(feature="macros")] #[cfg(feature="macros")]
pub use caretta_sync_macros::SyncableModel; pub use caretta_macros::SyncableModel;
pub trait SyncableModel: ModelTrait<Entity = Self::SyncableEntity> { pub trait SyncableModel: ModelTrait<Entity = Self::SyncableEntity> {
type SyncableEntity: SyncableEntity<SyncableModel = Self>; type SyncableEntity: SyncableEntity<SyncableModel = Self>;
fn get_timestamp(&self) -> DateTimeUtc; fn get_timestamp(&self) -> DateTimeUtc;

View file

@ -28,7 +28,7 @@ pub enum Error {
Noise(#[from] libp2p::noise::Error), Noise(#[from] libp2p::noise::Error),
#[error("Parse OsString error: {0:?}")] #[error("Parse OsString error: {0:?}")]
OsStringConvert(std::ffi::OsString), OsStringConvert(std::ffi::OsString),
#[cfg(feature="cli")] #[cfg(feature="desktop")]
#[error("Parse args error: {0}")] #[error("Parse args error: {0}")]
ParseCommand(#[from] clap::Error), ParseCommand(#[from] clap::Error),
#[error("toml deserialization error: {0}")] #[error("toml deserialization error: {0}")]

View file

@ -32,7 +32,4 @@ impl GlobalConfig {
pub fn get(&'static self) -> Option<&'static Config> { pub fn get(&'static self) -> Option<&'static Config> {
self.inner.get() self.inner.get()
} }
pub fn get_unchecked(&'static self) -> &'static Config {
self.get().expect("Config must be initialized before use!")
}
} }

View file

@ -1,5 +1,5 @@
mod cached_address; mod cached_address;
mod cached_peer; mod cached_peer;
tonic::include_proto!("caretta_sync"); tonic::include_proto!("caretta");

View file

@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
#[cfg(feature="macros")] #[cfg(feature="macros")]
pub use caretta_sync_macros::Emptiable; pub use caretta_macros::Emptiable;
pub trait Emptiable{ pub trait Emptiable{
fn empty() -> Self; fn empty() -> Self;

View file

@ -1,5 +1,5 @@
#[cfg(feature="macros")] #[cfg(feature="macros")]
pub use caretta_sync_macros::Mergeable; pub use caretta_macros::Mergeable;
pub trait Mergeable: Sized { pub trait Mergeable: Sized {
fn merge(&mut self, other: Self); fn merge(&mut self, other: Self);
} }

View file

@ -10,7 +10,7 @@ pub mod runnable;
/// use chrono::Utc; /// use chrono::Utc;
/// use std::time::SystemTime; /// use std::time::SystemTime;
/// use prost_types::Timestamp; /// use prost_types::Timestamp;
/// use caretta_sync_core::utils::utc_to_timestamp; /// use caretta_core::utils::utc_to_timestamp;
/// ///
/// let now_utc = Utc::now(); /// let now_utc = Utc::now();
/// let now_timestamp = utc_to_timestamp(&now_utc); /// let now_timestamp = utc_to_timestamp(&now_utc);
@ -27,7 +27,7 @@ pub fn utc_to_timestamp(utc: &DateTime<Utc>) -> Timestamp {
/// ``` /// ```
/// use std::time::SystemTime; /// use std::time::SystemTime;
/// use prost_types::Timestamp; /// use prost_types::Timestamp;
/// use caretta_sync_core::utils::timestamp_to_utc; /// use caretta_core::utils::timestamp_to_utc;
/// ///
/// let now_timestamp = Timestamp::from(SystemTime::now()); /// let now_timestamp = Timestamp::from(SystemTime::now());
/// let now_utc = timestamp_to_utc(&now_timestamp); /// let now_utc = timestamp_to_utc(&now_timestamp);

View file

@ -1,3 +1,6 @@
#[cfg(feature="macros")]
pub use caretta_macros::Runnable;
pub trait Runnable { pub trait Runnable {
fn run(self, app_name: &'static str); async fn run(self, app_name: &'static str);
} }

View file

@ -1,5 +1,5 @@
[package] [package]
name = "caretta-sync-cli" name = "caretta-desktop"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -8,13 +8,13 @@ repository.workspace = true
[features] [features]
default = [] default = []
test = ["caretta-sync-core/test"] test = ["caretta-core/test"]
[dependencies] [dependencies]
ciborium.workspace = true ciborium.workspace = true
clap.workspace = true clap.workspace = true
dirs = "6.0.0" dirs = "6.0.0"
caretta-sync-core = { workspace = true, features = ["cli"] } caretta-core = { workspace = true, features = ["desktop"] }
libp2p.workspace = true libp2p.workspace = true
sea-orm.workspace = true sea-orm.workspace = true
serde.workspace = true serde.workspace = true
@ -25,4 +25,7 @@ tonic.workspace = true
uuid.workspace = true uuid.workspace = true
[dev-dependencies] [dev-dependencies]
caretta-sync-core = {workspace = true, features = ["test"]} caretta-core = {workspace = true, features = ["test"]}
[build-dependencies]
tonic-prost-build = "0.14.0"

View file

@ -1,7 +1,7 @@
use std::{net::IpAddr, path::PathBuf, sync::LazyLock}; use std::{net::IpAddr, path::PathBuf, sync::LazyLock};
use clap::Args; use clap::Args;
use caretta_sync_core::{ use caretta_core::{
config::{Config, ConfigError, PartialConfig, PartialP2pConfig, PartialStorageConfig}, config::{Config, ConfigError, PartialConfig, PartialP2pConfig, PartialStorageConfig},
utils::{emptiable::Emptiable, mergeable::Mergeable} utils::{emptiable::Emptiable, mergeable::Mergeable}
}; };

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use crate::cli::ConfigArgs; use crate::cli::ConfigArgs;
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -9,7 +9,6 @@ pub struct ConfigCheckCommandArgs{
} }
impl Runnable for ConfigCheckCommandArgs { impl Runnable for ConfigCheckCommandArgs {
#[tokio::main]
async fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
let _ = self.config.into_config(app_name).await; let _ = self.config.into_config(app_name).await;
println!("Ok"); println!("Ok");

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::{config::PartialConfig, utils::runnable::Runnable}; use caretta_core::{config::PartialConfig, utils::runnable::Runnable};
use crate::cli::ConfigArgs; use crate::cli::ConfigArgs;
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -11,7 +11,6 @@ pub struct ConfigListCommandArgs{
} }
impl Runnable for ConfigListCommandArgs { impl Runnable for ConfigListCommandArgs {
#[tokio::main]
async fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
let config: PartialConfig = if self.all { let config: PartialConfig = if self.all {
self.config.into_config(app_name).await.into() self.config.into_config(app_name).await.into()

View file

@ -4,7 +4,7 @@ mod list;
pub use check::*; pub use check::*;
pub use list::*; pub use list::*;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use clap::{Args, Subcommand}; use clap::{Args, Subcommand};
@ -15,8 +15,8 @@ pub struct ConfigCommandArgs {
} }
impl Runnable for ConfigCommandArgs { impl Runnable for ConfigCommandArgs {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
self.command.run(app_name) self.command.run(app_name).await
} }
} }
@ -27,10 +27,10 @@ pub enum ConfigSubcommand {
} }
impl Runnable for ConfigSubcommand { impl Runnable for ConfigSubcommand {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
match self { match self {
Self::Check(x) => x.run(app_name), Self::Check(x) => x.run(app_name).await,
Self::List(x) => x.run(app_name), Self::List(x) => x.run(app_name).await,
} }
} }
} }

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use crate::cli::ConfigArgs; use crate::cli::ConfigArgs;
@ -16,7 +16,7 @@ pub struct DeviceAddCommandArgs {
} }
impl Runnable for DeviceAddCommandArgs { impl Runnable for DeviceAddCommandArgs {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
todo!() todo!()
} }
} }

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use crate::cli::ConfigArgs; use crate::cli::ConfigArgs;
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -9,7 +9,7 @@ pub struct DeviceListCommandArgs{
} }
impl Runnable for DeviceListCommandArgs { impl Runnable for DeviceListCommandArgs {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
todo!() todo!()
} }
} }

View file

@ -5,7 +5,7 @@ mod remove;
mod scan; mod scan;
pub use add::DeviceAddCommandArgs; pub use add::DeviceAddCommandArgs;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use libp2p::{Multiaddr, PeerId}; use libp2p::{Multiaddr, PeerId};
pub use list::DeviceListCommandArgs; pub use list::DeviceListCommandArgs;
pub use ping::DevicePingCommandArgs; pub use ping::DevicePingCommandArgs;
@ -22,8 +22,8 @@ pub struct DeviceCommandArgs {
} }
impl Runnable for DeviceCommandArgs { impl Runnable for DeviceCommandArgs {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
self.command.run(app_name) self.command.run(app_name).await
} }
} }
@ -37,13 +37,13 @@ pub enum DeviceSubcommand {
} }
impl Runnable for DeviceSubcommand { impl Runnable for DeviceSubcommand {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
match self { match self {
Self::Add(x) => x.run(app_name), Self::Add(x) => x.run(app_name).await,
Self::List(x) => x.run(app_name), Self::List(x) => x.run(app_name).await,
Self::Ping(x) => x.run(app_name), Self::Ping(x) => x.run(app_name).await,
Self::Remove(x) => x.run(app_name), Self::Remove(x) => x.run(app_name).await,
Self::Scan(x) => x.run(app_name), Self::Scan(x) => x.run(app_name).await,
} }
} }
} }

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use crate::cli::{ConfigArgs, PeerArgs}; use crate::cli::{ConfigArgs, PeerArgs};
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -11,7 +11,7 @@ pub struct DevicePingCommandArgs{
} }
impl Runnable for DevicePingCommandArgs { impl Runnable for DevicePingCommandArgs {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
todo!() todo!()
} }
} }

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use crate::cli::{ConfigArgs, DeviceArgs}; use crate::cli::{ConfigArgs, DeviceArgs};
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -11,7 +11,7 @@ pub struct DeviceRemoveCommandArgs{
} }
impl Runnable for DeviceRemoveCommandArgs { impl Runnable for DeviceRemoveCommandArgs {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
todo!() todo!()
} }
} }

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use crate::cli::ConfigArgs; use crate::cli::ConfigArgs;
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -9,7 +9,7 @@ pub struct DeviceScanCommandArgs{
} }
impl Runnable for DeviceScanCommandArgs { impl Runnable for DeviceScanCommandArgs {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
todo!() todo!()
} }
} }

14
desktop/src/cli/logs.rs Normal file
View file

@ -0,0 +1,14 @@
use caretta_core::utils::runnable::Runnable;
use clap::Args;
#[derive(Args, Debug)]
pub struct LogsCommandArgs {
#[arg(short='n', long)]
lines: Option<u32>,
}
impl Runnable for LogsCommandArgs {
async fn run(self, app_name: &'static str) {
todo!()
}
}

View file

@ -3,11 +3,11 @@ use std::path::PathBuf;
mod args; mod args;
mod config; mod config;
mod device; mod device;
mod logs;
mod peer; mod peer;
mod serve;
pub use args::*; pub use args::*;
pub use config::*; pub use config::*;
pub use device::*; pub use device::*;
pub use logs::*;
pub use peer::*; pub use peer::*;
pub use serve::*;

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use crate::cli::{ConfigArgs, PeerArgs}; use crate::cli::{ConfigArgs, PeerArgs};
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -11,7 +11,7 @@ pub struct PeerInfoCommandArgs{
} }
impl Runnable for PeerInfoCommandArgs { impl Runnable for PeerInfoCommandArgs {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
todo!() todo!()
} }
} }

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::{ use caretta_core::{
utils::runnable::Runnable, utils::runnable::Runnable,
proto::*, proto::*,
}; };
@ -12,11 +12,10 @@ pub struct PeerListCommandArgs{
} }
impl Runnable for PeerListCommandArgs { impl Runnable for PeerListCommandArgs {
#[tokio::main]
async fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
let config = self.config.into_config(app_name).await; let config = self.config.into_config(app_name).await;
let path = String::from("unix://") + config.rpc.socket_path.as_os_str().to_str().expect("Invalid string"); let path = String::from("unix://") + config.rpc.socket_path.as_os_str().to_str().expect("Invalid string");
let mut client = caretta_sync_core::proto::cached_peer_service_client::CachedPeerServiceClient::connect(path).await.expect("Unix socket should be accessible"); let mut client = caretta_core::proto::cached_peer_service_client::CachedPeerServiceClient::connect(path).await.expect("Unix socket should be accessible");
let request = tonic::Request::new(CachedPeerListRequest {}); let request = tonic::Request::new(CachedPeerListRequest {});
let response = client.list(request).await.expect("Faild to request/response"); let response = client.list(request).await.expect("Faild to request/response");
println!("{:?}", response); println!("{:?}", response);

View file

@ -6,7 +6,7 @@ pub use info::*;
pub use list::*; pub use list::*;
pub use ping::*; pub use ping::*;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use clap::{Args, Subcommand}; use clap::{Args, Subcommand};
@ -17,8 +17,8 @@ pub struct PeerCommandArgs {
} }
impl Runnable for PeerCommandArgs { impl Runnable for PeerCommandArgs {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
self.command.run(app_name) self.command.run(app_name).await
} }
} }
@ -30,11 +30,11 @@ pub enum PeerSubcommand {
} }
impl Runnable for PeerSubcommand { impl Runnable for PeerSubcommand {
fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
match self { match self {
Self::Info(x) => x.run(app_name), Self::Info(x) => x.run(app_name).await,
Self::List(x) => x.run(app_name), Self::List(x) => x.run(app_name).await,
Self::Ping(x) => x.run(app_name), Self::Ping(x) => x.run(app_name).await,
} }
} }
} }

View file

@ -1,5 +1,5 @@
use clap::Args; use clap::Args;
use caretta_sync_core::utils::runnable::Runnable; use caretta_core::utils::runnable::Runnable;
use crate::cli::{ConfigArgs, PeerArgs}; use crate::cli::{ConfigArgs, PeerArgs};
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -11,7 +11,6 @@ pub struct PeerPingCommandArgs{
} }
impl Runnable for PeerPingCommandArgs { impl Runnable for PeerPingCommandArgs {
#[tokio::main]
async fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
todo!() todo!()
} }

View file

@ -1,5 +1,5 @@
[package] [package]
name = "caretta-sync-example-core" name = "caretta-example-core"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -7,8 +7,7 @@ license.workspace = true
repository.workspace = true repository.workspace = true
[dependencies] [dependencies]
bevy.workspace = true caretta.path = "../.."
caretta-sync = { path = "../..", features = ["bevy"] }
libp2p.workspace = true libp2p.workspace = true
tokio.workspace = true tokio.workspace = true
tokio-stream = { version = "0.1.17", features = ["net"] } tokio-stream = { version = "0.1.17", features = ["net"] }

View file

@ -1 +1 @@
pub const APP_NAME: &str = "caretta_sync_example"; pub const APP_NAME: &str = "caretta_demo";

View file

@ -1,13 +0,0 @@
use caretta_sync::{bevy::peer::PeerPlugin, utils::Runnable};
use bevy::prelude::*;
pub struct Gui {}
impl Runnable for Gui {
fn run(self, app_name: &'static str) {
App::new()
//.add_plugins(DefaultPlugins)
.add_plugins(PeerPlugin)
.run();
}
}

View file

@ -1,4 +1,3 @@
pub mod global; pub mod global;
pub mod gui;
pub mod rpc; pub mod rpc;
pub mod server; pub mod server;

View file

@ -1,4 +1,4 @@
use caretta_sync::{ use caretta::{
config::P2pConfig, config::P2pConfig,
proto::cached_peer_service_server::CachedPeerServiceServer, proto::cached_peer_service_server::CachedPeerServiceServer,
server::ServerTrait, server::ServerTrait,
@ -7,12 +7,10 @@ use caretta_sync::{
use libp2p::{futures::StreamExt, noise, swarm::SwarmEvent, tcp, yamux}; use libp2p::{futures::StreamExt, noise, swarm::SwarmEvent, tcp, yamux};
use tokio::net::UnixListener; use tokio::net::UnixListener;
use tokio_stream::wrappers::UnixListenerStream; use tokio_stream::wrappers::UnixListenerStream;
#[derive(Debug)]
pub struct Server{} pub struct Server{}
impl ServerTrait for Server { impl ServerTrait for Server {
async fn serve_p2p<T>(config: &T) -> Result<(), caretta_sync::error::Error> async fn serve_p2p<T>(config: &T) -> Result<(), caretta::error::Error>
where where
T: AsRef<P2pConfig> T: AsRef<P2pConfig>
{ {
@ -23,7 +21,7 @@ impl ServerTrait for Server {
noise::Config::new, noise::Config::new,
yamux::Config::default, yamux::Config::default,
)? )?
.with_behaviour(|keypair| caretta_sync::p2p::Behaviour::try_from(keypair).unwrap())? .with_behaviour(|keypair| caretta::p2p::Behaviour::try_from(keypair).unwrap())?
.build(); .build();
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?; swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;
loop{ loop{
@ -41,8 +39,8 @@ impl ServerTrait for Server {
} }
} }
async fn serve_rpc<T>(config: &T) -> Result<(), caretta_sync::error::Error> async fn serve_rpc<T>(config: &T) -> Result<(), caretta::error::Error>
where T: AsRef<caretta_sync::config::RpcConfig> { where T: AsRef<caretta::config::RpcConfig> {
let path = config.as_ref().socket_path.clone(); let path = config.as_ref().socket_path.clone();
if let Some(x) = path.parent() { if let Some(x) = path.parent() {
if !x.exists() { if !x.exists() {

View file

@ -1,14 +1,14 @@
[package] [package]
name = "caretta-sync-example-desktop" name = "caretta-example-desktop"
edition.workspace = true version = "0.1.0"
version.workspace = true edition = "2021"
description.workspace = true
license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
repository.workspace = true
[dependencies] [dependencies]
clap.workspace = true clap.workspace = true
caretta-sync = { path = "../..", features = ["cli", "bevy", "test"] } caretta = { path = "../..", features = ["desktop", "test"] }
caretta-sync-example-core.path = "../core" caretta-example-core.path = "../core"
libp2p.workspace = true libp2p.workspace = true
tokio.workspace = true tokio.workspace = true

View file

@ -0,0 +1,21 @@
[application]
[web.app]
# HTML title tag content
title = "desktop"
# include `assets` in web platform
[web.resource]
# Additional CSS style files
style = []
# Additional JavaScript files
script = []
[web.resource.dev]
# Javascript code file
# serve: [dev-server] only
script = []

View file

@ -0,0 +1,25 @@
# Development
Your new bare-bones project includes minimal organization with a single `main.rs` file and a few assets.
```
project/
├─ assets/ # Any assets that are used by the app should be placed here
├─ src/
│ ├─ main.rs # main.rs is the entry point to your application and currently contains all components for the app
├─ Cargo.toml # The Cargo.toml file defines the dependencies and feature flags for your project
```
### Serving Your App
Run the following command in the root of your project to start developing with the default platform:
```bash
dx serve
```
To run for a different platform, use the `--platform platform` flag. E.g.
```bash
dx serve --platform desktop
```

View file

@ -0,0 +1,8 @@
await-holding-invalid-types = [
"generational_box::GenerationalRef",
{ path = "generational_box::GenerationalRef", reason = "Reads should not be held over an await point. This will cause any writes to fail while the await is pending since the read borrow is still active." },
"generational_box::GenerationalRefMut",
{ path = "generational_box::GenerationalRefMut", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." },
"dioxus_signals::Write",
{ path = "dioxus_signals::Write", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." },
]

View file

@ -1,39 +1,21 @@
use caretta_sync_example_core::{gui::Gui, server::Server}; mod server;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use caretta_sync::{cli::*, config::Config, data::migration::DataMigrator, global::{CONFIG, DATABASE_CONNECTIONS}, utils::Runnable}; use caretta::{cli::*, utils::runnable::Runnable};
pub use server::*;
#[derive(Debug, Parser)] #[derive(Debug, Parser, Runnable)]
pub struct Cli { pub struct Cli {
#[command(subcommand)] #[command(subcommand)]
command: Option<CliCommand>, #[runnable]
#[command(flatten)] command: CliCommand
config: ConfigArgs,
}
impl Runnable for Cli {
fn run(self, app_name: &'static str) {
if let Some(x) = self.command {
x.run(app_name)
} else {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
let config: caretta_sync::config::Config = self.config.into_config(app_name).await;
let _ = CONFIG.get_or_init::<Config>(config).await;
});
//let _ = DATABASE_CONNECTIONS.get_or_init_unchecked(&config, DataMigrator).await;
Gui{}.run(app_name)
}
}
} }
#[derive(Debug, Subcommand, Runnable)] #[derive(Debug, Subcommand, Runnable)]
pub enum CliCommand { pub enum CliCommand {
Config(ConfigCommandArgs), Config(ConfigCommandArgs),
Device(DeviceCommandArgs), Device(DeviceCommandArgs),
Logs(LogsCommandArgs),
Peer(PeerCommandArgs), Peer(PeerCommandArgs),
Serve(ServeCommandArgs<Server>), Server(ServerCommandArgs),
} }

View file

@ -1,29 +1,19 @@
use std::marker::PhantomData; use caretta_example_core::server::Server;
use clap::Args; use clap::Args;
use caretta_sync_core::{config::Config, data::migration::DataMigrator, global::{CONFIG, DATABASE_CONNECTIONS}, server::ServerTrait, utils::runnable::Runnable}; use caretta::{config::Config, data::migration::DataMigrator, global::{CONFIG, DATABASE_CONNECTIONS}, server::ServerTrait, utils::runnable::Runnable};
use libp2p::{noise, ping, swarm::{NetworkBehaviour, SwarmEvent}, tcp, yamux, Swarm}; use libp2p::{noise, ping, swarm::{NetworkBehaviour, SwarmEvent}, tcp, yamux, Swarm};
use super::ConfigArgs; use super::ConfigArgs;
#[derive(Args, Debug)] #[derive(Args, Debug)]
pub struct ServeCommandArgs<T> pub struct ServerCommandArgs {
where
T: ServerTrait
{
#[arg(skip)]
server: PhantomData<T>,
#[command(flatten)] #[command(flatten)]
config: ConfigArgs, config: ConfigArgs,
} }
impl<T> Runnable for ServeCommandArgs<T> impl Runnable for ServerCommandArgs {
where
T: ServerTrait
{
#[tokio::main]
async fn run(self, app_name: &'static str) { async fn run(self, app_name: &'static str) {
let config = CONFIG.get_or_init::<Config>(self.config.into_config(app_name).await).await; let config = CONFIG.get_or_init::<Config>(self.config.into_config(app_name).await).await;
let _ = DATABASE_CONNECTIONS.get_or_init_unchecked(&config, DataMigrator).await; let _ = DATABASE_CONNECTIONS.get_or_init_unchecked(&config, DataMigrator).await;
T::serve_all(config).await.unwrap(); Server::serve_all(config).await.unwrap();
} }
} }

View file

View file

@ -1,10 +1,14 @@
use caretta_sync::utils::Runnable; use caretta::utils::runnable::Runnable;
use caretta_sync_example_core::global::APP_NAME; use caretta_example_core::global::APP_NAME;
use clap::Parser; use clap::Parser;
use crate::cli::Cli; use crate::cli::Cli;
fn main() { mod cli;
mod ipc;
#[tokio::main]
async fn main() {
let args = Cli::parse(); let args = Cli::parse();
args.run(APP_NAME); args.run(APP_NAME).await;
} }

View file

View file

@ -1,7 +0,0 @@
/build
.gradle
.idea
.DS_Store
build
.cxx
local.properties

View file

@ -1,20 +1,9 @@
[package] [package]
name = "caretta-sync-example-mobile" name = "caretta-example-mobile"
edition.workspace = true version = "0.1.0"
version.workspace = true authors = ["fluo10 <fluo10.dev@fireturtle.net>"]
description.workspace = true edition = "2021"
license.workspace = true
repository.workspace = true
[[bin]]
name = "caretta_sync_example"
path = "src/main.rs"
[lib]
name = "caretta_sync_example"
crate-type = ["lib", "cdylib"]
[dependencies] [dependencies]
bevy.workspace = true dioxus.workspace = true
caretta-sync-example-core.path = "../core" caretta-example-core.path = "../core"
caretta-sync.path = "../.."

View file

@ -1,25 +0,0 @@
.PHONY: xcodebuild run install boot-sim generate clean
DEVICE = ${DEVICE_ID}
ifndef DEVICE_ID
DEVICE=$(shell xcrun simctl list devices 'iOS' | grep -v 'unavailable' | grep -v '^--' | grep -v '==' | head -n 1 | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})")
endif
run: install
xcrun simctl launch --console $(DEVICE) net.fireturtle.caretta-sync-example
boot-sim:
xcrun simctl boot $(DEVICE) || true
install: xcodebuild-simulator boot-sim
xcrun simctl install $(DEVICE) build/Build/Products/Debug-iphonesimulator/caretta_sync_example.app
xcodebuild-simulator:
IOS_TARGETS=x86_64-apple-ios xcodebuild -scheme caretta_sync_example -configuration Debug -derivedDataPath build -destination "id=$(DEVICE)"
xcodebuild-iphone:
IOS_TARGETS=aarch64-apple-ios xcodebuild -scheme caretta_sync_example -configuration Debug -derivedDataPath build -arch arm64
clean:
rm -r build
cargo clean

View file

@ -1,68 +0,0 @@
#!/usr/bin/env bash
# based on https://github.com/mozilla/glean/blob/main/build-scripts/xc-universal-binary.sh
set -eux
PATH=$PATH:$HOME/.cargo/bin
PROFILE=debug
RELFLAG=
if [[ "$CONFIGURATION" != "Debug" ]]; then
PROFILE=release
RELFLAG=--release
fi
set -euvx
# add homebrew bin path, as it's the most commonly used package manager on macOS
# this is needed for cmake on apple arm processors as it's not available by default
export PATH="$PATH:/opt/homebrew/bin"
# Make Cargo output cache files in Xcode's directories
export CARGO_TARGET_DIR="$DERIVED_FILE_DIR/cargo"
# Xcode places `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin`
# at the front of the path, with makes the build fail with `ld: library 'System' not found`, upstream issue:
# <https://github.com/rust-lang/rust/issues/80817>.
#
# Work around it by resetting the path, so that we use the system `cc`.
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
IS_SIMULATOR=0
if [ "${LLVM_TARGET_TRIPLE_SUFFIX-}" = "-simulator" ]; then
IS_SIMULATOR=1
fi
EXECUTABLES=
for arch in $ARCHS; do
case "$arch" in
x86_64)
if [ $IS_SIMULATOR -eq 0 ]; then
echo "Building for x86_64, but not a simulator build. What's going on?" >&2
exit 2
fi
# Intel iOS simulator
export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios"
TARGET=x86_64-apple-ios
;;
arm64)
if [ $IS_SIMULATOR -eq 0 ]; then
# Hardware iOS targets
TARGET=aarch64-apple-ios
else
# M1 iOS simulator
TARGET=aarch64-apple-ios-sim
fi
esac
cd ..
cargo build $RELFLAG --target $TARGET --bin caretta_sync_example
cd -
# Collect the executables
EXECUTABLES="$EXECUTABLES $DERIVED_FILE_DIR/cargo/$TARGET/$PROFILE/caretta_sync_example"
done
# Combine executables, and place them at the output path excepted by Xcode
lipo -create -output "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" $EXECUTABLES

View file

@ -1,307 +0,0 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 77;
objects = {
/* Begin PBXFileReference section */
B617AE7C2E5D5E5A0013202E /* caretta_sync_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = caretta_sync_example.app; sourceTree = BUILT_PRODUCTS_DIR; };
B698F93D2E5E743A00C7EE06 /* caretta_sync_example.app */ = {isa = PBXFileReference; lastKnownFileType = wrapper.application; name = caretta_sync_example.app; path = "build/Build/Products/Debug-iphonesimulator/caretta_sync_example.app"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXGroup section */
B617AE732E5D5E5A0013202E = {
isa = PBXGroup;
children = (
B617AE7D2E5D5E5A0013202E /* Products */,
B698F93D2E5E743A00C7EE06 /* caretta_sync_example.app */,
);
sourceTree = "<group>";
};
B617AE7D2E5D5E5A0013202E /* Products */ = {
isa = PBXGroup;
children = (
B617AE7C2E5D5E5A0013202E /* caretta_sync_example.app */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
B617AE7B2E5D5E5A0013202E /* caretta_sync_example */ = {
isa = PBXNativeTarget;
buildConfigurationList = B617AE872E5D5E5B0013202E /* Build configuration list for PBXNativeTarget "caretta_sync_example" */;
buildPhases = (
B698F8CE2E5D609900C7EE06 /* ShellScript */,
);
buildRules = (
);
dependencies = (
);
name = caretta_sync_example;
packageProductDependencies = (
);
productName = caretta_sync_example;
productReference = B617AE7C2E5D5E5A0013202E /* caretta_sync_example.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
B617AE742E5D5E5A0013202E /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = NO;
LastSwiftUpdateCheck = 1640;
LastUpgradeCheck = 1640;
TargetAttributes = {
B617AE7B2E5D5E5A0013202E = {
CreatedOnToolsVersion = 16.4;
};
};
};
buildConfigurationList = B617AE772E5D5E5A0013202E /* Build configuration list for PBXProject "caretta_sync_example" */;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = B617AE732E5D5E5A0013202E;
minimizedProjectReferenceProxies = 1;
preferredProjectObjectVersion = 77;
productRefGroup = B617AE7D2E5D5E5A0013202E /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
B617AE7B2E5D5E5A0013202E /* caretta_sync_example */,
);
};
/* End PBXProject section */
/* Begin PBXShellScriptBuildPhase section */
B698F8CE2E5D609900C7EE06 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"$(SRCROOT)/build_rust_deps.sh",
);
outputFileListPaths = (
);
outputPaths = (
$TARGET_BUILD_DIR/$EXECUTABLE_PATH,
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "./build_rust_deps.sh\n";
};
/* End PBXShellScriptBuildPhase section */
/* Begin XCBuildConfiguration section */
B617AE852E5D5E5B0013202E /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
B617AE862E5D5E5B0013202E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
B617AE882E5D5E5B0013202E /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "net.fireturtle.caretta-sync-example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
B617AE892E5D5E5B0013202E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "net.fireturtle.caretta-sync-example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
B617AE772E5D5E5A0013202E /* Build configuration list for PBXProject "caretta_sync_example" */ = {
isa = XCConfigurationList;
buildConfigurations = (
B617AE852E5D5E5B0013202E /* Debug */,
B617AE862E5D5E5B0013202E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
B617AE872E5D5E5B0013202E /* Build configuration list for PBXNativeTarget "caretta_sync_example" */ = {
isa = XCConfigurationList;
buildConfigurations = (
B617AE882E5D5E5B0013202E /* Debug */,
B617AE892E5D5E5B0013202E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Debug;
};
/* End XCConfigurationList section */
};
rootObject = B617AE742E5D5E5A0013202E /* Project object */;
}

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>caretta_sync_example.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>

View file

@ -1,70 +0,0 @@
use bevy::{
color::palettes::basic::*,
input::{gestures::RotationGesture, touch::TouchPhase},
log::{Level, LogPlugin},
prelude::*,
window::{AppLifecycle, ScreenEdge, WindowMode},
winit::WinitSettings,
};
#[bevy_main]
pub fn main() {
let mut app = App::new();
app.add_plugins(
DefaultPlugins.set(LogPlugin {
level: Level::DEBUG,
filter: "wgpu=error,bevy_render=info,bevy_ecs_trace".to_string(),
..Default::default()
})
.set(WindowPlugin {
primary_window: Some(Window {
resizable: false,
mode: WindowMode::BorderlessFullscreen(MonitorSelection::Primary),
recognize_rotation_gesture: true,
prefers_home_indicator_hidden: true,
prefers_status_bar_hidden: true,
preferred_screen_edges_deferring_system_gestures: ScreenEdge::Bottom,
..default()
}),
..default()
}),
)
.insert_resource(WinitSettings::mobile())
.add_systems(Startup, setup_scene)
.run();
}
fn setup_scene(
mut commands: Commands,
) {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
// MSAA makes some Android devices panic, this is under investigation
// https://github.com/bevyengine/bevy/issues/8229
#[cfg(target_os = "android")]
Msaa::Off,
));
commands
.spawn((
Button,
Node {
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
position_type: PositionType::Absolute,
left: Val::Px(50.0),
right: Val::Px(50.0),
bottom: Val::Px(50.0),
..default()
}
))
.with_child((
Text::new(format!( "{:?}", std::fs::read_dir(std::env::current_dir().unwrap()).unwrap().map(|x| x.unwrap().path()).collect::<Vec<std::path::PathBuf>>())),
TextFont {
font_size: 16.0,
..default()
},
TextColor::BLACK,
TextLayout::new_with_justify(Justify::Center),
));
}

View file

@ -1 +1,3 @@
use caretta_sync_example::main; fn main() {
dioxus::launch(caretta_examples_core::ui::plain::App);
}

View file

@ -1,5 +1,5 @@
[package] [package]
name = "caretta-sync-mobile" name = "caretta-mobile"
edition.workspace = true edition.workspace = true
version.workspace = true version.workspace = true
description.workspace = true description.workspace = true
@ -8,7 +8,7 @@ repository.workspace = true
[features] [features]
default = [] default = []
test = ["caretta-sync-core/test"] test = ["caretta-core/test"]
[dependencies] [dependencies]
caretta-sync-core.workspace = true caretta-core.workspace = true

View file

@ -1,22 +1,5 @@
pub use caretta_sync_core::*; pub use caretta_core::*;
#[cfg(feature = "desktop")]
#[cfg(feature = "bevy")] pub use caretta_desktop::*;
pub use caretta_sync_bevy as bevy;
#[cfg(feature = "cli")]
pub use caretta_sync_cli::*;
#[cfg(feature = "mobile")] #[cfg(feature = "mobile")]
pub use caretta_sync_mobile::*; pub use caretta_mobile::*;
#[cfg(feature = "macros")]
pub mod utils {
pub use caretta_sync_core::utils::{
runnable::Runnable,
emptiable::Emptiable,
mergeable::Mergeable,
};
pub use caretta_sync_macros::{
Runnable,
Emptiable,
Mergeable,
};
}