This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
codegen.rs
executable file
·69 lines (59 loc) · 1.99 KB
/
codegen.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#[cfg(not(feature = "es6"))]
pub mod tcp {
use protoc_rust::Customize;
use std::path::Path;
pub fn generate() {
let generated_file = Path::new("src/internal/messages.rs");
if !generated_file.exists() {
protoc_rust::Codegen::new()
.out_dir("src/internal")
.inputs(&["protos/tcp/messages.proto"])
.include("protos/tcp")
.customize(Customize {
carllerche_bytes_for_bytes: Some(true),
carllerche_bytes_for_string: Some(true),
..Default::default()
})
.run()
.expect("Running protoc failed");
}
}
}
#[cfg(feature = "es6")]
pub mod es6 {
pub fn generate() {
let out_dir = "src/es6/grpc/event_store/client";
let files = [
"protos/es6/persistent.proto",
"protos/es6/streams.proto",
"protos/es6/shared.proto",
];
tonic_build::configure()
.build_server(false)
.out_dir(out_dir)
.compile(&files, &["protos/es6"])
.unwrap();
let gen_dir = std::fs::read_dir(out_dir).unwrap();
for entry in gen_dir {
let file = entry.unwrap();
let filename_string = file.file_name().into_string().unwrap();
if filename_string.starts_with("event_store.client.") {
let remaining = filename_string.trim_start_matches("event_store.client.");
let new_file_name = if remaining == "persistent_subscriptions.rs" {
"persistent.rs"
} else {
remaining
};
let new_file = file.path().parent().unwrap().join(new_file_name);
std::fs::rename(file.path(), new_file).unwrap();
}
}
}
}
#[cfg(feature = "es6")]
use self::es6::generate;
#[cfg(not(feature = "es6"))]
use self::tcp::generate;
fn main() {
generate();
}