-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the git hash and commit/date to
--version
(#896)
Inspired by similar functionality on `wit-bindgen`
- Loading branch information
1 parent
21478d4
commit e60c90e
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::{path::Path, process::Command}; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
|
||
commit_info(); | ||
} | ||
|
||
fn commit_info() { | ||
if !Path::new(".git").exists() { | ||
return; | ||
} | ||
let output = match Command::new("git") | ||
.arg("log") | ||
.arg("-1") | ||
.arg("--date=short") | ||
.arg("--format=%H %h %cd") | ||
.arg("--abbrev=9") | ||
.output() | ||
{ | ||
Ok(output) if output.status.success() => output, | ||
_ => return, | ||
}; | ||
let stdout = String::from_utf8(output.stdout).unwrap(); | ||
let mut parts = stdout.split_whitespace(); | ||
let mut next = || parts.next().unwrap(); | ||
println!("cargo:rustc-env=CARGO_GIT_HASH={}", next()); | ||
println!( | ||
"cargo:rustc-env=CARGO_VERSION_INFO={} ({} {})", | ||
env!("CARGO_PKG_VERSION"), | ||
next(), | ||
next() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters