From 85496e3200ab92a9e1aadafb57e797cae0243131 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Sun, 31 Dec 2023 17:41:59 +0100 Subject: [PATCH] make git commit hash available at compile time --- build.rs | 7 +++++++ src/main.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..9721023 --- /dev/null +++ b/build.rs @@ -0,0 +1,7 @@ +use std::process::Command; + +fn main() { + let output = Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output().unwrap(); + let git_hash = String::from_utf8(output.stdout).unwrap(); + println!("cargo:rustc-env=GIT_HASH={}", git_hash); +} diff --git a/src/main.rs b/src/main.rs index 71d0a95..553789b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,6 +160,7 @@ fn main() -> Result<()> { text += format!("\nYou gained {} experience.", game.get_player().get_experience()).as_str(); text += format!("\nYou collected {} gold.", game.get_player().get_gold()).as_str(); text += format!("\nYou played {} seconds.", playtime.as_secs()).as_str(); + text += format!("\nYou played game version '{}'.", env!("GIT_HASH")).as_str(); let paragraph = Paragraph::new(text).block(block).wrap(Wrap { trim: true }); frame.render_widget(paragraph, area); }); @@ -171,7 +172,6 @@ fn main() -> Result<()> { } } } - stdout().execute(LeaveAlternateScreen)?; disable_raw_mode()?; Ok(())