# Build Version Information into Your Rust Binary To help us disect the problem from a deployed binary, it will be useful to build some information like git-commit hash, build date, etc. Use [`vergen`](https://crates.io/crates/vergen) to generate a list of `env` during building. You have to add `vergen` into `Cargo.toml`. ```toml [package] build = "build.rs" [build-dependencies] anyhow = "1.0.69" vergen = { version = "7.5.1", features = ["build", "git"] } ``` Since we are using these packages in `build.rs` instead of `src/*.rs`, we should specify each version of the packages in the `build-dependencies` section. After setting up the `Cargo.toml`, prepare a `build.rs`: ```rs use anyhow::Result; use vergen::{vergen, Config}; fn main() -> Result<()> { vergen(Config::default()) } ``` Then we can retrieve the enviroment variables in our source code ```rs fn main() { println!("build from commit {}", env!["VERGEN_GIT_SHA"]); } ``` ###### tags: `rust`