|
@@ -22,7 +22,7 @@ pub fn gen(crate_name: &str, proto_file_dir: &str) {
|
|
#[cfg(feature = "proto_gen")]
|
|
#[cfg(feature = "proto_gen")]
|
|
let _ = gen_protos(crate_name);
|
|
let _ = gen_protos(crate_name);
|
|
|
|
|
|
- let mut paths = vec![];
|
|
|
|
|
|
+ let mut proto_file_paths = vec![];
|
|
let mut file_names = vec![];
|
|
let mut file_names = vec![];
|
|
|
|
|
|
for (path, file_name) in WalkDir::new(proto_file_dir)
|
|
for (path, file_name) in WalkDir::new(proto_file_dir)
|
|
@@ -37,26 +37,31 @@ pub fn gen(crate_name: &str, proto_file_dir: &str) {
|
|
if path.ends_with(".proto") {
|
|
if path.ends_with(".proto") {
|
|
// https://stackoverflow.com/questions/49077147/how-can-i-force-build-rs-to-run-again-without-cleaning-my-whole-project
|
|
// https://stackoverflow.com/questions/49077147/how-can-i-force-build-rs-to-run-again-without-cleaning-my-whole-project
|
|
println!("cargo:rerun-if-changed={}", path);
|
|
println!("cargo:rerun-if-changed={}", path);
|
|
- paths.push(path);
|
|
|
|
|
|
+ proto_file_paths.push(path);
|
|
file_names.push(file_name);
|
|
file_names.push(file_name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
let protoc_bin_path = protoc_bin_vendored::protoc_bin_path().unwrap();
|
|
let protoc_bin_path = protoc_bin_vendored::protoc_bin_path().unwrap();
|
|
|
|
|
|
// 2. generate the protobuf files(Dart)
|
|
// 2. generate the protobuf files(Dart)
|
|
#[cfg(feature = "dart")]
|
|
#[cfg(feature = "dart")]
|
|
- generate_dart_protobuf_files(crate_name, proto_file_dir, &paths, &file_names, &protoc_bin_path);
|
|
|
|
|
|
+ generate_dart_protobuf_files(
|
|
|
|
+ crate_name,
|
|
|
|
+ proto_file_dir,
|
|
|
|
+ &proto_file_paths,
|
|
|
|
+ &file_names,
|
|
|
|
+ &protoc_bin_path,
|
|
|
|
+ );
|
|
|
|
|
|
// 3. generate the protobuf files(Rust)
|
|
// 3. generate the protobuf files(Rust)
|
|
- generate_rust_protobuf_files(&protoc_bin_path, &paths, proto_file_dir);
|
|
|
|
|
|
+ generate_rust_protobuf_files(&protoc_bin_path, &proto_file_paths, proto_file_dir);
|
|
}
|
|
}
|
|
|
|
|
|
-fn generate_rust_protobuf_files(protoc_bin_path: &PathBuf, input_paths: &Vec<String>, proto_file_dir: &str) {
|
|
|
|
|
|
+fn generate_rust_protobuf_files(protoc_bin_path: &PathBuf, proto_file_paths: &Vec<String>, proto_file_dir: &str) {
|
|
protoc_rust::Codegen::new()
|
|
protoc_rust::Codegen::new()
|
|
.out_dir("./src/protobuf/model")
|
|
.out_dir("./src/protobuf/model")
|
|
.protoc_path(protoc_bin_path)
|
|
.protoc_path(protoc_bin_path)
|
|
- .inputs(input_paths)
|
|
|
|
|
|
+ .inputs(proto_file_paths)
|
|
.include(proto_file_dir)
|
|
.include(proto_file_dir)
|
|
.run()
|
|
.run()
|
|
.expect("Running protoc failed.");
|
|
.expect("Running protoc failed.");
|
|
@@ -68,7 +73,7 @@ fn generate_dart_protobuf_files(
|
|
root: &str,
|
|
root: &str,
|
|
paths: &Vec<String>,
|
|
paths: &Vec<String>,
|
|
file_names: &Vec<String>,
|
|
file_names: &Vec<String>,
|
|
- proto_path: &PathBuf,
|
|
|
|
|
|
+ protoc_bin_path: &PathBuf,
|
|
) {
|
|
) {
|
|
if std::env::var("CARGO_MAKE_WORKING_DIRECTORY").is_err() {
|
|
if std::env::var("CARGO_MAKE_WORKING_DIRECTORY").is_err() {
|
|
log::warn!("CARGO_MAKE_WORKING_DIRECTORY was not set, skip generate dart pb");
|
|
log::warn!("CARGO_MAKE_WORKING_DIRECTORY was not set, skip generate dart pb");
|
|
@@ -82,15 +87,15 @@ fn generate_dart_protobuf_files(
|
|
|
|
|
|
let workspace_dir = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap();
|
|
let workspace_dir = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap();
|
|
let flutter_sdk_path = std::env::var("FLUTTER_FLOWY_SDK_PATH").unwrap();
|
|
let flutter_sdk_path = std::env::var("FLUTTER_FLOWY_SDK_PATH").unwrap();
|
|
- let output = format!("{}/{}/{}", workspace_dir, flutter_sdk_path, name);
|
|
|
|
|
|
+ let output = format!("{}/{}/lib/protobuf/{}", workspace_dir, flutter_sdk_path, name);
|
|
if !std::path::Path::new(&output).exists() {
|
|
if !std::path::Path::new(&output).exists() {
|
|
std::fs::create_dir_all(&output).unwrap();
|
|
std::fs::create_dir_all(&output).unwrap();
|
|
}
|
|
}
|
|
check_pb_dart_plugin();
|
|
check_pb_dart_plugin();
|
|
- let proto_path = proto_path.to_str().unwrap().to_owned();
|
|
|
|
|
|
+ let protoc_bin_path = protoc_bin_path.to_str().unwrap().to_owned();
|
|
paths.iter().for_each(|path| {
|
|
paths.iter().for_each(|path| {
|
|
if cmd_lib::run_cmd! {
|
|
if cmd_lib::run_cmd! {
|
|
- ${proto_path} --dart_out=${output} --proto_path=${root} ${path}
|
|
|
|
|
|
+ ${protoc_bin_path} --dart_out=${output} --proto_path=${root} ${path}
|
|
}
|
|
}
|
|
.is_err()
|
|
.is_err()
|
|
{
|
|
{
|