File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use std::process::Command;
2+
3+ fn main() {
4+ let git_hash = Command::new("git")
5+ .args(["describe", "--always", "--dirty"])
6+ .output()
7+ .map(|output| {
8+ if output.status.success() {
9+ String::from_utf8_lossy(&output.stdout).trim().to_string()
10+ } else {
11+ "unknown".to_string()
12+ }
13+ })
14+ .unwrap_or_else(|_| "unknown".to_string());
15+
16+ let git_date = Command::new("git")
17+ .args(["log", "-1", "--format=%cs"])
18+ .output()
19+ .map(|output| {
20+ if output.status.success() {
21+ String::from_utf8_lossy(&output.stdout).trim().to_string()
22+ } else {
23+ "unknown".to_string()
24+ }
25+ })
26+ .unwrap_or_else(|_| "unknown".to_string());
27+
28+ // Make the git info available to the program
29+ println!("cargo:rustc-env=GIT_HASH={}", git_hash);
30+ println!("cargo:rustc-env=GIT_DATE={}", git_date);
31+
32+ // Re-run build script if git HEAD changes
33+ println!("cargo:rerun-if-changed=.git/HEAD");
34+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,16 @@ use std::env;
22
33use cargo_hyperlight::cargo;
44
5+ const VERSION: &str = env!("CARGO_PKG_VERSION");
6+ const GIT_HASH: &str = env!("GIT_HASH");
7+ const GIT_DATE: &str = env!("GIT_DATE");
8+
59fn main() {
10+ if env::args().any(|arg| arg == "--version" || arg == "-V") {
11+ println!("cargo-hyperlight {} ({} {})", VERSION, GIT_HASH, GIT_DATE);
12+ return;
13+ }
14+
615 let args = env::args_os().enumerate().filter_map(|(i, arg)| {
716 // skip the binary name and the "hyperlight" subcommand if present
817 if i == 0 || (i == 1 && arg == "hyperlight") {
You can’t perform that action at this time.
0 commit comments