This was kind of taken from a cool trick I saw in dub's buildscript, but I figured it would be useful to have generalized in a convenient package, no messing with shell scripts or anything.

gen-package-version: Automatically generate a D module with version and timestamp information (detected from git) every time your program or library is built.

Additionally. all your in-between builds will automatically have their own git-generated version number, including the git commit hash (for example: v1.2.0-1-g78f5cf9). So there's never any confusion as to which "version" of v1.2.0 you're running!

Full usage and instructions are at the link above, but here's a brief primer for those using it with dub:

To use:

Add this to your dub.json:

"dependencies": {
    "gen-package-version": "~>0.9.0"
    ["dub run gen-package-version -- --src=path/to/src"]

It'll generate "path/to/src/package/name/packageVersion.d".

Then just import that and use:


import std.stdio;

void main()
    writeln("My Cool Program ", packageVersion);
    writeln("Built on ", packageTimestamp);

Reply via email to