How can I include the build date in an executable

I am building a command line app and when the user asks for help with -h or --help I want the help output to include the datetime the executable was built. How can I do this?

Use the same trick as from Include git commit hash as string into Rust program - Stack Overflow

  • println!("cargo:rustc-env=DATE={}", date); in build.rs
  • env!("DATE") in main.rs or something
4 Likes

Be aware that this will prevent your program from being reproducible. The recommendation is to use the SOURCE_DATE_EPOCH env var if it is set: SOURCE_DATE_EPOCH — reproducible-builds.org

6 Likes

Thanks for your replies. The first one is sufficient for my needs since I don't need reproducible builds.