//! client client //! NATS(c2se) NATS(c2se) //! <---> <---> //! client broker //! <---> <---> //! NATS(se2c) NATS(se2c) //! server edge server edge //! NATS(se) NATS(se) //! <---> <---> //! server service server broker server service //! NATS(ss) <---> <---> NATS(ss) //! use once_cell::sync::Lazy; use std::{collections::HashMap, fs, path::Path, process::Command}; static PROTO_PATHS: Lazy> = Lazy::new(|| vec!["/usr/local/include/protobuf/", "./proto/"]); static TARGETS: Lazy>> = Lazy::new(|| { println!("initializing"); let mut m = HashMap::new(); m.insert( "protobuf", vec![ "./proto/protobuf/rpc.proto", "./proto/protobuf/pagination.proto", ], ); m.insert( "models", vec![ "./proto/models/core/network.proto", "./proto/models/bank.proto", "./proto/models/member_bank_account.proto", "./proto/models/member_bank_deposit.proto", "./proto/models/member_bank_withdraw.proto", "./proto/models/member_class.proto", "./proto/models/member_level.proto", "./proto/models/member_permission.proto", "./proto/models/member_role.proto", "./proto/models/member_session.proto", "./proto/models/member_referrer.proto", "./proto/models/member.proto", "./proto/models/member_game_setting.proto", "./proto/models/member_settlement_setting.proto", "./proto/models/resource_action.proto", "./proto/models/resource.proto", "./proto/models/role.proto", "./proto/models/site.proto", "./proto/models/api/vendor.proto", "./proto/models/api/game.proto", ], ); m.insert( "c2se", vec![ "./proto/c2se/bank.proto", "./proto/c2se/identity.proto", "./proto/c2se/member_bank_account.proto", "./proto/c2se/member_bank_deposit.proto", "./proto/c2se/member_bank_withdraw.proto", "./proto/c2se/member_class.proto", "./proto/c2se/member_level.proto", "./proto/c2se/member_referrer.proto", "./proto/c2se/member.proto", "./proto/c2se/member_game_setting.proto", "./proto/c2se/member_settlement_setting.proto", "./proto/c2se/site.proto", "./proto/c2se/core/network.proto", "./proto/c2se/api/vendor.proto", "./proto/c2se/api/game.proto", "./proto/c2se/backend/bank.proto", "./proto/c2se/backend/identity.proto", "./proto/c2se/backend/member_bank_account.proto", "./proto/c2se/backend/member_bank_deposit.proto", "./proto/c2se/backend/member_bank_withdraw.proto", "./proto/c2se/backend/member_class.proto", "./proto/c2se/backend/member_level.proto", "./proto/c2se/backend/member_referrer.proto", "./proto/c2se/backend/member.proto", "./proto/c2se/backend/member_game_setting.proto", "./proto/c2se/backend/member_settlement_setting.proto", "./proto/c2se/backend/site.proto", "./proto/c2se/backend/api/vendor.proto", "./proto/c2se/backend/api/game.proto", "./proto/c2se/frontend/bank.proto", "./proto/c2se/frontend/identity.proto", "./proto/c2se/frontend/member_bank_account.proto", "./proto/c2se/frontend/member_bank_deposit.proto", "./proto/c2se/frontend/member_bank_withdraw.proto", "./proto/c2se/frontend/member_referrer.proto", "./proto/c2se/frontend/member.proto", "./proto/c2se/frontend/api/vendor.proto", "./proto/c2se/frontend/api/game.proto", ], ); m.insert( "ss", vec![ "./proto/ss/bank.proto", "./proto/ss/identity.proto", "./proto/ss/member_bank_account.proto", "./proto/ss/member_bank_deposit.proto", "./proto/ss/member_bank_withdraw.proto", "./proto/ss/member_class.proto", "./proto/ss/member_level.proto", "./proto/ss/member_referrer.proto", "./proto/ss/member.proto", "./proto/ss/member_game_setting.proto", "./proto/ss/member_settlement_setting.proto", "./proto/ss/site.proto", "./proto/ss/api/vendor.proto", "./proto/ss/api/game.proto", ], ); m }); fn main() { let build_path = "./build"; if Path::new(build_path).exists() { fs::remove_dir_all(build_path).expect("clean for library directory is failed"); } fs::create_dir_all(build_path).expect("creating for library directory is failed"); let build_path_rust = format!("{}/rust", build_path); if Path::new(&build_path_rust).exists() { fs::remove_dir_all(&build_path_rust).expect("clean for rust library directory is failed"); } fs::create_dir_all(&build_path_rust).expect("creating for rust library directory is failed"); let build_path_javascript = format!("{}/javascript", build_path); if Path::new(&build_path_javascript).exists() { fs::remove_dir_all(&build_path_javascript) .expect("clean for javascript library directory is failed"); } fs::create_dir_all(&build_path_javascript) .expect("creating for javascript library directory is failed"); let proto_paths: Vec<_> = PROTO_PATHS .iter() .map(|v| format!("--proto_path={}", *v)) .collect(); eprintln!("proto_paths: {:?}", proto_paths); for (key, protos) in TARGETS.iter() { let build_path_rust_sub = format!("{}/{}", &build_path_rust, key); fs::create_dir_all(&build_path_rust_sub) .expect("creating for rust library sub directory is failed"); let mut prost_build = prost_build::Config::new(); prost_build.out_dir(build_path_rust_sub); prost_build .compile_protos(protos.as_slice(), PROTO_PATHS.as_slice()) .expect("generating library for rust is failed"); let output = Command::new("protoc") .args(proto_paths.as_slice()) .args(["--experimental_allow_proto3_optional"]) .args(&[ &format!( "--js_out=import_style=commonjs,binary:{}", &build_path_javascript ), &format!("--ts_out={}", &build_path_javascript), ]) .args(protos.as_slice()) .output() .expect("generating library for javascript is failed"); eprintln!( "generating library for javascript status: {}", output.status.success() ); eprintln!( "generating library for typescript stdout: {}", String::from_utf8_lossy(&output.stdout) ); eprintln!( "generating library for typescript stderr: {}", String::from_utf8_lossy(&output.stderr) ); } }