Files
roowho2/build.rs
T
oysteikt 58f711cbef
Build and test / check (push) Successful in 2m51s
Build and test / build (push) Successful in 2m53s
Build and test / test (push) Successful in 2m55s
Build and test / docs (push) Successful in 7m0s
bin/*: extended --version output
2026-07-30 20:55:50 +09:00

41 lines
1.2 KiB
Rust

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();
let dependencies = build_info_build::build_script()
.collect_runtime_dependencies(build_info_build::DependencyDepth::Depth(1))
.build()
.crate_info
.dependencies
.into_iter()
.map(|dep| format!("{}: {}", dep.name, dep.version))
.collect::<Vec<_>>()
.join(";");
println!("cargo:rustc-env=GIT_COMMIT={}", commit);
println!("cargo:rustc-env=BUILD_PROFILE={}", build_profile);
println!("cargo:rustc-env=DEPENDENCY_LIST={}", dependencies);
}
fn main() -> anyhow::Result<()> {
embed_build_time_info();
Ok(())
}