-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
59 lines (51 loc) · 1.65 KB
/
build.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
use harmony_build::{Builder, Protocol, Result};
fn main() -> Result<()> {
build_protocol(
"before_account_kind",
&["profile.v1", "harmonytypes.v1"],
&[],
|builder| {
builder.modify_hrpc_config(|cfg| {
cfg.type_attribute(
".protocol.profile.v1.Profile",
"#[archive_attr(derive(::bytecheck::CheckBytes))]",
)
})
},
)?;
Ok(())
}
fn build_protocol(
version: &str,
stable_svcs: &[&str],
staging_svcs: &[&str],
f: impl FnOnce(Builder) -> Builder,
) -> Result<()> {
let protocol_path = format!("protocols/{}", version);
let out_dir = {
let mut dir = std::env::var("OUT_DIR").expect("no out dir, how");
dir.push('/');
dir.push_str(version);
dir
};
std::fs::create_dir_all(&out_dir)?;
let all_services = stable_svcs.iter().chain(staging_svcs.iter());
let protocol = Protocol::from_path(protocol_path, stable_svcs, staging_svcs)?;
let mut builder = Builder::new()
.modify_hrpc_config(|cfg| cfg.build_client(false).build_server(false))
.modify_prost_config(|mut cfg| {
cfg.bytes(&[".protocol.batch.v1"]);
cfg
});
for service in all_services.filter(|a| "batch.v1".ne(**a)) {
builder = builder.modify_hrpc_config(|cfg| {
cfg.type_attribute(
format!(".protocol.{}", service),
"#[derive(::rkyv::Archive, ::rkyv::Serialize, ::rkyv::Deserialize)]",
)
});
}
let builder = f(builder);
builder.generate(protocol, out_dir)?;
Ok(())
}