-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
48 additions
and
2 deletions.
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,27 @@ | ||
// Include the GIT_HASH, in `GIT_HASH` environment variable at build | ||
// time, panic'ing if it can not be found | ||
// | ||
// https://stackoverflow.com/questions/43753491/include-git-commit-hash-as-string-into-rust-program | ||
use std::process::Command; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
println!("cargo:rerun-if-env-changed=GIT_HASH"); | ||
// Populate env!(GIT_HASH) with the current git commit | ||
println!("cargo:rustc-env=GIT_HASH={}", get_git_hash()); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn get_git_hash() -> String { | ||
let git_hash = { | ||
let output = Command::new("git") | ||
.args(["describe", "--always", "--dirty", "--abbrev=64"]) | ||
.output() | ||
.expect("failed to execute git rev-parse to read the current git hash"); | ||
|
||
String::from_utf8(output.stdout).expect("non-utf8 found in git hash") | ||
}; | ||
|
||
assert!(!git_hash.is_empty(), "attempting to embed empty git hash"); | ||
git_hash | ||
} |
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 |
---|---|---|
@@ -1,2 +1,10 @@ | ||
pub(crate) static APP_USER_AGENT: &str = | ||
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),); | ||
pub(crate) static APP_USER_AGENT: &str = concat!( | ||
env!("CARGO_PKG_NAME"), | ||
"/", | ||
env!("CARGO_PKG_VERSION"), | ||
", revision ", | ||
env!("GIT_HASH") | ||
); | ||
|
||
pub(crate) static VERSION_STRING: &str = | ||
concat!(env!("CARGO_PKG_VERSION"), ", revision ", env!("GIT_HASH")); |
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
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