I host a Rust project in git repository and I want to make it print the version on some command. How can I include the version into the program? I thought that the build script
I can only think about writing data to some file, but I think this is overkill for this case.
That's unfortunate, because that is the only way of doing it. Environment variables can't work because changes to the environment can't "leak" into other, non-child processes.
For simpler things, you can instruct Cargo to define conditional compilation flags, but those aren't powerful enough to communicate a string [1].
The details of generating code from a build script is detailed in the code generation section of the Cargo documentation.
[1]: I mean, unless you feel like breaking the hash into 160 config flags and then re-assembling them in the source being compiled, but that's even more overkill.