From 768934231d7e1bace519eb5da3238d294dd156dd Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Thu, 28 Dec 2023 14:53:29 +0100 Subject: [PATCH] add gitbutler-core package and move IDs to it --- Cargo.lock | 10 ++++++++++ Cargo.toml | 7 +++++++ gitbutler-app/Cargo.toml | 7 ++++--- gitbutler-app/src/lib.rs | 7 ++++++- gitbutler-core/Cargo.toml | 14 ++++++++++++++ {gitbutler-app => gitbutler-core}/src/id.rs | 5 +++++ gitbutler-core/src/lib.rs | 1 + 7 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 gitbutler-core/Cargo.toml rename {gitbutler-app => gitbutler-core}/src/id.rs (94%) create mode 100644 gitbutler-core/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 7bb6abc8f..909e694b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1792,6 +1792,7 @@ dependencies = [ "futures", "git2", "git2-hooks", + "gitbutler-core", "governor", "itertools 0.12.0", "lazy_static", @@ -1838,6 +1839,15 @@ dependencies = [ "zip", ] +[[package]] +name = "gitbutler-core" +version = "0.0.0" +dependencies = [ + "rusqlite", + "serde", + "uuid", +] + [[package]] name = "glib" version = "0.15.12" diff --git a/Cargo.toml b/Cargo.toml index c3ef49bdf..1eca08634 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,16 @@ [workspace] members = [ "gitbutler-app", + "gitbutler-core", ] resolver = "2" +[workspace.dependencies] +gitbutler-core = { path = "gitbutler-core" } +uuid = "1.6.1" +serde = { version = "1.0", features = ["derive"] } +rusqlite = { version = "0.29.0", features = [ "bundled", "blob" ] } + [profile.release] codegen-units = 1 # Compile crates one after another so the compiler can optimize better lto = true # Enables link to optimizations diff --git a/gitbutler-app/Cargo.toml b/gitbutler-app/Cargo.toml index c9e0b9a0a..48587dbd2 100644 --- a/gitbutler-app/Cargo.toml +++ b/gitbutler-app/Cargo.toml @@ -35,6 +35,7 @@ fslock = "0.2.1" futures = "0.3" git2 = { version = "0.18.1", features = ["vendored-openssl", "vendored-libgit2"] } git2-hooks = "0.3" +gitbutler-core = { workspace = true } governor = "0.6.0" itertools = "0.12" lazy_static = "1.4.0" @@ -50,10 +51,10 @@ rand = "0.8.5" refinery = { version = "0.8", features = [ "rusqlite" ] } reqwest = "0.11.22" resolve-path = "0.1.0" -rusqlite = { version = "0.29.0", features = [ "bundled", "blob" ] } +rusqlite = { workspace = true } sentry = { version = "0.32", optional = true, features = ["backtrace", "contexts", "panic", "transport", "anyhow", "debug-images", "reqwest", "native-tls" ] } sentry-tracing = "0.32.0" -serde = { version = "1.0", features = ["derive"] } +serde = { workspace = true } serde_json = { version = "1.0", features = [ "std", "arbitrary_precision" ] } sha1 = "0.10.6" sha2 = "0.10.8" @@ -73,7 +74,7 @@ tracing-appender = "0.2.3" tracing-subscriber = "0.3.17" url = "2.4" urlencoding = "2.1.3" -uuid = "1.6.1" +uuid = { workspace = true } walkdir = "2.3.2" zip = "0.6.5" diff --git a/gitbutler-app/src/lib.rs b/gitbutler-app/src/lib.rs index 2519e6aa5..698a487ab 100644 --- a/gitbutler-app/src/lib.rs +++ b/gitbutler-app/src/lib.rs @@ -14,7 +14,6 @@ pub mod fs; pub mod gb_repository; pub mod git; pub mod github; -pub mod id; pub mod keys; pub mod logs; pub mod menu; @@ -37,3 +36,9 @@ pub mod zip; #[cfg(test)] pub mod test_utils; + +#[deprecated = "use `gitbutler-core` instead"] +pub mod id { + #[deprecated = "use `gitbutler-core` instead"] + pub use gitbutler_core::id::Id; +} diff --git a/gitbutler-core/Cargo.toml b/gitbutler-core/Cargo.toml new file mode 100644 index 000000000..a243af8b8 --- /dev/null +++ b/gitbutler-core/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "gitbutler-core" +version = "0.0.0" +edition = "2021" + +[features] +default = ["serde", "rusqlite"] +serde = ["dep:serde"] +rusqlite = ["dep:rusqlite"] + +[dependencies] +rusqlite = { workspace = true, optional = true } +serde = { workspace = true, optional = true } +uuid = { workspace = true } diff --git a/gitbutler-app/src/id.rs b/gitbutler-core/src/id.rs similarity index 94% rename from gitbutler-app/src/id.rs rename to gitbutler-core/src/id.rs index 64afa0835..6335eda1c 100644 --- a/gitbutler-app/src/id.rs +++ b/gitbutler-core/src/id.rs @@ -1,5 +1,6 @@ use std::{fmt, hash::Hash, marker::PhantomData, str}; +#[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; use uuid::Uuid; @@ -35,6 +36,7 @@ impl Default for Id { } } +#[cfg(feature = "rusqlite")] impl rusqlite::types::FromSql for Id { fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult { Uuid::parse_str(value.as_str()?) @@ -43,6 +45,7 @@ impl rusqlite::types::FromSql for Id { } } +#[cfg(feature = "rusqlite")] impl rusqlite::ToSql for Id { fn to_sql(&self) -> rusqlite::Result> { Ok(rusqlite::types::ToSqlOutput::from(self.0.to_string())) @@ -63,6 +66,7 @@ impl From for Id { } } +#[cfg(feature = "serde")] impl<'de, T> Deserialize<'de> for Id { fn deserialize(deserializer: D) -> Result where @@ -72,6 +76,7 @@ impl<'de, T> Deserialize<'de> for Id { } } +#[cfg(feature = "serde")] impl Serialize for Id { fn serialize(&self, serializer: S) -> Result where diff --git a/gitbutler-core/src/lib.rs b/gitbutler-core/src/lib.rs new file mode 100644 index 000000000..fd6bb6c43 --- /dev/null +++ b/gitbutler-core/src/lib.rs @@ -0,0 +1 @@ +pub mod id;