-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.rs
53 lines (48 loc) · 1.87 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
use std::io;
use std::io::Write;
use std::process::Command;
fn main() {
// Use write! as a workaround to avoid https://github.com/rust-lang/rust/issues/46016
// when piping output to an external program
let mut stdout = io::stdout();
let mut output = Command::new("git")
.args(&["log", "-n1", "--pretty=format:%h", "HEAD"])
.output()
.unwrap();
let mut result = String::from_utf8(output.stdout).unwrap();
if !Command::new("git")
.args(&["diff", "--quiet"])
.status()
.expect("failed to execute process")
.success()
{
result += "-dirty";
}
_ = write!(&mut stdout, "cargo:rustc-env=GIT_HASH={}\n", result);
output = Command::new("git")
.args(&["log", "-n1", "--pretty=format:%cd", "--date=short", "HEAD"])
.output()
.unwrap();
result = String::from_utf8(output.stdout).unwrap().replace("-", "");
_ = write!(&mut stdout, "cargo:rustc-env=GIT_DATE={}\n", result);
output = Command::new("date")
.args(&["+%Y%m%d_%H%M%S"])
.output()
.unwrap();
result = String::from_utf8(output.stdout).unwrap();
_ = write!(&mut stdout, "cargo:rustc-env=BUILD_DATE={}\n", result);
// creating protobuf
protobuf_codegen::Codegen::new()
// Use `protoc` parser, optional.
.protoc()
// Use `protoc-bin-vendored` bundled protoc command, optional.
.protoc_path(&protoc_bin_vendored::protoc_bin_path().unwrap())
// All inputs and imports from the inputs must reside in `includes` directories.
.includes(&["src/protos"])
// Inputs must reside in some of include paths.
.input("src/protos/WifiStartRequest.proto")
.input("src/protos/WifiInfoResponse.proto")
// Specify output directory relative to Cargo output directory.
.cargo_out_dir("protos")
.run_from_script();
}