-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
50 lines (45 loc) · 1.81 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
//! Build script for Pleezer.
//!
//! This script:
//! 1. Sets Git-related environment variables if available:
//! * `PLEEZER_COMMIT_HASH` - Abbreviated commit hash
//! * `PLEEZER_COMMIT_DATE` - Commit date
//! 2. Generates Rust code from Protocol Buffer definitions in `src/protocol/connect/protos/`
//!
//! The Git information can be accessed at runtime using:
//! * `env!("PLEEZER_COMMIT_HASH")` for the commit hash
//! * `env!("PLEEZER_COMMIT_DATE")` for the commit date
use std::path::Path;
use git2::Repository;
use time::OffsetDateTime;
fn main() {
if let Ok(repo) = Repository::open(".") {
if let Some(commit) = repo.head().ok().and_then(|head| head.peel_to_commit().ok()) {
if let Some(hash) = commit
.as_object()
.short_id()
.ok()
.and_then(|buf| buf.as_str().map(|s| s.to_string()))
{
println!("cargo:rustc-env=PLEEZER_COMMIT_HASH={hash}");
}
if let Ok(timestamp) = OffsetDateTime::from_unix_timestamp(commit.time().seconds()) {
let format = time::format_description::parse("[year]-[month]-[day]")
.expect("invalid date format string");
println!(
"cargo:rustc-env=PLEEZER_COMMIT_DATE={}",
timestamp.format(&format).expect("could not format date")
);
}
}
}
let proto_dir = Path::new("src/protocol/connect/protos");
protobuf_codegen::Codegen::new()
.protoc()
.protoc_path(&protoc_bin_vendored::protoc_bin_path().expect("could not find protoc binary"))
.cargo_out_dir("protos")
.include(proto_dir)
.input(proto_dir.join("queue.proto"))
.input(proto_dir.join("repeat.proto"))
.run_from_script();
}