ソースを参照

chore: build tauri from vscode launch (#1720)

* chore: build tauri from vscode launch

* fix: unit test

Co-authored-by: nathan <[email protected]>
Nathan.fooo 2 年 前
コミット
d77c41013f

+ 2 - 2
frontend/.vscode/launch.json

@@ -94,7 +94,7 @@
         {
             "type": "lldb",
             "request": "launch",
-            "name": "AF: Tauri dev",
+            "name": "AF-tauri: Dev",
             "cargo": {
                 "args": [
                     "build",
@@ -102,7 +102,7 @@
                     "--no-default-features"
                 ]
             },
-            "preLaunchTask": "tauri:dev",
+            "preLaunchTask": "AF: Tauri Dev",
             "cwd": "${workspaceRoot}/appflowy_tauri/"
         },
         {

+ 12 - 4
frontend/.vscode/tasks.json

@@ -14,7 +14,7 @@
 			"type": "shell",
 			"dependsOrder": "sequence",
 			"dependsOn": [
-				"AF: Rust Clean",
+				"AF: Dart Clean",
 				"AF: Flutter Clean",
 				"AF: build_flowy_sdk",
 				"AF: Flutter Pub Get",
@@ -32,7 +32,7 @@
 			"type": "shell",
 			"dependsOrder": "sequence",
 			"dependsOn": [
-				"AF: Rust Clean",
+				"AF: Dart Clean",
 				"AF: Flutter Clean",
 				"AF: build_flowy_sdk_for_android",
 				"AF: Flutter Pub Get",
@@ -166,7 +166,7 @@
 			}
 		},
 		{
-			"label": "AF: Rust Clean",
+			"label": "AF: Dart Clean",
 			"type": "shell",
 			"command": "cargo make dart_clean",
 			"group": "build",
@@ -187,7 +187,7 @@
 			"detail": "app_flowy"
 		},
 		{
-			"label": "tauri:dev",
+			"label": "AF: Tauri Dev",
 			"type": "shell",
 			"isBackground": true,
 			"command": "npm run dev",
@@ -196,5 +196,13 @@
 				"cwd": "${workspaceFolder}/appflowy_tauri"
 			}
 		},
+		{
+			"label": "AF: Tauri Clean",
+			"type": "shell",
+			"command": "cargo make tauri_clean",
+			"options": {
+				"cwd": "${workspaceFolder}"
+			}
+		},
 	]
 }

+ 4 - 0
frontend/appflowy_tauri/src-tauri/build.rs

@@ -1,3 +1,7 @@
+use std::env;
 fn main() {
+    env::set_var("TAURI_PROTOBUF_PATH", "appflowy_tauri/src/protobuf");
+    env::set_var("CARGO_MAKE_WORKING_DIRECTORY", "../../../");
+
     tauri_build::build()
 }

+ 1 - 4
frontend/rust-lib/dart-ffi/Cargo.toml

@@ -38,7 +38,4 @@ http_sync = ["flowy-core/http_sync", "flowy-core/use_bunyan"]
 openssl_vendored = ["flowy-core/openssl_vendored"]
 
 [build-dependencies]
-flowy-codegen = { path = "../flowy-codegen", features = [
-    "dart",
-]}
-
+flowy-codegen = { path = "../flowy-codegen", features = ["dart"] }

+ 7 - 7
frontend/rust-lib/dart-notify/Cargo.toml

@@ -6,17 +6,17 @@ edition = "2018"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-lazy_static = {version = "1.4.0"}
-protobuf = {version = "2.20.0"}
-allo-isolate = {version = "^0.1", features = ["catch-unwind",]}
+lazy_static = { version = "1.4.0" }
+protobuf = { version = "2.20.0" }
+allo-isolate = { version = "^0.1", features = ["catch-unwind"] }
 log = "0.4.14"
 bytes = { version = "1.0" }
 
-flowy-derive = {path = "../flowy-derive" }
-lib-dispatch = {path = "../lib-dispatch" }
+flowy-derive = { path = "../flowy-derive" }
+lib-dispatch = { path = "../lib-dispatch" }
 
 [build-dependencies]
-flowy-codegen = { path = "../flowy-codegen", features = ["dart"]}
+flowy-codegen = { path = "../flowy-codegen" }
 
 [features]
-dart = []
+dart = ["flowy-codegen/dart"]

+ 3 - 4
frontend/rust-lib/flowy-codegen/Cargo.toml

@@ -16,7 +16,7 @@ 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 }
+syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "full"] }
 fancy-regex = { version = "0.10.0", optional = true }
 lazy_static = { version = "1.4.0", optional = true }
 tera = { version = "1.5.0", optional = true}
@@ -31,7 +31,6 @@ toml = {version = "0.5.8", optional = true}
 [features]
 proto_gen = [
     "similar",
-    "syn",
     "fancy-regex",
     "lazy_static",
     "tera",
@@ -45,7 +44,7 @@ proto_gen = [
     "walkdir",
     "protoc-bin-vendored",
 ]
-dart_event = ["walkdir", "tera", "syn"]
+dart_event = ["walkdir", "tera", ]
 dart = ["proto_gen", "dart_event"]
-ts_event = ["walkdir", "tera", "syn"]
+ts_event = ["walkdir", "tera", ]
 ts = ["proto_gen", "ts_event"]

+ 0 - 0
frontend/rust-lib/flowy-codegen/src/dart_event/ast.rs → frontend/rust-lib/flowy-codegen/src/ast.rs


+ 1 - 1
frontend/rust-lib/flowy-codegen/src/dart_event/dart_event.rs

@@ -1,5 +1,5 @@
 use super::event_template::*;
-use crate::dart_event::ast::EventASTContext;
+use crate::ast::EventASTContext;
 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::ASTResult;

+ 1 - 1
frontend/rust-lib/flowy-codegen/src/dart_event/mod.rs

@@ -1,5 +1,5 @@
 #![allow(clippy::module_inception)]
-pub(crate) mod ast;
+
 mod dart_event;
 mod event_template;
 

+ 1 - 0
frontend/rust-lib/flowy-codegen/src/lib.rs

@@ -10,6 +10,7 @@ pub mod ts_event;
 #[cfg(any(feature = "proto_gen", feature = "dart_event", feature = "ts_event"))]
 mod flowy_toml;
 
+pub(crate) mod ast;
 #[cfg(any(feature = "proto_gen", feature = "dart_event", feature = "ts_event"))]
 pub mod util;
 

+ 7 - 8
frontend/rust-lib/flowy-codegen/src/protobuf_file/mod.rs

@@ -100,14 +100,13 @@ fn generate_ts_protobuf_files(
     file_names: &Vec<String>,
     protoc_bin_path: &Path,
 ) {
-    if std::env::var("TAURI_PROTOBUF_PATH").is_err() {
-        eprintln!("TAURI_PROTOBUF_PATH was not set, skip generate ts pb");
-        return;
-    }
+    let root = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("../../".to_string());
+    let tauri_protobuf_path =
+        std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("appflowy_tauri/src/protobuf".to_string());
 
     let mut output = PathBuf::new();
-    output.push(std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap());
-    output.push(std::env::var("TAURI_PROTOBUF_PATH").unwrap());
+    output.push(root);
+    output.push(tauri_protobuf_path);
     output.push("classes");
     output.push(name);
 
@@ -159,12 +158,12 @@ fn generate_dart_protobuf_files(
     protoc_bin_path: &Path,
 ) {
     if std::env::var("CARGO_MAKE_WORKING_DIRECTORY").is_err() {
-        log::warn!("CARGO_MAKE_WORKING_DIRECTORY was not set, skip generate dart pb");
+        log::error!("CARGO_MAKE_WORKING_DIRECTORY was not set, skip generate dart pb");
         return;
     }
 
     if std::env::var("FLUTTER_FLOWY_SDK_PATH").is_err() {
-        log::warn!("FLUTTER_FLOWY_SDK_PATH was not set, skip generate dart pb");
+        log::error!("FLUTTER_FLOWY_SDK_PATH was not set, skip generate dart pb");
         return;
     }
 

+ 5 - 14
frontend/rust-lib/flowy-codegen/src/ts_event/mod.rs

@@ -1,6 +1,6 @@
 mod event_template;
 
-use crate::dart_event::ast::EventASTContext;
+use crate::ast::EventASTContext;
 use crate::flowy_toml::{parse_crate_config_from, CrateConfig};
 use crate::ts_event::event_template::{EventRenderContext, EventTemplate};
 use crate::util::{is_crate_dir, is_hidden, path_string_with_component, read_file};
@@ -13,10 +13,9 @@ use syn::Item;
 use walkdir::WalkDir;
 
 pub fn gen(crate_name: &str) {
-    if std::env::var("TAURI_PROTOBUF_PATH").is_err() {
-        log::warn!("TAURI_PROTOBUF_PATH was not set, skip generate ts event");
-        return;
-    }
+    let root = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("../../".to_string());
+    let tauri_protobuf_path =
+        std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("appflowy_tauri/src/protobuf".to_string());
 
     let crate_path = std::fs::canonicalize(".").unwrap().as_path().display().to_string();
     let event_crates = parse_ts_event_files(vec![crate_path]);
@@ -33,15 +32,7 @@ pub fn gen(crate_name: &str) {
     }
     render_result.push_str(TS_FOOTER);
 
-    let ts_event_folder: PathBuf = [
-        &std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap(),
-        &std::env::var("TAURI_PROTOBUF_PATH").unwrap(),
-        "events",
-        crate_name,
-    ]
-    .iter()
-    .collect();
-
+    let ts_event_folder: PathBuf = [&root, &tauri_protobuf_path, "events", crate_name].iter().collect();
     if !ts_event_folder.as_path().exists() {
         std::fs::create_dir_all(ts_event_folder.as_path()).unwrap();
     }

+ 2 - 2
frontend/rust-lib/flowy-sync/src/synchronizer.rs

@@ -149,7 +149,7 @@ where
     pub async fn pong(&self, user: Arc<dyn RevisionUser>, client_rev_id: i64) -> Result<(), CollaborateError> {
         let object_id = self.object_id.clone();
         let server_rev_id = self.rev_id();
-        tracing::Span::current().record("server_rev_id", &server_rev_id);
+        tracing::Span::current().record("server_rev_id", server_rev_id);
         match server_rev_id.cmp(&client_rev_id) {
             Ordering::Less => {
                 tracing::trace!("Client should not send ping and the server should pull the revisions from the client")
@@ -171,7 +171,7 @@ where
     #[tracing::instrument(level = "debug", skip(self, revisions), fields(object_id), err)]
     pub async fn reset(&self, revisions: Vec<Revision>) -> Result<(), CollaborateError> {
         let object_id = self.object_id.clone();
-        tracing::Span::current().record("object_id", &object_id.as_str());
+        tracing::Span::current().record("object_id", object_id.as_str());
         let (_, rev_id) = pair_rev_id_from_revision_pbs(&revisions);
         let operations = make_operations_from_revisions(revisions.clone())?;
         self.persistence.reset_object(&object_id, revisions).await?;

+ 25 - 17
frontend/scripts/makefile/tauri.toml

@@ -1,37 +1,45 @@
+
+
+
+[tasks.tauri_env]
+script_runner = "@rust"
+script = '''
+//! ```cargo
+use std::env;
+fn main() {
+    env.set_var("TAURI_PROTOBUF_PATH", "appflowy_tauri/src/protobuf");
+}
+'''
+
+
 [tasks.tauri_build]
-script = [
-    """
+script = ["""
     cd appflowy_tauri/src-tauri
     npm run tauri build
-    """,
-]
+    """]
 script_runner = "@shell"
 
 [tasks.tauri_pb]
-script = [
-    """
+script = ["""
     cd appflowy_tauri/src-tauri
     cargo build
-    """,
-]
+    """]
 script_runner = "@shell"
 
 [tasks.tauri_dev]
-script = [
-    """
+script = ["""
     cd appflowy_tauri
     npm run tauri dev
-    """,
-]
+    """]
 script_runner = "@shell"
 
 [tasks.tauri_clean]
 run_task = { name = [
-    "rust_lib_clean",
-    "rm_macro_build_cache",
-    "rm_rust_generated_files",
-    "rm_tauri_generated_protobuf_files",
-    "rm_tauri_generated_event_files",
+  "rust_lib_clean",
+  "rm_macro_build_cache",
+  "rm_rust_generated_files",
+  "rm_tauri_generated_protobuf_files",
+  "rm_tauri_generated_event_files",
 ] }
 
 [tasks.rm_tauri_generated_protobuf_files]