This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
51 lines (39 loc) · 1.99 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
use chrono::Utc;
use git_meta::GitRepo;
use std::env;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("protos/orbital_types.proto")?;
tonic_build::compile_protos("protos/build_meta.proto")?;
tonic_build::compile_protos("protos/notify.proto")?;
tonic_build::compile_protos("protos/organization.proto")?;
tonic_build::compile_protos("protos/secret.proto")?;
tonic_build::compile_protos("protos/code.proto")?;
println!("cargo:rerun-if-changed=protos/orbital_types.proto");
println!("cargo:rerun-if-changed=protos/build_meta.proto");
println!("cargo:rerun-if-changed=protos/notify.proto");
println!("cargo:rerun-if-changed=protos/organization.proto");
println!("cargo:rerun-if-changed=protos/secret.proto");
println!("cargo:rerun-if-changed=protos/code.proto");
let package_version = env::var("CARGO_PKG_VERSION")?;
let cargo_build_root = env::var("CARGO_MANIFEST_DIR")?;
// This is some manual walking to the root of the repo. Ew.
let git_repo_dir = Path::new(&cargo_build_root);
// This is all to get the commit id
let git_repo =
GitRepo::open(git_repo_dir.to_path_buf(), None, None).expect("Unable to open git repo");
//// FIXME: The `cargo publish --dry-run` fails with this
//let git_repo = GitRepo::open(git_repo_dir.to_path_buf(), None, None).unwrap_or_else(|_| {
// let cargo_publish_root = format!("{}/../../..", &cargo_build_root);
// let git_repo_cargo_publish_root = Path::new(&cargo_publish_root);
// GitRepo::open(git_repo_cargo_publish_root.to_path_buf(), None, None).unwrap()
//});
// Get git version
let git_commit = git_repo.head.expect("No GitCommitMeta found").id;
// Get build datetime
let now = Utc::now();
let version_string = format!("{} {} {}", package_version, git_commit, now.to_rfc3339());
println!("cargo:rustc-env=BUILD_VERSION={}", version_string);
println!("cargo:rerun-if-changed=build.rs");
Ok(())
}