diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f95eb3e0e7..3b37270dde 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,6 +32,7 @@ jobs: run: | cargo install --force cargo-make cargo install --force duckscript_cli + brew install protobuf cargo make flowy_dev - name: Build working-directory: frontend @@ -73,6 +74,7 @@ jobs: run: | cargo install --force cargo-make cargo install --force duckscript_cli + sudo apt-get install protobuf-compiler cargo make flowy_dev - name: Build working-directory: frontend diff --git a/frontend/scripts/makefile/desktop.toml b/frontend/scripts/makefile/desktop.toml index cab4dcba60..157b1a4b92 100644 --- a/frontend/scripts/makefile/desktop.toml +++ b/frontend/scripts/makefile/desktop.toml @@ -5,7 +5,7 @@ # cargo make --profile production-windows-x86 flowy-sdk-dev [tasks.env_check] -dependencies = ["echo_env"] +dependencies = ["echo_env", "install-pb-tool-if-need"] condition = { env_set = [ "BUILD_FLAG", "RUST_COMPILE_TARGET", "CRATE_TYPE", "TARGET_OS"], channels = ["stable"] } [tasks.flowy-sdk-dev] @@ -142,3 +142,16 @@ script = [ """, ] script_runner = "@duckscript" + +[tasks.check_protoc_cmd] +script = [ + """ + ret = which protoc + if is_empty ${ret} + echo Please make sure /bin/ is in PATH env var + echo See BUILD_ON_{LINUX|WINDOWS}.md for how to get protoc + exit -1 + end + """, +] +script_runner = "@duckscript" diff --git a/frontend/scripts/makefile/env.toml b/frontend/scripts/makefile/env.toml index 4bf1122e02..ae36f2d1ba 100644 --- a/frontend/scripts/makefile/env.toml +++ b/frontend/scripts/makefile/env.toml @@ -95,30 +95,6 @@ dependencies=["install_targets"] [tasks.install_prerequests.windows] dependencies=["install_targets", "install_windows_deps"] -[tasks.install_protobuf] -script = """ -dart pub global activate protoc_plugin -cargo install --version 2.22.1 protobuf-codegen -""" - -[tasks.install_protobuf.windows] -script = """ -ret = which dart -if is_empty ${ret} - echo Please make sure flutter/dart is properly installed and in PATH env var - exit -1 -end -ret = which protoc-gen-dart -if is_empty ${ret} - exec cmd.exe /c dart pub global activate protoc_plugin - home_dir = get_home_dir - echo Please add '${home_dir}\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\bin' into PATH env var - exit -1 -end -exec cargo install --version 2.22.1 protobuf-codegen -""" -script_runner = "@duckscript" - [tasks.install_tools] script = """ rustup component add rustfmt diff --git a/frontend/scripts/makefile/protobuf.toml b/frontend/scripts/makefile/protobuf.toml index 6cef4512d2..5dc076a013 100644 --- a/frontend/scripts/makefile/protobuf.toml +++ b/frontend/scripts/makefile/protobuf.toml @@ -2,6 +2,52 @@ [tasks.pb] dependencies = ["check_protoc_cmd", "gen_pb_file"] +[tasks.install-pb-tool-if-need] +condition_script = [ + """ + if [ ! "$(command -v dart)" ]; then + echo Please make sure flutter/dart is properly installed and in PATH env var + exit 1 + fi + + if [ ! "$(command -v protoc-gen-dart)" ]; then + # not install + exit 0 + fi + + # installed + exit 1 + """, +] +run_task = { name = ["install_protobuf"] } + +[tasks.install_protobuf] +script = """ +echo "Install protoc_plugin (Dart)" +dart pub global activate protoc_plugin +export PATH="$HOME/.pub-cache/bin:$PATH" + +cargo install --version 2.22.1 protobuf-codegen +""" +script_runner = "@shell" + +[tasks.install_protobuf.windows] +script = """ +ret = which dart +if is_empty ${ret} + echo Please make sure flutter/dart is properly installed and in PATH env var + exit -1 +end +ret = which protoc-gen-dart +if is_empty ${ret} + exec cmd.exe /c dart pub global activate protoc_plugin + home_dir = get_home_dir + echo Please add '${home_dir}\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\bin' into PATH env var + exit -1 +end +""" +script_runner = "@duckscript" + [tasks.check_protoc_cmd] script = [ """ diff --git a/shared-lib/lib-infra/src/pb_gen.rs b/shared-lib/lib-infra/src/pb_gen.rs index 5296a39f31..b63c6a0067 100644 --- a/shared-lib/lib-infra/src/pb_gen.rs +++ b/shared-lib/lib-infra/src/pb_gen.rs @@ -1,8 +1,10 @@ #![allow(unused_imports)] +#![allow(unused_attributes)] use std::fs::File; use std::io::Write; use walkdir::WalkDir; +#[allow(dead_code)] pub fn gen(name: &str, root: &str) { let mut paths = vec![]; let mut file_names = vec![]; @@ -19,8 +21,8 @@ pub fn gen(name: &str, root: &str) { } } - #[cfg(feature = "dart")] - gen_pb_for_dart(name, root, &paths, &file_names); + // #[cfg(feature = "dart")] + // gen_pb_for_dart(name, root, &paths, &file_names); protoc_rust::Codegen::new() .out_dir("./src/protobuf/model") @@ -31,6 +33,7 @@ pub fn gen(name: &str, root: &str) { } #[cfg(feature = "dart")] +#[allow(dead_code)] fn gen_pb_for_dart(name: &str, root: &str, paths: &Vec, file_names: &Vec) { let output = format!( "{}/{}/{}",