diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock index 5d49dc217e..d4fc37209e 100644 --- a/frontend/rust-lib/Cargo.lock +++ b/frontend/rust-lib/Cargo.lock @@ -570,10 +570,10 @@ dependencies = [ "crossbeam-utils", "dart-notify", "ffi-support", + "flowy-codegen", "flowy-derive", "flowy-sdk", "lib-dispatch", - "lib-infra", "log", "once_cell", "protobuf", @@ -588,10 +588,10 @@ version = "0.1.0" dependencies = [ "allo-isolate", "bytes", + "flowy-codegen", "flowy-derive", "lazy_static", "lib-dispatch", - "lib-infra", "log", "protobuf", ] @@ -816,6 +816,29 @@ dependencies = [ "syn", ] +[[package]] +name = "flowy-codegen" +version = "0.1.0" +dependencies = [ + "cmd_lib", + "console", + "fancy-regex", + "flowy-ast", + "itertools", + "lazy_static", + "log", + "phf 0.8.0", + "protoc-bin-vendored", + "protoc-rust", + "serde", + "serde_json", + "similar", + "syn", + "tera", + "toml", + "walkdir", +] + [[package]] name = "flowy-database" version = "0.1.0" @@ -834,8 +857,8 @@ version = "0.1.0" dependencies = [ "dashmap", "flowy-ast", + "flowy-codegen", "lazy_static", - "lib-infra", "proc-macro2", "quote", "serde_json", @@ -857,6 +880,7 @@ dependencies = [ "derive_more", "diesel", "diesel_derives", + "flowy-codegen", "flowy-database", "flowy-derive", "flowy-document", @@ -891,13 +915,13 @@ name = "flowy-error" version = "0.1.0" dependencies = [ "bytes", + "flowy-codegen", "flowy-database", "flowy-derive", "flowy-error-code", "flowy-sync", "http-flowy", "lib-dispatch", - "lib-infra", "lib-ot", "lib-sqlite", "protobuf", @@ -910,8 +934,8 @@ name = "flowy-error-code" version = "0.1.0" dependencies = [ "derive_more", + "flowy-codegen", "flowy-derive", - "lib-infra", "protobuf", ] @@ -923,6 +947,7 @@ dependencies = [ "dart-notify", "diesel", "diesel_derives", + "flowy-codegen", "flowy-database", "flowy-derive", "flowy-document", @@ -965,6 +990,7 @@ dependencies = [ "dashmap", "diesel", "fancy-regex", + "flowy-codegen", "flowy-database", "flowy-derive", "flowy-error", @@ -1002,6 +1028,7 @@ name = "flowy-http-model" version = "0.1.0" dependencies = [ "bytes", + "flowy-codegen", "flowy-derive", "lib-infra", "md5", @@ -1017,6 +1044,7 @@ dependencies = [ "bytes", "config", "dashmap", + "flowy-codegen", "flowy-derive", "flowy-document", "flowy-error", @@ -1178,6 +1206,7 @@ dependencies = [ "diesel_derives", "fake", "fancy-regex", + "flowy-codegen", "flowy-database", "flowy-derive", "flowy-error", @@ -1740,27 +1769,10 @@ version = "0.1.0" dependencies = [ "bytes", "chrono", - "cmd_lib", - "console", - "fancy-regex", - "flowy-ast", "futures-core", - "itertools", - "lazy_static", - "log", - "phf 0.8.0", "pin-project", - "protoc-bin-vendored", - "protoc-rust", "rand 0.8.5", - "serde", - "serde_json", - "similar", - "syn", - "tera", "tokio", - "toml", - "walkdir", ] [[package]] @@ -1827,6 +1839,7 @@ version = "0.1.0" dependencies = [ "bytes", "dashmap", + "flowy-codegen", "flowy-derive", "futures", "futures-channel", diff --git a/frontend/rust-lib/dart-ffi/Cargo.toml b/frontend/rust-lib/dart-ffi/Cargo.toml index 71df69e4cb..708ddb00a5 100644 --- a/frontend/rust-lib/dart-ffi/Cargo.toml +++ b/frontend/rust-lib/dart-ffi/Cargo.toml @@ -37,6 +37,7 @@ http_sync = ["flowy-sdk/http_sync", "flowy-sdk/use_bunyan"] openssl_vendored = ["flowy-sdk/openssl_vendored"] [build-dependencies] -lib-infra = { path = "../../../shared-lib/lib-infra", features = [ +flowy-codegen= { path = "../../../shared-lib/flowy-codegen", features = [ "dart", -] } +]} + diff --git a/frontend/rust-lib/dart-ffi/build.rs b/frontend/rust-lib/dart-ffi/build.rs index e897c3690d..90fa29ba4c 100644 --- a/frontend/rust-lib/dart-ffi/build.rs +++ b/frontend/rust-lib/dart-ffi/build.rs @@ -1,5 +1,3 @@ -use lib_infra::code_gen; - fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); + flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/frontend/rust-lib/dart-notify/Cargo.toml b/frontend/rust-lib/dart-notify/Cargo.toml index 64469a3f24..c6f79a249d 100644 --- a/frontend/rust-lib/dart-notify/Cargo.toml +++ b/frontend/rust-lib/dart-notify/Cargo.toml @@ -16,7 +16,7 @@ flowy-derive = {path = "../../../shared-lib/flowy-derive" } lib-dispatch = {path = "../lib-dispatch" } [features] -dart = ["lib-infra/dart"] +dart = ["flowy-codegen/dart"] [build-dependencies] -lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] } \ No newline at end of file +flowy-codegen= { path = "../../../shared-lib/flowy-codegen"} diff --git a/frontend/rust-lib/dart-notify/build.rs b/frontend/rust-lib/dart-notify/build.rs index e897c3690d..90fa29ba4c 100644 --- a/frontend/rust-lib/dart-notify/build.rs +++ b/frontend/rust-lib/dart-notify/build.rs @@ -1,5 +1,3 @@ -use lib_infra::code_gen; - fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); + flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/frontend/rust-lib/flowy-document/Cargo.toml b/frontend/rust-lib/flowy-document/Cargo.toml index 4fc1b899ce..ad7602f776 100644 --- a/frontend/rust-lib/flowy-document/Cargo.toml +++ b/frontend/rust-lib/flowy-document/Cargo.toml @@ -52,10 +52,11 @@ criterion = "0.3" rand = "0.8.5" [build-dependencies] -lib-infra = { path = "../../../shared-lib/lib-infra", features = [ "proto_gen"] } +flowy-codegen= { path = "../../../shared-lib/flowy-codegen"} + [features] sync = [] cloud_sync = ["sync"] flowy_unit_test = ["lib-ot/flowy_unit_test", "flowy-revision/flowy_unit_test"] -dart = ["lib-infra/dart"] \ No newline at end of file +dart = ["flowy-codegen/dart"] \ No newline at end of file diff --git a/frontend/rust-lib/flowy-document/build.rs b/frontend/rust-lib/flowy-document/build.rs index b5514a7944..7ea4c907a8 100644 --- a/frontend/rust-lib/flowy-document/build.rs +++ b/frontend/rust-lib/flowy-document/build.rs @@ -1,9 +1,7 @@ -use lib_infra::code_gen; - fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name); + flowy_codegen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] - code_gen::dart_event::gen(crate_name); + flowy_codegen::dart_event::gen(crate_name); } diff --git a/frontend/rust-lib/flowy-error/Cargo.toml b/frontend/rust-lib/flowy-error/Cargo.toml index 09e3e4eb70..b0986a2a78 100644 --- a/frontend/rust-lib/flowy-error/Cargo.toml +++ b/frontend/rust-lib/flowy-error/Cargo.toml @@ -27,7 +27,7 @@ ot = ["lib-ot"] serde = ["serde_json"] http_server = ["http-flowy"] db = ["flowy-database", "lib-sqlite", "r2d2"] -dart = ["flowy-error-code/dart", "lib-infra/dart"] +dart = ["flowy-error-code/dart", "flowy-codegen/dart"] [build-dependencies] -lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] } \ No newline at end of file +flowy-codegen= { path = "../../../shared-lib/flowy-codegen"} diff --git a/frontend/rust-lib/flowy-error/build.rs b/frontend/rust-lib/flowy-error/build.rs index c674f76a4f..009e328849 100644 --- a/frontend/rust-lib/flowy-error/build.rs +++ b/frontend/rust-lib/flowy-error/build.rs @@ -1,5 +1,3 @@ -use lib_infra::code_gen; - fn main() { - code_gen::protobuf_file::gen("flowy-error"); + flowy_codegen::protobuf_file::gen("flowy-error"); } diff --git a/frontend/rust-lib/flowy-folder/Cargo.toml b/frontend/rust-lib/flowy-folder/Cargo.toml index adde645085..3c9a02f09a 100644 --- a/frontend/rust-lib/flowy-folder/Cargo.toml +++ b/frontend/rust-lib/flowy-folder/Cargo.toml @@ -42,11 +42,12 @@ flowy-folder = { path = "../flowy-folder", features = ["flowy_unit_test"]} flowy-test = { path = "../flowy-test" } [build-dependencies] -lib-infra = { path = "../../../shared-lib/lib-infra", features = [ "proto_gen"] } +flowy-codegen= { path = "../../../shared-lib/flowy-codegen"} + [features] default = [] sync = [] cloud_sync = ["sync"] flowy_unit_test = ["lib-ot/flowy_unit_test", "flowy-revision/flowy_unit_test"] -dart = ["lib-infra/dart"] \ No newline at end of file +dart = ["flowy-codegen/dart"] \ No newline at end of file diff --git a/frontend/rust-lib/flowy-folder/build.rs b/frontend/rust-lib/flowy-folder/build.rs index b5514a7944..7ea4c907a8 100644 --- a/frontend/rust-lib/flowy-folder/build.rs +++ b/frontend/rust-lib/flowy-folder/build.rs @@ -1,9 +1,7 @@ -use lib_infra::code_gen; - fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name); + flowy_codegen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] - code_gen::dart_event::gen(crate_name); + flowy_codegen::dart_event::gen(crate_name); } diff --git a/frontend/rust-lib/flowy-grid/Cargo.toml b/frontend/rust-lib/flowy-grid/Cargo.toml index f4325b8bcc..f67c88384b 100644 --- a/frontend/rust-lib/flowy-grid/Cargo.toml +++ b/frontend/rust-lib/flowy-grid/Cargo.toml @@ -51,10 +51,11 @@ flowy-test = { path = "../flowy-test" } flowy-grid = { path = "../flowy-grid", features = ["flowy_unit_test"]} [build-dependencies] -lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] } +flowy-codegen= { path = "../../../shared-lib/flowy-codegen"} + [features] default = [] -dart = ["lib-infra/dart"] +dart = ["flowy-codegen/dart"] flowy_unit_test = ["flowy-revision/flowy_unit_test"] \ No newline at end of file diff --git a/frontend/rust-lib/flowy-grid/build.rs b/frontend/rust-lib/flowy-grid/build.rs index b5514a7944..7ea4c907a8 100644 --- a/frontend/rust-lib/flowy-grid/build.rs +++ b/frontend/rust-lib/flowy-grid/build.rs @@ -1,9 +1,7 @@ -use lib_infra::code_gen; - fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name); + flowy_codegen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] - code_gen::dart_event::gen(crate_name); + flowy_codegen::dart_event::gen(crate_name); } diff --git a/frontend/rust-lib/flowy-net/Cargo.toml b/frontend/rust-lib/flowy-net/Cargo.toml index 459dfff32b..78e6aee028 100644 --- a/frontend/rust-lib/flowy-net/Cargo.toml +++ b/frontend/rust-lib/flowy-net/Cargo.toml @@ -42,10 +42,10 @@ nanoid = "0.4.0" [features] http_server = [] dart = [ - "lib-infra/dart", + "flowy-codegen/dart", "flowy-user/dart", "flowy-error/dart", ] [build-dependencies] -lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] } \ No newline at end of file +flowy-codegen = { path = "../../../shared-lib/flowy-codegen"} diff --git a/frontend/rust-lib/flowy-net/build.rs b/frontend/rust-lib/flowy-net/build.rs index b5514a7944..7ea4c907a8 100644 --- a/frontend/rust-lib/flowy-net/build.rs +++ b/frontend/rust-lib/flowy-net/build.rs @@ -1,9 +1,7 @@ -use lib_infra::code_gen; - fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name); + flowy_codegen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] - code_gen::dart_event::gen(crate_name); + flowy_codegen::dart_event::gen(crate_name); } diff --git a/frontend/rust-lib/flowy-user/Cargo.toml b/frontend/rust-lib/flowy-user/Cargo.toml index d2c0d55f32..5d18ec979b 100644 --- a/frontend/rust-lib/flowy-user/Cargo.toml +++ b/frontend/rust-lib/flowy-user/Cargo.toml @@ -45,7 +45,7 @@ rand_core = "0.6.3" rand = "0.8.5" [features] -dart = ["lib-infra/dart"] +dart = ["flowy-codegen/dart"] [build-dependencies] -lib-infra = { path = "../../../shared-lib/lib-infra", features = ["proto_gen"] } \ No newline at end of file +flowy-codegen= { path = "../../../shared-lib/flowy-codegen"} diff --git a/frontend/rust-lib/flowy-user/build.rs b/frontend/rust-lib/flowy-user/build.rs index b5514a7944..7ea4c907a8 100644 --- a/frontend/rust-lib/flowy-user/build.rs +++ b/frontend/rust-lib/flowy-user/build.rs @@ -1,9 +1,7 @@ -use lib_infra::code_gen; - fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name); + flowy_codegen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] - code_gen::dart_event::gen(crate_name); + flowy_codegen::dart_event::gen(crate_name); } diff --git a/frontend/scripts/makefile/tool.toml b/frontend/scripts/makefile/tool.toml index 08e5de3c49..870a4888f8 100644 --- a/frontend/scripts/makefile/tool.toml +++ b/frontend/scripts/makefile/tool.toml @@ -17,7 +17,7 @@ script_runner = "@shell" [tasks.rm_macro_build_cache] script = [ """ - path = canonicalize ../shared-lib/lib-infra/.cache + path = canonicalize ../shared-lib/flowy-codegen/.cache if is_path_exists ${path} rm -rf ${path} end diff --git a/shared-lib/Cargo.toml b/shared-lib/Cargo.toml index a401ffa0f4..4e65489a8f 100644 --- a/shared-lib/Cargo.toml +++ b/shared-lib/Cargo.toml @@ -8,6 +8,7 @@ members = [ "lib-infra", "flowy-derive", "flowy-ast", + "flowy-codegen", "flowy-error-code", "grid-rev-model", ] diff --git a/shared-lib/flowy-codegen/Cargo.toml b/shared-lib/flowy-codegen/Cargo.toml new file mode 100644 index 0000000000..382fa41471 --- /dev/null +++ b/shared-lib/flowy-codegen/Cargo.toml @@ -0,0 +1,49 @@ +[package] +name = "flowy-codegen" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +log = "0.4.14" +serde = { version = "1.0", features = ["derive"]} +serde_json = "1.0" +flowy-ast = { path = "../flowy-ast"} + +cmd_lib = { version = "1", optional = true } +protoc-rust = { version = "2", optional = true } +walkdir = { version = "2", optional = true } +similar = { version = "1.2.2", optional = true } +syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "full"], optional = true } +fancy-regex = { version = "0.10.0", optional = true } +lazy_static = { version = "1.4.0", optional = true } +tera = { version = "1.5.0", optional = true} +itertools = { version = "0.10", optional = true } +phf = { version = "0.8.0", features = ["macros"], optional = true } +console = {version = "0.14.0", optional = true} +protoc-bin-vendored = { version = "3.0", optional = true } +toml = {version = "0.5.8", optional = true} + + + + +[features] +proto_gen = [ + "similar", + "syn", + "fancy-regex", + "lazy_static", + "tera", + "itertools", + "phf", + "walkdir", + "console", + "toml", + "cmd_lib", + "protoc-rust", + "walkdir", + "protoc-bin-vendored", +] +dart_event = ["walkdir", "tera", "syn"] +dart = ["proto_gen", "dart_event"] \ No newline at end of file diff --git a/shared-lib/lib-infra/src/code_gen/dart_event/dart_event.rs b/shared-lib/flowy-codegen/src/dart_event/dart_event.rs similarity index 97% rename from shared-lib/lib-infra/src/code_gen/dart_event/dart_event.rs rename to shared-lib/flowy-codegen/src/dart_event/dart_event.rs index eea9c1160b..33fc75a195 100644 --- a/shared-lib/lib-infra/src/code_gen/dart_event/dart_event.rs +++ b/shared-lib/flowy-codegen/src/dart_event/dart_event.rs @@ -1,6 +1,6 @@ use super::event_template::*; -use crate::code_gen::flowy_toml::{parse_crate_config_from, CrateConfig}; -use crate::code_gen::util::{is_crate_dir, is_hidden, path_string_with_component, read_file}; +use crate::flowy_toml::{parse_crate_config_from, CrateConfig}; +use crate::util::{is_crate_dir, is_hidden, path_string_with_component, read_file}; use flowy_ast::{event_ast::*, *}; use std::fs::File; use std::io::Write; diff --git a/shared-lib/lib-infra/src/code_gen/dart_event/event_template.rs b/shared-lib/flowy-codegen/src/dart_event/event_template.rs similarity index 98% rename from shared-lib/lib-infra/src/code_gen/dart_event/event_template.rs rename to shared-lib/flowy-codegen/src/dart_event/event_template.rs index f9b08adea1..8da5c910cd 100644 --- a/shared-lib/lib-infra/src/code_gen/dart_event/event_template.rs +++ b/shared-lib/flowy-codegen/src/dart_event/event_template.rs @@ -1,4 +1,4 @@ -use crate::code_gen::util::get_tera; +use crate::util::get_tera; use tera::Context; pub struct EventTemplate { diff --git a/shared-lib/lib-infra/src/code_gen/dart_event/event_template.tera b/shared-lib/flowy-codegen/src/dart_event/event_template.tera similarity index 100% rename from shared-lib/lib-infra/src/code_gen/dart_event/event_template.tera rename to shared-lib/flowy-codegen/src/dart_event/event_template.tera diff --git a/shared-lib/lib-infra/src/code_gen/dart_event/mod.rs b/shared-lib/flowy-codegen/src/dart_event/mod.rs similarity index 100% rename from shared-lib/lib-infra/src/code_gen/dart_event/mod.rs rename to shared-lib/flowy-codegen/src/dart_event/mod.rs diff --git a/shared-lib/lib-infra/src/code_gen/flowy_toml.rs b/shared-lib/flowy-codegen/src/flowy_toml.rs similarity index 100% rename from shared-lib/lib-infra/src/code_gen/flowy_toml.rs rename to shared-lib/flowy-codegen/src/flowy_toml.rs diff --git a/shared-lib/lib-infra/src/code_gen/mod.rs b/shared-lib/flowy-codegen/src/lib.rs similarity index 100% rename from shared-lib/lib-infra/src/code_gen/mod.rs rename to shared-lib/flowy-codegen/src/lib.rs diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/ast.rs b/shared-lib/flowy-codegen/src/protobuf_file/ast.rs similarity index 96% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/ast.rs rename to shared-lib/flowy-codegen/src/protobuf_file/ast.rs index 995764a793..9b07e02291 100644 --- a/shared-lib/lib-infra/src/code_gen/protobuf_file/ast.rs +++ b/shared-lib/flowy-codegen/src/protobuf_file/ast.rs @@ -2,9 +2,9 @@ #![allow(dead_code)] #![allow(unused_imports)] #![allow(unused_results)] -use crate::code_gen::protobuf_file::template::{EnumTemplate, StructTemplate, RUST_TYPE_MAP}; -use crate::code_gen::protobuf_file::{parse_crate_info_from_path, ProtoFile, ProtobufCrateContext}; -use crate::code_gen::util::*; +use crate::protobuf_file::template::{EnumTemplate, StructTemplate, RUST_TYPE_MAP}; +use crate::protobuf_file::{parse_crate_info_from_path, ProtoFile, ProtobufCrateContext}; +use crate::util::*; use fancy_regex::Regex; use flowy_ast::*; use lazy_static::lazy_static; diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/mod.rs b/shared-lib/flowy-codegen/src/protobuf_file/mod.rs similarity index 99% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/mod.rs rename to shared-lib/flowy-codegen/src/protobuf_file/mod.rs index 1e2d89ba2d..3a151292dd 100644 --- a/shared-lib/lib-infra/src/code_gen/protobuf_file/mod.rs +++ b/shared-lib/flowy-codegen/src/protobuf_file/mod.rs @@ -6,7 +6,7 @@ mod proto_gen; mod proto_info; mod template; -use crate::code_gen::util::path_string_with_component; +use crate::util::path_string_with_component; use itertools::Itertools; use log::info; pub use proto_gen::*; diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_gen.rs b/shared-lib/flowy-codegen/src/protobuf_file/proto_gen.rs similarity index 95% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/proto_gen.rs rename to shared-lib/flowy-codegen/src/protobuf_file/proto_gen.rs index f38f9b40fc..2594d7d0ae 100644 --- a/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_gen.rs +++ b/shared-lib/flowy-codegen/src/protobuf_file/proto_gen.rs @@ -2,11 +2,11 @@ #![allow(dead_code)] #![allow(unused_imports)] #![allow(unused_results)] -use crate::code_gen::protobuf_file::ast::parse_protobuf_context_from; -use crate::code_gen::protobuf_file::proto_info::ProtobufCrateContext; -use crate::code_gen::protobuf_file::ProtoFile; -use crate::code_gen::util::*; -use crate::code_gen::ProtoCache; +use crate::protobuf_file::ast::parse_protobuf_context_from; +use crate::protobuf_file::proto_info::ProtobufCrateContext; +use crate::protobuf_file::ProtoFile; +use crate::util::*; +use crate::ProtoCache; use std::collections::HashMap; use std::fs::File; use std::path::Path; diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_info.rs b/shared-lib/flowy-codegen/src/protobuf_file/proto_info.rs similarity index 97% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/proto_info.rs rename to shared-lib/flowy-codegen/src/protobuf_file/proto_info.rs index d47210eaba..f071fe0461 100644 --- a/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_info.rs +++ b/shared-lib/flowy-codegen/src/protobuf_file/proto_info.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -use crate::code_gen::flowy_toml::{parse_crate_config_from, CrateConfig, FlowyConfig}; -use crate::code_gen::util::*; +use crate::flowy_toml::{parse_crate_config_from, CrateConfig, FlowyConfig}; +use crate::util::*; use std::fs::OpenOptions; use std::io::Write; use std::path::PathBuf; diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/derive_meta/derive_meta.rs b/shared-lib/flowy-codegen/src/protobuf_file/template/derive_meta/derive_meta.rs similarity index 95% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/template/derive_meta/derive_meta.rs rename to shared-lib/flowy-codegen/src/protobuf_file/template/derive_meta/derive_meta.rs index c38e301aa9..1babe1ced6 100644 --- a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/derive_meta/derive_meta.rs +++ b/shared-lib/flowy-codegen/src/protobuf_file/template/derive_meta/derive_meta.rs @@ -1,4 +1,4 @@ -use crate::code_gen::util::get_tera; +use crate::util::get_tera; use itertools::Itertools; use tera::Context; diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/derive_meta/derive_meta.tera b/shared-lib/flowy-codegen/src/protobuf_file/template/derive_meta/derive_meta.tera similarity index 100% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/template/derive_meta/derive_meta.tera rename to shared-lib/flowy-codegen/src/protobuf_file/template/derive_meta/derive_meta.tera diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/derive_meta/mod.rs b/shared-lib/flowy-codegen/src/protobuf_file/template/derive_meta/mod.rs similarity index 100% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/template/derive_meta/mod.rs rename to shared-lib/flowy-codegen/src/protobuf_file/template/derive_meta/mod.rs diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/mod.rs b/shared-lib/flowy-codegen/src/protobuf_file/template/mod.rs similarity index 100% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/template/mod.rs rename to shared-lib/flowy-codegen/src/protobuf_file/template/mod.rs diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/enum.tera b/shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/enum.tera similarity index 100% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/enum.tera rename to shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/enum.tera diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/enum_template.rs b/shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/enum_template.rs similarity index 91% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/enum_template.rs rename to shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/enum_template.rs index 28162bf0bb..9e390c1f5c 100644 --- a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/enum_template.rs +++ b/shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/enum_template.rs @@ -1,5 +1,5 @@ -use crate::code_gen::protobuf_file::ast::FlowyEnum; -use crate::code_gen::util::get_tera; +use crate::protobuf_file::ast::FlowyEnum; +use crate::util::get_tera; use tera::Context; pub struct EnumTemplate { diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/mod.rs b/shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/mod.rs similarity index 100% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/mod.rs rename to shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/mod.rs diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/struct.tera b/shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/struct.tera similarity index 100% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/struct.tera rename to shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/struct.tera diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/struct_template.rs b/shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/struct_template.rs similarity index 99% rename from shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/struct_template.rs rename to shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/struct_template.rs index c1844889a3..c84d1e8875 100644 --- a/shared-lib/lib-infra/src/code_gen/protobuf_file/template/proto_file/struct_template.rs +++ b/shared-lib/flowy-codegen/src/protobuf_file/template/proto_file/struct_template.rs @@ -1,4 +1,4 @@ -use crate::code_gen::util::get_tera; +use crate::util::get_tera; use flowy_ast::*; use phf::phf_map; use tera::Context; diff --git a/shared-lib/lib-infra/src/code_gen/util.rs b/shared-lib/flowy-codegen/src/util.rs similarity index 98% rename from shared-lib/lib-infra/src/code_gen/util.rs rename to shared-lib/flowy-codegen/src/util.rs index 51afcddd21..c3b57eab38 100644 --- a/shared-lib/lib-infra/src/code_gen/util.rs +++ b/shared-lib/flowy-codegen/src/util.rs @@ -142,7 +142,7 @@ pub fn suffix_relative_to_path(path: &str, base: &str) -> String { } pub fn get_tera(directory: &str) -> Tera { - let mut root = format!("{}/src/code_gen/", env!("CARGO_MANIFEST_DIR")); + let mut root = format!("{}/src/", env!("CARGO_MANIFEST_DIR")); root.push_str(directory); let root_absolute_path = match std::fs::canonicalize(&root) { diff --git a/shared-lib/flowy-derive/Cargo.toml b/shared-lib/flowy-derive/Cargo.toml index 5346ea52e9..935ee663f5 100644 --- a/shared-lib/flowy-derive/Cargo.toml +++ b/shared-lib/flowy-derive/Cargo.toml @@ -20,7 +20,7 @@ proc-macro2 = "1.0" flowy-ast = { path = "../flowy-ast" } lazy_static = {version = "1.4.0"} dashmap = "5" -lib-infra = { path = "../lib-infra", features = ["proto_gen"]} +flowy-codegen= { path = "../flowy-codegen"} serde_json = "1.0" walkdir = "2.3.1" diff --git a/shared-lib/flowy-derive/src/proto_buf/util.rs b/shared-lib/flowy-derive/src/proto_buf/util.rs index ef9391fa0d..c9af09c796 100644 --- a/shared-lib/flowy-derive/src/proto_buf/util.rs +++ b/shared-lib/flowy-derive/src/proto_buf/util.rs @@ -1,7 +1,7 @@ use dashmap::{DashMap, DashSet}; use flowy_ast::{Ctxt, TyInfo}; +use flowy_codegen::ProtoCache; use lazy_static::lazy_static; -use lib_infra::code_gen::ProtoCache; use std::fs::File; use std::io::Read; use std::sync::atomic::{AtomicBool, Ordering}; @@ -50,7 +50,7 @@ pub fn category_from_str(type_str: String) -> TypeCategory { IS_LOAD.store(true, Ordering::SeqCst); // Dependents on another crate file is not good, just leave it here. // Maybe find another way to read the .cache in the future. - let cache_dir = format!("{}/../lib-infra/.cache", env!("CARGO_MANIFEST_DIR")); + let cache_dir = format!("{}/../flowy-codegen/.cache", env!("CARGO_MANIFEST_DIR")); for path in WalkDir::new(cache_dir) .into_iter() .filter_map(|e| e.ok()) diff --git a/shared-lib/flowy-error-code/Cargo.toml b/shared-lib/flowy-error-code/Cargo.toml index ab72ad2711..fdee8d2d31 100644 --- a/shared-lib/flowy-error-code/Cargo.toml +++ b/shared-lib/flowy-error-code/Cargo.toml @@ -11,7 +11,8 @@ protobuf = {version = "2.18.0"} derive_more = {version = "0.99", features = ["display"]} [build-dependencies] -lib-infra = { path = "../lib-infra", features = ["proto_gen"] } +flowy-codegen= { path = "../flowy-codegen"} + [features] -dart = ["lib-infra/dart"] \ No newline at end of file +dart = ["flowy-codegen/dart"] \ No newline at end of file diff --git a/shared-lib/flowy-error-code/build.rs b/shared-lib/flowy-error-code/build.rs index e897c3690d..90fa29ba4c 100644 --- a/shared-lib/flowy-error-code/build.rs +++ b/shared-lib/flowy-error-code/build.rs @@ -1,5 +1,3 @@ -use lib_infra::code_gen; - fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); + flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/shared-lib/flowy-http-model/Cargo.toml b/shared-lib/flowy-http-model/Cargo.toml index 2b81acef41..bfc150a093 100644 --- a/shared-lib/flowy-http-model/Cargo.toml +++ b/shared-lib/flowy-http-model/Cargo.toml @@ -13,5 +13,6 @@ protobuf = {version = "2.18.0"} md5 = "0.7.0" [build-dependencies] -lib-infra = { path = "../lib-infra", features = ["proto_gen"] } +flowy-codegen= { path = "../flowy-codegen"} + diff --git a/shared-lib/flowy-http-model/build.rs b/shared-lib/flowy-http-model/build.rs index e897c3690d..90fa29ba4c 100644 --- a/shared-lib/flowy-http-model/build.rs +++ b/shared-lib/flowy-http-model/build.rs @@ -1,5 +1,3 @@ -use lib_infra::code_gen; - fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); + flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/shared-lib/lib-infra/Cargo.toml b/shared-lib/lib-infra/Cargo.toml index 4852f7932b..aa15b8e7dd 100644 --- a/shared-lib/lib-infra/Cargo.toml +++ b/shared-lib/lib-infra/Cargo.toml @@ -6,50 +6,10 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -log = "0.4.14" chrono = "0.4.19" bytes = { version = "1.0" } pin-project = "1.0" futures-core = { version = "0.3" } tokio = { version = "1.0", features = ["time", "rt"] } rand = "0.8.5" -serde = { version = "1.0", features = ["derive"]} -serde_json = "1.0" - -cmd_lib = { version = "1", optional = true } -protoc-rust = { version = "2", optional = true } -walkdir = { version = "2", optional = true } - -flowy-ast = { path = "../flowy-ast", optional = true} -similar = { version = "1.2.2", optional = true } -syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "full"], optional = true } -fancy-regex = { version = "0.10.0", optional = true } -lazy_static = { version = "1.4.0", optional = true } -tera = { version = "1.5.0", optional = true} -itertools = { version = "0.10", optional = true } -phf = { version = "0.8.0", features = ["macros"], optional = true } -console = {version = "0.14.0", optional = true} -protoc-bin-vendored = { version = "3.0", optional = true } -toml = {version = "0.5.8", optional = true} - -[features] -proto_gen = [ - "flowy-ast", - "similar", - "syn", - "fancy-regex", - "lazy_static", - "tera", - "itertools", - "phf", - "walkdir", - "console", - "toml", - "cmd_lib", - "protoc-rust", - "walkdir", - "protoc-bin-vendored", -] -dart_event = ["walkdir", "flowy-ast", "tera", "syn"] -dart = ["proto_gen", "dart_event"] \ No newline at end of file diff --git a/shared-lib/lib-infra/src/lib.rs b/shared-lib/lib-infra/src/lib.rs index 9168f97f09..95496e8550 100644 --- a/shared-lib/lib-infra/src/lib.rs +++ b/shared-lib/lib-infra/src/lib.rs @@ -1,4 +1,3 @@ -pub mod code_gen; pub mod future; pub mod ref_map; pub mod retry; diff --git a/shared-lib/lib-ws/Cargo.toml b/shared-lib/lib-ws/Cargo.toml index 3e49545e6c..0261cab886 100644 --- a/shared-lib/lib-ws/Cargo.toml +++ b/shared-lib/lib-ws/Cargo.toml @@ -28,11 +28,11 @@ parking_lot = "0.12.1" dashmap = "5" [build-dependencies] -lib-infra = { path = "../lib-infra", features = ["proto_gen"] } +flowy-codegen= { path = "../flowy-codegen"} [dev-dependencies] tokio = {version = "1", features = ["full"]} env_logger = "0.8.2" [features] -dart = ["lib-infra/dart"] \ No newline at end of file +dart = ["flowy-codegen/dart"] \ No newline at end of file diff --git a/shared-lib/lib-ws/build.rs b/shared-lib/lib-ws/build.rs index e897c3690d..90fa29ba4c 100644 --- a/shared-lib/lib-ws/build.rs +++ b/shared-lib/lib-ws/build.rs @@ -1,5 +1,3 @@ -use lib_infra::code_gen; - fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); + flowy_codegen::protobuf_file::gen(env!("CARGO_PKG_NAME")); }