-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
36 lines (32 loc) · 1.23 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
// The following method for generating Rust code from .proto files is
// adapted from a recommendation of the `rust-protobuf` library:
//
// https://github.com/stepancheg/rust-protobuf/tree/master/protoc-rust
#[cfg(feature = "proto-gen")]
use protobuf_codegen;
#[cfg(feature = "proto-gen")]
use std::fs;
// NOTE: When this feature is enabled, the build will always run, even if the
// .proto file has not changed. This happens because the .rs file always gets
// updated, since this function unconditionally creates it.
#[cfg(feature = "proto-gen")]
fn proto_gen() {
protobuf_codegen::Codegen::new()
.pure()
.out_dir("proto/")
.includes(&["proto/"])
.input("proto/metadata.proto")
.run_from_script();
// Allow missing docs for the generated code, since its not under our
// control.
let proto_mod_rs =
fs::read_to_string("proto/mod.rs").expect("Unable to open file");
let header = "// Header added by Tindercrypt's build.rs script\n\
#![allow(missing_docs)]\n\n";
let new_proto_mod_rs = header.to_owned() + &proto_mod_rs;
fs::write("proto/mod.rs", new_proto_mod_rs).expect("Unable to write file");
}
fn main() {
#[cfg(feature = "proto-gen")]
proto_gen()
}