/
rustwizard
/
pg_exporter
Обзор
Документация
Войти
/
rustwizard
/
pg_exporter
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
build.rs
23 строки
777 B
Rust Wizard
add build script and git hash to the version
07 ноя 2025, 16:13
Верифицирован
07 ноя 2025, 16:13
cfd13c9
Код
Авторство
О чём код?
use std::process::Command; fn main() { // Get the Git hash let output = Command::new("git").args(["rev-parse", "HEAD"]).output(); let git_hash = match output { Ok(o) if o.status.success() => String::from_utf8_lossy(&o.stdout).trim().to_string(), _ => { eprintln!( "Warning: Could not get Git hash. Is Git installed and are you in a Git repository?" ); "unknown".to_string() } }; // Make the hash available as an environment variable println!("cargo:rustc-env=GIT_HASH={}", git_hash); // Rerun if the HEAD of the Git repository changes println!("cargo:rerun-if-changed=.git/HEAD"); println!("cargo:rerun-if-changed=.git/index"); // Also consider index changes }