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


#1

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

build.rs setting an env var and env!() in the code looks right.


#3

try crate built: https://docs.rs/built


#4

built sounds awesome, thanks!