Embed extra build time information in --version
All checks were successful
Build and test / check (push) Successful in 2m38s
Build and test / build (push) Successful in 3m30s
Build and test / check-license (push) Successful in 4m49s
Build and test / test (push) Successful in 4m20s
Build and test / docs (push) Successful in 5m40s

This commit is contained in:
2025-12-03 12:24:21 +09:00
parent 7df04ec413
commit 3ac90dcb26
4 changed files with 135 additions and 3 deletions

View File

@@ -3,6 +3,30 @@ use anyhow::anyhow;
#[cfg(feature = "mysql-admutils-compatibility")]
use std::{env, os::unix::fs::symlink, path::PathBuf};
fn get_git_commit() -> Option<String> {
let repo = git2::Repository::discover(".").ok()?;
let head = repo.head().ok()?;
let commit = head.peel_to_commit().ok()?;
Some(commit.id().to_string())
}
fn embed_build_time_info() {
let commit = option_env!("GIT_COMMIT")
.map(|s| s.to_string())
.or_else(get_git_commit)
.unwrap_or_else(|| "unknown".to_string());
let build_profile = std::env::var("OUT_DIR")
.unwrap_or_else(|_| "unknown".to_string())
.split(std::path::MAIN_SEPARATOR)
.nth_back(3)
.unwrap_or("unknown")
.to_string();
println!("cargo:rustc-env=GIT_COMMIT={}", commit);
println!("cargo:rustc-env=BUILD_PROFILE={}", build_profile);
}
fn generate_mysql_admutils_symlinks() -> anyhow::Result<()> {
// NOTE: This is slightly illegal, and depends on implementation details.
// But it is only here for ease of testing the compatibility layer,
@@ -42,5 +66,7 @@ fn main() -> anyhow::Result<()> {
#[cfg(feature = "mysql-admutils-compatibility")]
generate_mysql_admutils_symlinks()?;
embed_build_time_info();
Ok(())
}