From aa1a1900a0ebedecefc4413fd3e5ad1779b4d860 Mon Sep 17 00:00:00 2001 From: Tin Rabzelj Date: Mon, 7 Oct 2024 01:16:49 +0200 Subject: [PATCH] Refactor crates deps --- Cargo.toml | 50 +++++++++++- README.md | 6 +- bomboni_common/Cargo.toml | 32 ++++---- bomboni_common/src/date_time/mod.rs | 9 +-- bomboni_common/src/id/mod.rs | 2 +- bomboni_common/src/lib.rs | 12 --- bomboni_core/Cargo.toml | 8 +- bomboni_fs/Cargo.toml | 2 - bomboni_prost/Cargo.toml | 14 ++-- bomboni_proto/Cargo.toml | 36 +++++---- bomboni_proto/build.rs | 19 +++-- bomboni_proto/src/lib.rs | 12 --- bomboni_request/Cargo.toml | 41 +++++----- bomboni_request/src/error.rs | 2 +- bomboni_request/src/lib.rs | 12 --- bomboni_request/src/parse/mod.rs | 85 ++++++++++++--------- bomboni_request/src/testing/mod.rs | 10 --- bomboni_request_derive/Cargo.toml | 13 ++-- bomboni_request_derive/src/parse/mod.rs | 58 +++++++------- bomboni_request_derive/src/parse/options.rs | 10 ++- bomboni_template/Cargo.toml | 14 ++-- bomboni_wasm/Cargo.toml | 15 ++-- bomboni_wasm/src/lib.rs | 11 +-- bomboni_wasm_core/Cargo.toml | 14 ++-- bomboni_wasm_core/src/options.rs | 3 + bomboni_wasm_derive/Cargo.toml | 17 +++-- bomboni_wasm_derive/src/wasm.rs | 21 ++--- 27 files changed, 272 insertions(+), 256 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2d4aebe..462c1a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,53 @@ bomboni_common = { path = "bomboni_common", version = "0.1.60" } bomboni_prost = { path = "bomboni_prost", version = "0.1.60", default-features = false, optional = true } bomboni_proto = { path = "bomboni_proto", version = "0.1.60", default-features = false, optional = true } -bomboni_request = { path = "bomboni_request", version = "0.1.60", default-features = false, optional = true } +bomboni_request = { path = "bomboni_request", version = "0.1.60", default-features = false, optional = true, features = [ + "root-crate", +] } bomboni_template = { path = "bomboni_template", version = "0.1.60", default-features = false, optional = true } -bomboni_wasm = { path = "bomboni_wasm", version = "0.1.60", default-features = false, optional = true } +bomboni_wasm = { path = "bomboni_wasm", version = "0.1.60", default-features = false, optional = true, features = [ + "root-crate", +] } bomboni_fs = { path = "bomboni_fs", version = "0.1.60", default-features = false, optional = true } + +[workspace.dependencies] +bomboni_core = { path = "bomboni_core", version = "0.1.60" } +bomboni_common = { path = "bomboni_common", version = "0.1.60" } +bomboni_prost = { path = "bomboni_prost", version = "0.1.60" } +bomboni_proto = { path = "bomboni_proto", version = "0.1.60" } +bomboni_request = { path = "bomboni_request", version = "0.1.60" } +bomboni_request_derive = { path = "bomboni_request_derive", version = "0.1.60" } +bomboni_template = { path = "bomboni_template", version = "0.1.60" } +bomboni_wasm = { path = "bomboni_wasm", version = "0.1.60" } +bomboni_wasm_core = { path = "bomboni_wasm_core", version = "0.1.60" } +bomboni_wasm_derive = { path = "bomboni_wasm_derive", version = "0.1.60" } +bomboni_fs = { path = "bomboni_fs", version = "0.1.60" } + +thiserror = "1.0.64" +regex = "1.11.0" +time = "0.3.36" +chrono = "0.4.38" +ulid = "1.1.3" +bytes = "1.7.2" +serde = "1.0.210" +serde_json = "1.0.128" +serde_derive_internals = "0.29.1" +convert_case = "0.6.0" +handlebars = "6.1.0" +rand = "0.8.5" +itertools = "0.13.0" + +http = "1.1.0" +prost = "0.13.3" +prost-types = "0.13.3" +prost-build = "0.13.3" +tonic = "0.12.3" +tokio = "1.40.0" +parking_lot = "0.12.3" +postgres-types = "0.2.8" + +proc-macro2 = "1.0.86" +syn = "2.0.79" +quote = "1.0.37" +prettyplease = "0.2.22" +darling = "0.20.10" diff --git a/README.md b/README.md index 411b5e7..90b9cdb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # Bomboni: Utility Library for Rust -WIP. +Work in progress (WIP). + +This project includes utilities for working with WASM, extras for protobuf/prost +(like constants for field names), tools for gRPC requests following Google AIP +designs, etc. diff --git a/bomboni_common/Cargo.toml b/bomboni_common/Cargo.toml index 60a50a4..2897387 100644 --- a/bomboni_common/Cargo.toml +++ b/bomboni_common/Cargo.toml @@ -27,28 +27,26 @@ js = [] postgres = ["dep:postgres-types", "dep:bytes"] [dependencies] -bomboni_wasm = { path = "../bomboni_wasm", version = "0.1.60", features = [ - "derive", -], optional = true } +bomboni_wasm = { workspace = true, features = ["derive"], optional = true } -thiserror = "1.0.63" -regex = "1.10.5" -time = { version = "0.3.36", features = ["formatting", "parsing"] } -ulid = "1.1.3" +thiserror.workspace = true +regex.workspace = true +time = { workspace = true, features = ["formatting", "parsing"] } +ulid.workspace = true -tokio = { version = "1.39.1", features = ["time", "sync"], optional = true } -parking_lot = { version = "0.12.3", optional = true } -serde = { version = "1.0.204", features = ["derive"], optional = true } -chrono = { version = "0.4.38", optional = true } -postgres-types = { version = "0.2.7", features = [ +tokio = { workspace = true, features = ["time", "sync"], optional = true } +parking_lot = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"], optional = true } +chrono = { workspace = true, optional = true } +postgres-types = { workspace = true, features = [ "with-time-0_3", ], optional = true } -bytes = { version = "1.6.1", optional = true } +bytes = { workspace = true, optional = true } [target.'cfg(all(target_family = "wasm", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies] -wasm-bindgen = { version = "0.2.92", optional = true } -js-sys = { version = "0.3.69", optional = true } +wasm-bindgen = { version = "0.2.93", optional = true } +js-sys = { version = "0.3.70", optional = true } [dev-dependencies] -serde_json = "1.0.120" -tokio = { version = "1.39.1", features = ["rt-multi-thread", "macros"] } +serde_json.workspace = true +tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } diff --git a/bomboni_common/src/date_time/mod.rs b/bomboni_common/src/date_time/mod.rs index 257ddd0..9af7291 100644 --- a/bomboni_common/src/date_time/mod.rs +++ b/bomboni_common/src/date_time/mod.rs @@ -20,7 +20,7 @@ mod postgres; ), derive(bomboni_wasm::Wasm), wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, wasm_abi, js_value { convert_string }, ) @@ -33,12 +33,7 @@ mod postgres; feature = "js", ), derive(bomboni_wasm::Wasm), - wasm( - bomboni_crate = crate::bomboni, - wasm_abi, - js_value, - override_type = "Date", - ) + wasm(wasm_abi, js_value, override_type = "Date",) )] pub struct UtcDateTime(OffsetDateTime); diff --git a/bomboni_common/src/id/mod.rs b/bomboni_common/src/id/mod.rs index 8d22e11..397e970 100644 --- a/bomboni_common/src/id/mod.rs +++ b/bomboni_common/src/id/mod.rs @@ -27,7 +27,7 @@ pub mod worker; ), derive(bomboni_wasm::Wasm), wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, wasm_abi, js_value { convert_string }, ) diff --git a/bomboni_common/src/lib.rs b/bomboni_common/src/lib.rs index 79e625a..d973adb 100644 --- a/bomboni_common/src/lib.rs +++ b/bomboni_common/src/lib.rs @@ -1,15 +1,3 @@ pub mod date_time; pub mod id; pub mod macros; - -#[doc(hidden)] -#[cfg(all( - target_family = "wasm", - not(any(target_os = "emscripten", target_os = "wasi")), - feature = "wasm" -))] -pub mod bomboni { - pub mod wasm { - pub use bomboni_wasm::*; - } -} diff --git a/bomboni_core/Cargo.toml b/bomboni_core/Cargo.toml index 4d90e53..00ad442 100644 --- a/bomboni_core/Cargo.toml +++ b/bomboni_core/Cargo.toml @@ -14,7 +14,7 @@ name = "bomboni_core" path = "src/lib.rs" [dependencies] -convert_case = "0.6.0" -proc-macro2 = "1.0.86" -syn = { version = "2.0.72", features = ["full"] } -quote = "1.0.36" +convert_case.workspace = true +proc-macro2.workspace = true +syn = { workspace = true, features = ["full"] } +quote.workspace = true diff --git a/bomboni_fs/Cargo.toml b/bomboni_fs/Cargo.toml index a352e63..558614e 100644 --- a/bomboni_fs/Cargo.toml +++ b/bomboni_fs/Cargo.toml @@ -12,5 +12,3 @@ edition = "2021" [lib] name = "bomboni_fs" path = "src/lib.rs" - -[dependencies] diff --git a/bomboni_prost/Cargo.toml b/bomboni_prost/Cargo.toml index a60fb44..60e6701 100644 --- a/bomboni_prost/Cargo.toml +++ b/bomboni_prost/Cargo.toml @@ -14,11 +14,11 @@ name = "bomboni_prost" path = "src/lib.rs" [dependencies] -bomboni_core = { path = "../bomboni_core", version = "0.1.60" } +bomboni_core = { workspace = true } -prost = "0.13.1" -prost-types = "0.13.1" -proc-macro2 = "1.0.86" -syn = { version = "2.0.72", features = ["full"] } -quote = "1.0.36" -prettyplease = "0.2.20" +prost.workspace = true +prost-types.workspace = true +proc-macro2.workspace = true +syn = { workspace = true, features = ["full"] } +quote.workspace = true +prettyplease.workspace = true diff --git a/bomboni_proto/Cargo.toml b/bomboni_proto/Cargo.toml index cb9747b..6f38966 100644 --- a/bomboni_proto/Cargo.toml +++ b/bomboni_proto/Cargo.toml @@ -19,40 +19,38 @@ testing = [] tonic = ["dep:tonic", "dep:http"] chrono = ["dep:chrono", "bomboni_common/chrono"] wasm = [ + "bomboni_common/wasm", "dep:wasm-bindgen", "dep:js-sys", "dep:serde-wasm-bindgen", - "bomboni_common/wasm", "dep:bomboni_wasm", ] js = ["bomboni_common/js"] [dependencies] -bomboni_common = { path = "../bomboni_common", features = [ - "serde", -], version = "0.1.60" } +bomboni_common = { workspace = true, features = ["serde"] } -thiserror = "1.0.63" -time = { version = "0.3.36", features = ["serde", "formatting", "parsing"] } -prost = "0.13.1" -serde = { version = "1.0.204", features = ["derive"] } -serde_json = "1.0.120" -pot = "3.0.0" +thiserror.workspace = true +time = { workspace = true, features = ["serde", "formatting", "parsing"] } +prost.workspace = true +serde = { workspace = true, features = ["derive"] } +serde_json.workspace = true +pot = "3.0.1" -tonic = { version = "0.12.1", optional = true } -http = { version = "1.1.0", optional = true } -chrono = { version = "0.4.38", optional = true } +tonic = { workspace = true, optional = true } +http = { workspace = true, optional = true } +chrono = { workspace = true, optional = true } [target.'cfg(all(target_family = "wasm", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies] -bomboni_wasm = { path = "../bomboni_wasm", version = "0.1.60", optional = true } +bomboni_wasm = { workspace = true, optional = true, features = ["derive"] } -wasm-bindgen = { version = "0.2.92", optional = true } -js-sys = { version = "0.3.69", optional = true } +wasm-bindgen = { version = "0.2.93", optional = true } +js-sys = { version = "0.3.70", optional = true } serde-wasm-bindgen = { version = "0.6.5", optional = true } [dev-dependencies] -serde_json = "1.0.120" +serde_json.workspace = true [build-dependencies] -bomboni_prost = { path = "../bomboni_prost", version = "0.1.60" } -prost-build = "0.13.1" +bomboni_prost = { workspace = true } +prost-build.workspace = true diff --git a/bomboni_proto/build.rs b/bomboni_proto/build.rs index 434e0e0..02915cc 100644 --- a/bomboni_proto/build.rs +++ b/bomboni_proto/build.rs @@ -1,10 +1,9 @@ -use std::{error::Error, path::PathBuf}; - use bomboni_prost::{ compile, config::{ApiConfig, CompileConfig}, }; use prost_build::Config; +use std::{error::Error, path::PathBuf}; fn main() -> Result<(), Box> { let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); @@ -149,7 +148,7 @@ fn build_wasm(config: &mut Config) { format!(".google.rpc.{type_name}"), r" #[derive(bomboni_wasm::Wasm)] - #[wasm(bomboni_crate = crate::bomboni, wasm_abi)] + #[wasm(bomboni_wasm_crate = bomboni_wasm, wasm_abi)] ", ); } @@ -177,7 +176,7 @@ fn build_wasm(config: &mut Config) { r#" #[derive(bomboni_wasm::Wasm)] #[wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, wasm_abi, js_value { convert_string }, override_type = "`${number}.${number}s` | `${number}s`", @@ -189,7 +188,7 @@ fn build_wasm(config: &mut Config) { r#" #[derive(bomboni_wasm::Wasm)] #[wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, wasm_abi, js_value, rename = "JsonObject", @@ -202,7 +201,7 @@ fn build_wasm(config: &mut Config) { r#" #[derive(bomboni_wasm::Wasm)] #[wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, wasm_abi, js_value, rename = "JsonValue", @@ -217,7 +216,7 @@ fn build_wasm(config: &mut Config) { r#" #[derive(bomboni_wasm::Wasm)] #[wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, wasm_abi, js_value, override_type = "undefined | null", @@ -229,7 +228,7 @@ fn build_wasm(config: &mut Config) { r#" #[derive(bomboni_wasm::Wasm)] #[wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, wasm_abi, js_value, override_type = "Date", @@ -242,7 +241,7 @@ fn build_wasm(config: &mut Config) { r#" #[derive(bomboni_wasm::Wasm)] #[wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, wasm_abi, js_value, override_type = "null", @@ -254,7 +253,7 @@ fn build_wasm(config: &mut Config) { " #[derive(bomboni_wasm::Wasm)] #[wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, wasm_abi, js_value { convert_string }, )] diff --git a/bomboni_proto/src/lib.rs b/bomboni_proto/src/lib.rs index 257a77d..4fba639 100644 --- a/bomboni_proto/src/lib.rs +++ b/bomboni_proto/src/lib.rs @@ -35,15 +35,3 @@ pub mod google { crate::include_proto!("google.rpc.plus"); } } - -#[doc(hidden)] -#[cfg(all( - target_family = "wasm", - not(any(target_os = "emscripten", target_os = "wasi")), - feature = "wasm" -))] -pub mod bomboni { - pub mod wasm { - pub use bomboni_wasm::*; - } -} diff --git a/bomboni_request/Cargo.toml b/bomboni_request/Cargo.toml index 40c0c20..bea4b42 100644 --- a/bomboni_request/Cargo.toml +++ b/bomboni_request/Cargo.toml @@ -15,6 +15,7 @@ path = "src/lib.rs" [features] default = ["testing"] +root-crate = ["bomboni_request_derive/root-crate"] testing = [] derive = [] tonic = ["bomboni_proto/tonic", "dep:tonic"] @@ -29,36 +30,34 @@ wasm = [ postgres = ["dep:postgres-types", "dep:bytes"] [dependencies] -bomboni_common = { path = "../bomboni_common", version = "0.1.60" } -bomboni_proto = { path = "../bomboni_proto", version = "0.1.60" } -bomboni_request_derive = { path = "../bomboni_request_derive", version = "0.1.60" } -bomboni_wasm = { path = "../bomboni_wasm", version = "0.1.60", features = [ - "derive", -], optional = true } +bomboni_common = { workspace = true } +bomboni_proto = { workspace = true } +bomboni_request_derive = { workspace = true } +bomboni_wasm = { workspace = true, features = ["derive"], optional = true } -thiserror = "1.0.63" -itertools = "0.13.0" -prost = "0.13.1" -pest = "2.7.11" -pest_derive = "2.7.11" +thiserror.workspace = true +prost.workspace = true +rand.workspace = true +regex.workspace = true +itertools.workspace = true +serde = { workspace = true, features = ["derive"] } +pest = "2.7.13" +pest_derive = "2.7.13" base64ct = { version = "1.6.0", features = ["alloc"] } aes-gcm = { version = "0.10.3", features = ["alloc"] } blake2 = "0.10.6" rsa = "0.9.6" -rand = "0.8.5" -regex = "1.10.5" -serde = { version = "1.0.204", features = ["derive"] } -tonic = { version = "0.12.1", optional = true } -getrandom = { version = "0.2.15", features = ["js"], optional = true } -postgres-types = { version = "0.2.7", features = [ +tonic = { workspace = true, optional = true } +postgres-types = { workspace = true, features = [ "with-time-0_3", ], optional = true } -bytes = { version = "1.6.1", optional = true } +bytes = { workspace = true, optional = true } +getrandom = { version = "0.2.15", features = ["js"], optional = true } [target.'cfg(all(target_family = "wasm", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies] -wasm-bindgen = { version = "0.2.92", optional = true } -js-sys = { version = "0.3.69", optional = true } +wasm-bindgen = { version = "0.2.93", optional = true } +js-sys = { version = "0.3.70", optional = true } [dev-dependencies] -serde_json = "1.0.120" +serde_json.workspace = true diff --git a/bomboni_request/src/error.rs b/bomboni_request/src/error.rs index ccd650a..d50d522 100644 --- a/bomboni_request/src/error.rs +++ b/bomboni_request/src/error.rs @@ -18,7 +18,7 @@ use thiserror::Error; ), derive(bomboni_wasm::Wasm), wasm( - bomboni_crate = crate::bomboni, + bomboni_wasm_crate = bomboni_wasm, into_wasm_abi, proxy { source = Status, try_from = RequestParse::parse }, ) diff --git a/bomboni_request/src/lib.rs b/bomboni_request/src/lib.rs index 20e52d6..392bf8c 100644 --- a/bomboni_request/src/lib.rs +++ b/bomboni_request/src/lib.rs @@ -23,15 +23,3 @@ pub mod testing; pub mod derive { pub use bomboni_request_derive::*; } - -#[doc(hidden)] -#[cfg(all( - target_family = "wasm", - not(any(target_os = "emscripten", target_os = "wasi")), - feature = "wasm" -))] -pub mod bomboni { - pub mod wasm { - pub use bomboni_wasm::*; - } -} diff --git a/bomboni_request/src/parse/mod.rs b/bomboni_request/src/parse/mod.rs index 92b4a9e..ada687b 100644 --- a/bomboni_request/src/parse/mod.rs +++ b/bomboni_request/src/parse/mod.rs @@ -50,11 +50,13 @@ pub struct ParsedResource { #[cfg(feature = "testing")] #[cfg(test)] mod tests { + use super::*; + + use serde::{Deserialize, Serialize}; use std::collections::{BTreeMap, HashMap}; use std::fmt::Debug; use std::marker::PhantomData; - use crate::schema::FunctionSchemaMap; use crate::{ error::{CommonError, PathError, PathErrorStep, RequestError, RequestResult}, filter::Filter, @@ -65,16 +67,23 @@ mod tests { page_token::{plain::PlainPageTokenBuilder, FilterPageToken, PageTokenBuilder}, search::{SearchQuery, SearchQueryBuilder, SearchQueryConfig}, }, - testing::{bomboni, schema::UserItem}, + schema::FunctionSchemaMap, + testing::schema::UserItem, }; use bomboni_common::{btree_map, btree_map_into, hash_map_into}; use bomboni_proto::google::protobuf::{ FloatValue, Int32Value, Int64Value, StringValue, Timestamp, UInt32Value, UInt64Value, }; use bomboni_request_derive::{derived_map, parse_resource_name, Parse}; - use serde::{Deserialize, Serialize}; - use super::*; + mod bomboni { + pub mod proto { + pub use bomboni_proto::*; + } + pub mod request { + pub use crate::*; + } + } #[derive(Debug, PartialEq, Eq, Clone, Copy, Default)] #[repr(i32)] @@ -119,7 +128,7 @@ mod tests { } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { #[parse(source = "string")] s: String, @@ -189,7 +198,7 @@ mod tests { struct NestedItem {} #[derive(Parse, Debug, Default, PartialEq)] - #[parse(bomboni_crate = bomboni, source = NestedItem, write)] + #[parse(source = NestedItem, write)] struct ParsedNestedItem {} #[derive(Debug, PartialEq)] @@ -202,7 +211,7 @@ mod tests { #[derive(Parse, Debug, PartialEq)] #[allow(dead_code)] - #[parse(bomboni_crate = bomboni, source = OneofKind, write)] + #[parse(source = OneofKind, write)] enum ParsedOneofKind { String(String), Boolean(bool), @@ -418,7 +427,7 @@ mod tests { } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { value: i32, #[parse(try_from = i32, extract = [Unwrap])] @@ -446,14 +455,14 @@ mod tests { } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = NestedItem, write)] + #[parse(source = NestedItem, write)] struct ParsedNested { name: String, description: Option, } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Oneof, tagged_union { oneof = OneofKind, field = kind }, write)] + #[parse(source = Oneof, tagged_union { oneof = OneofKind, field = kind }, write)] enum ParsedOneof { Value(i32), } @@ -665,7 +674,7 @@ mod tests { } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { required: String, #[parse(extract = [StringFilterEmpty])] @@ -736,7 +745,7 @@ mod tests { } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { #[parse(enumeration)] required: DataTypeEnum, @@ -802,7 +811,7 @@ mod tests { } #[derive(Parse, Debug, PartialEq, Default)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { #[parse(derive { parse = pos_parse, write = pos_write })] pos: String, @@ -850,7 +859,7 @@ mod tests { } #[derive(Debug, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Oneof, tagged_union { oneof = OneofKind, field = kind }, write)] + #[parse(source = Oneof, tagged_union { oneof = OneofKind, field = kind }, write)] enum ParsedOneof { #[parse(derive { parse = derived_oneof_parse, write = derived_oneof_write })] Derived(i32), @@ -1095,7 +1104,7 @@ mod tests { } #[derive(Debug, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { values: Vec, #[parse(regex = "^[a-z]$")] @@ -1110,7 +1119,7 @@ mod tests { } #[derive(Debug, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = NestedItem, write)] + #[parse(source = NestedItem, write)] struct ParsedNestedItem { value: i32, } @@ -1278,7 +1287,7 @@ mod tests { } #[derive(Debug, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { #[parse(wrapper)] value_f32: Option, @@ -1313,7 +1322,7 @@ mod tests { } #[derive(Debug, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Value, tagged_union { oneof = ValueKind, field = kind }, write)] + #[parse(source = Value, tagged_union { oneof = ValueKind, field = kind }, write)] enum ParsedValue { #[parse(wrapper)] I32(i32), @@ -1381,7 +1390,7 @@ mod tests { } #[derive(Debug, Clone, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] enum ParsedItem { String(String), Data(ParsedData), @@ -1394,7 +1403,7 @@ mod tests { } #[derive(Debug, Clone, Default, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Data, write)] + #[parse(source = Data, write)] struct ParsedData { value: i32, } @@ -1424,7 +1433,7 @@ mod tests { } #[derive(Debug, Clone, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Container, write)] + #[parse(source = Container, write)] struct ParsedContainer { #[parse(oneof)] item: ParsedItem, @@ -1548,7 +1557,7 @@ mod tests { } #[derive(Debug, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Value, tagged_union { oneof = ValueKind, field = kind }, write)] + #[parse(source = Value, tagged_union { oneof = ValueKind, field = kind }, write)] enum ParsedValue { Number(i32), #[parse(extract = [Unbox])] @@ -1560,7 +1569,7 @@ mod tests { } #[derive(Debug, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = NestedValue, write)] + #[parse(source = NestedValue, write)] struct ParsedNestedValue { value: i32, } @@ -1671,7 +1680,7 @@ mod tests { } #[derive(Debug, Clone, PartialEq, Default, Parse)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { #[parse(keep, source = "value")] x: i32, @@ -1682,7 +1691,7 @@ mod tests { } #[derive(Debug, Clone, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Oneof, write)] + #[parse(source = Oneof, write)] enum ParsedOneof { #[parse(keep)] Item(NestedItem), @@ -1742,7 +1751,7 @@ mod tests { } #[derive(Debug, Clone, PartialEq, Default, Parse)] - #[parse(bomboni_crate = bomboni, source = Item::, write)] + #[parse(source = Item::, write)] struct ParsedItem where T: Default + Debug + Clone + Into, @@ -1756,7 +1765,7 @@ mod tests { } #[derive(Debug, Clone, PartialEq, Default, Parse)] - #[parse(bomboni_crate = bomboni, source = Item::, write)] + #[parse(source = Item::, write)] struct ParsedItemI32 where T: Default + Debug + Clone + RequestParse + Into, @@ -1806,28 +1815,28 @@ mod tests { } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedListQuery { #[parse(list_query)] list_query: ListQuery, } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedNoFilter { #[parse(list_query { filter = false })] query: ListQuery, } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedCustomToken { #[parse(list_query)] query: ListQuery, } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedSearchQuery { #[parse(search_query)] search_query: SearchQuery, @@ -2107,14 +2116,14 @@ mod tests { } #[derive(Debug, Clone, PartialEq, Default, Parse)] - #[parse(bomboni_crate = bomboni, source = Request, request, write)] + #[parse(source = Request, request, write)] struct ParsedRequest { #[parse(source = "value?")] value: i32, } #[derive(Debug, Clone, PartialEq, Default, Parse)] - #[parse(bomboni_crate = bomboni, source = Request, request { name = "Test" }, write)] + #[parse(source = Request, request { name = "Test" }, write)] struct ParsedCustomNameRequest { #[parse(source = "value?")] value: i32, @@ -2158,7 +2167,7 @@ mod tests { } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { #[parse(resource { fields { @@ -2173,7 +2182,7 @@ mod tests { } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItemDefaultResource { #[parse(resource)] resource: ParsedResource, @@ -2244,7 +2253,7 @@ mod tests { } #[derive(Debug, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Item, write)] + #[parse(source = Item, write)] struct ParsedItem { #[parse(try_from = i32)] value: u64, @@ -2307,7 +2316,7 @@ mod tests { } #[derive(Debug, Clone, PartialEq, Parse)] - #[parse(bomboni_crate = bomboni, source = Item, write, serde_as)] + #[parse(source = Item, write, serde_as)] struct ParsedItem { value: i32, } @@ -2396,7 +2405,7 @@ mod tests { } #[derive(Parse, Debug, PartialEq)] - #[parse(bomboni_crate = bomboni, source = Item)] + #[parse(source = Item)] struct ParsedItem { #[parse(source = "values", derive = values_parse_hash)] values: HashMap, diff --git a/bomboni_request/src/testing/mod.rs b/bomboni_request/src/testing/mod.rs index 029656d..1ce7e17 100644 --- a/bomboni_request/src/testing/mod.rs +++ b/bomboni_request/src/testing/mod.rs @@ -1,11 +1 @@ pub mod schema; - -pub mod bomboni { - pub mod proto { - pub use bomboni_proto::*; - } - - pub mod request { - pub use crate::*; - } -} diff --git a/bomboni_request_derive/Cargo.toml b/bomboni_request_derive/Cargo.toml index 9216f70..701536a 100644 --- a/bomboni_request_derive/Cargo.toml +++ b/bomboni_request_derive/Cargo.toml @@ -14,10 +14,13 @@ name = "bomboni_request_derive" path = "src/lib.rs" proc-macro = true +[features] +root-crate = [] + [dependencies] -bomboni_core = { path = "../bomboni_core", version = "0.1.60" } +bomboni_core = { workspace = true } -proc-macro2 = { version = "1.0.86", features = ["proc-macro"] } -syn = "2.0.72" -quote = "1.0.36" -darling = "0.20.10" +proc-macro2 = { workspace = true, features = ["proc-macro"] } +syn.workspace = true +quote.workspace = true +darling.workspace = true diff --git a/bomboni_request_derive/src/parse/mod.rs b/bomboni_request_derive/src/parse/mod.rs index 0538e4f..a03f7b7 100644 --- a/bomboni_request_derive/src/parse/mod.rs +++ b/bomboni_request_derive/src/parse/mod.rs @@ -39,46 +39,48 @@ pub fn expand(input: DeriveInput) -> syn::Result { fn expand_usage(options: &ParseOptions) -> TokenStream { let mut result = quote!(); - result.extend(if let Some(path) = options.bomboni_crate.as_ref() { + result.extend(if let Some(path) = options.serde_crate.as_ref() { quote! { - use #path as _bomboni; + use #path as _serde; } } else { quote! { #[allow(unused_extern_crates, clippy::useless_attribute)] - extern crate bomboni as _bomboni; + extern crate serde as _serde; } }); + let (mut use_proto, mut use_request) = if let Some(path) = options.bomboni_crate.as_ref() { + (quote!(#path::proto), quote!(#path::request)) + } else if cfg!(feature = "root-crate") { + (quote!(bomboni::proto), quote!(bomboni::request)) + } else { + (quote!(bomboni_proto), quote!(bomboni_request)) + }; + + if let Some(path) = options.bomboni_proto_crate.as_ref() { + use_proto = quote!(#path); + } + if let Some(path) = options.bomboni_request_crate.as_ref() { + use_request = quote!(#path); + } + result.extend(quote! { - use _bomboni::{ - proto::google::protobuf::{ - BoolValue, DoubleValue, FloatValue, Int32Value, Int64Value, StringValue, Timestamp, - UInt32Value, UInt64Value, - }, - request::{ - error::{CommonError, PathError, PathErrorStep, RequestError, RequestResult}, - filter::Filter, - ordering::{Ordering, OrderingDirection, OrderingTerm}, - query::{ - list::{ListQuery, ListQueryBuilder, ListQueryConfig}, - page_token::{plain::PlainPageTokenBuilder, FilterPageToken, PageTokenBuilder}, - search::{SearchQuery, SearchQueryBuilder, SearchQueryConfig}, - }, + use #use_proto::google::protobuf::{ + BoolValue, DoubleValue, FloatValue, Int32Value, Int64Value, StringValue, Timestamp, + UInt32Value, UInt64Value, + }; + use #use_request::{ + error::{CommonError, PathError, PathErrorStep, RequestError, RequestResult}, + filter::Filter, + ordering::{Ordering, OrderingDirection, OrderingTerm}, + query::{ + list::{ListQuery, ListQueryBuilder, ListQueryConfig}, + page_token::{plain::PlainPageTokenBuilder, FilterPageToken, PageTokenBuilder}, + search::{SearchQuery, SearchQueryBuilder, SearchQueryConfig}, }, }; }); - result.extend(if let Some(path) = options.serde_crate.as_ref() { - quote! { - use #path as _serde; - } - } else { - quote! { - #[allow(unused_extern_crates, clippy::useless_attribute)] - extern crate serde as _serde; - } - }); - result } diff --git a/bomboni_request_derive/src/parse/options.rs b/bomboni_request_derive/src/parse/options.rs index 36194aa..7de5ad8 100644 --- a/bomboni_request_derive/src/parse/options.rs +++ b/bomboni_request_derive/src/parse/options.rs @@ -42,10 +42,16 @@ pub struct ParseOptions { #[darling(default)] pub request: Option, - /// Custom comboni crate path. + /// Custom `bomboni` crate path. #[darling(default)] pub bomboni_crate: Option, - /// Custom serde crate path. + /// Custom `bomboni_proto` crate path. + #[darling(default)] + pub bomboni_proto_crate: Option, + /// Custom `bomboni_request` crate path. + #[darling(default)] + pub bomboni_request_crate: Option, + /// Custom `serde` crate path. #[darling(default)] pub serde_crate: Option, } diff --git a/bomboni_template/Cargo.toml b/bomboni_template/Cargo.toml index a14165f..9dac8d7 100644 --- a/bomboni_template/Cargo.toml +++ b/bomboni_template/Cargo.toml @@ -18,11 +18,11 @@ default = ["testing"] testing = [] [dependencies] -bomboni_common = { path = "../bomboni_common", version = "0.1.60" } -bomboni_proto = { version = "0.1.60", path = "../bomboni_proto" } +bomboni_common = { workspace = true } +bomboni_proto = { workspace = true } -thiserror = "1.0.63" -handlebars = "6.0.0" -serde = { version = "1.0.204", features = ["derive"] } -serde_json = "1.0.120" -convert_case = "0.6.0" +thiserror.workspace = true +handlebars.workspace = true +serde = { workspace = true, features = ["derive"] } +serde_json.workspace = true +convert_case.workspace = true diff --git a/bomboni_wasm/Cargo.toml b/bomboni_wasm/Cargo.toml index fa22fa1..1f7abf3 100644 --- a/bomboni_wasm/Cargo.toml +++ b/bomboni_wasm/Cargo.toml @@ -14,18 +14,19 @@ name = "bomboni_wasm" path = "src/lib.rs" [features] +root-crate = ["bomboni_wasm_derive/root-crate"] derive = ["dep:bomboni_wasm_derive"] js = ["bomboni_wasm_core/js"] [dependencies] -bomboni_wasm_core = { path = "../bomboni_wasm_core", version = "0.1.60" } -bomboni_wasm_derive = { path = "../bomboni_wasm_derive", version = "0.1.60", optional = true } +bomboni_wasm_core = { workspace = true } +bomboni_wasm_derive = { workspace = true, optional = true } -serde = "1.0.204" -wasm-bindgen = "0.2.92" -js-sys = "0.3.69" +serde.workspace = true +wasm-bindgen = "0.2.93" +js-sys = "0.3.70" serde-wasm-bindgen = "0.6.5" [dev-dependencies] -serde = { version = "1.0.204", features = ["derive"] } -serde_json = "1.0.120" +serde = { workspace = true, features = ["derive"] } +serde_json.workspace = true diff --git a/bomboni_wasm/src/lib.rs b/bomboni_wasm/src/lib.rs index 523c16f..b293f6a 100644 --- a/bomboni_wasm/src/lib.rs +++ b/bomboni_wasm/src/lib.rs @@ -31,18 +31,18 @@ pub use bomboni_wasm_derive::*; #[cfg(test)] mod tests { use super::*; + use serde::{Deserialize, Serialize}; - pub mod bomboni { + mod bomboni { pub mod wasm { - pub use crate::Wasm; + pub use crate::*; } } #[test] fn structs() { #[derive(Serialize, Deserialize, Wasm)] - #[wasm(bomboni_crate = bomboni)] pub struct Simple { a: String, b: i32, @@ -59,7 +59,7 @@ mod tests { #[test] fn renames() { #[derive(Serialize, Deserialize, Wasm)] - #[wasm(bomboni_crate = bomboni, rename_all = "camelCase")] + #[wasm(rename_all = "camelCase")] struct Item { test_name: String, #[wasm(rename = "x")] @@ -75,14 +75,12 @@ mod tests { #[test] fn enums() { #[derive(Serialize, Deserialize, Wasm)] - #[wasm(bomboni_crate = bomboni)] pub enum ExternalTag { String(String), Number(f64), } #[derive(Serialize, Deserialize, Wasm)] - #[wasm(bomboni_crate = bomboni)] #[serde(tag = "kind", content = "data")] pub enum AdjacentTag { String(String), @@ -90,7 +88,6 @@ mod tests { } #[derive(Serialize, Deserialize, Wasm)] - #[wasm(bomboni_crate = bomboni)] #[serde(tag = "kind")] pub enum InternalTag { String { value: String }, diff --git a/bomboni_wasm_core/Cargo.toml b/bomboni_wasm_core/Cargo.toml index df91801..7e89af7 100644 --- a/bomboni_wasm_core/Cargo.toml +++ b/bomboni_wasm_core/Cargo.toml @@ -17,11 +17,11 @@ path = "src/lib.rs" js = [] [dependencies] -bomboni_core = { path = "../bomboni_core", version = "0.1.60" } +bomboni_core = { workspace = true } -proc-macro2 = { version = "1.0.86", features = ["proc-macro"] } -syn = "2.0.72" -quote = "1.0.36" -darling = "0.20.10" -serde_derive_internals = "0.29.1" -convert_case = "0.6.0" +proc-macro2 = { workspace = true, features = ["proc-macro"] } +syn.workspace = true +quote.workspace = true +darling.workspace = true +serde_derive_internals.workspace = true +convert_case.workspace = true diff --git a/bomboni_wasm_core/src/options.rs b/bomboni_wasm_core/src/options.rs index dcab5b7..2329702 100644 --- a/bomboni_wasm_core/src/options.rs +++ b/bomboni_wasm_core/src/options.rs @@ -16,6 +16,7 @@ pub struct WasmOptions<'a> { pub wasm_bindgen_crate: Option, pub js_sys_crate: Option, pub bomboni_crate: Option, + pub bomboni_wasm_crate: Option, pub into_wasm_abi: bool, pub from_wasm_abi: bool, pub enum_value: bool, @@ -76,6 +77,7 @@ struct Attributes { wasm_bindgen_crate: Option, js_sys_crate: Option, bomboni_crate: Option, + bomboni_wasm_crate: Option, wasm_abi: Option, into_wasm_abi: Option, from_wasm_abi: Option, @@ -202,6 +204,7 @@ impl<'a> WasmOptions<'a> { wasm_bindgen_crate: attributes.wasm_bindgen_crate, js_sys_crate: attributes.js_sys_crate, bomboni_crate: attributes.bomboni_crate, + bomboni_wasm_crate: attributes.bomboni_wasm_crate, into_wasm_abi: attributes.into_wasm_abi.unwrap_or(wasm_abi), from_wasm_abi: attributes.from_wasm_abi.unwrap_or(wasm_abi), enum_value: attributes.enum_value.unwrap_or_default(), diff --git a/bomboni_wasm_derive/Cargo.toml b/bomboni_wasm_derive/Cargo.toml index 98e1c7f..07a2004 100644 --- a/bomboni_wasm_derive/Cargo.toml +++ b/bomboni_wasm_derive/Cargo.toml @@ -14,12 +14,15 @@ name = "bomboni_wasm_derive" path = "src/lib.rs" proc-macro = true +[features] +root-crate = [] + [dependencies] -bomboni_core = { path = "../bomboni_core", version = "0.1.60" } -bomboni_wasm_core = { path = "../bomboni_wasm_core", version = "0.1.60" } +bomboni_core = { workspace = true } +bomboni_wasm_core = { workspace = true } -proc-macro2 = { version = "1.0.86", features = ["proc-macro"] } -syn = "2.0.72" -quote = "1.0.36" -darling = "0.20.10" -serde_derive_internals = "0.29.1" +proc-macro2 = { workspace = true, features = ["proc-macro"] } +syn.workspace = true +quote.workspace = true +darling.workspace = true +serde_derive_internals.workspace = true diff --git a/bomboni_wasm_derive/src/wasm.rs b/bomboni_wasm_derive/src/wasm.rs index 2253109..f297dd9 100644 --- a/bomboni_wasm_derive/src/wasm.rs +++ b/bomboni_wasm_derive/src/wasm.rs @@ -701,16 +701,17 @@ fn expand_usage(options: &WasmOptions) -> TokenStream { }, ); - result.extend(if let Some(path) = options.bomboni_crate.as_ref() { - quote! { - use #path as _bomboni; - } + let mut use_wasm = if let Some(path) = options.bomboni_crate.as_ref() { + quote!(#path::wasm) + } else if cfg!(feature = "root-crate") { + quote!(bomboni::wasm) } else { - quote! { - #[allow(unused_extern_crates, clippy::useless_attribute)] - extern crate bomboni as _bomboni; - } - }); + quote!(bomboni_wasm) + }; + + if let Some(path) = options.bomboni_wasm_crate.as_ref() { + use_wasm = quote!(#path); + } quote! { #result @@ -724,7 +725,7 @@ fn expand_usage(options: &WasmOptions) -> TokenStream { JsObject, JsValue, }; use _js_sys::JsString; - use _bomboni::wasm::Wasm; + use #use_wasm::Wasm; } }