diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..2928c1b --- /dev/null +++ b/build.rs @@ -0,0 +1,22 @@ +use std::{env, fs, path::Path}; + +fn main() { + let out_dir = env::var_os("OUT_DIR").unwrap(); + + let path = Path::new(&out_dir).join("git_hash.rs"); + + let git_output = std::process::Command::new("git") + .args(["rev-parse", "--short", "HEAD"]) + .output() + .unwrap() + .stdout; + + let last_hash = String::from_utf8(git_output).unwrap(); + let last_hash = last_hash.trim(); + + fs::write( + &path, + format!("pub const GIT_HASH: &str = \"{last_hash}\";"), + ) + .unwrap(); +} diff --git a/justfile b/justfile index 7d3fb8d..c717d91 100644 --- a/justfile +++ b/justfile @@ -2,7 +2,7 @@ set export set quiet set dotenv-load -#[arg("assets", long="assets")] +[arg("assets", long="assets")] build assets="false": #!/usr/bin/env bash mkdir -p ./out diff --git a/src/main.rs b/src/main.rs index 5785e94..0229ceb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,8 @@ use tracing_subscriber::EnvFilter; mod common; +include!(concat!(env!("OUT_DIR"), "/git_hash.rs")); + #[cfg(feature = "bbs")] mod bbs; diff --git a/templates/layouts/base.html b/templates/layouts/base.html index d133685..292230a 100644 --- a/templates/layouts/base.html +++ b/templates/layouts/base.html @@ -11,7 +11,7 @@