Is there a way to include the (git)commit hash in the building crate for debug builds only?


I wonder whether there is a convenient way to include the git commit hash into the debug build of a crate, but not into the release build.

My attempt on solving this is: this build script and this helper macro.

Maybe there’s a more convenient way? Cargo does not include this information as environment variable itself, as far as I see? Maybe that’s an idea for a feature in cargo?

#2 setting an env var and env!() in the code looks right.


try crate built:


built sounds awesome, thanks!