Thread overview
How to get compiler name and version from D code?
Jul 29
Kirill
Jul 29
Kirill
Jul 29
Dennis
July 29

I'd like to get the compiler name and version from within the D code automatically so my binary can output the following:

Built with COMPILER_NAME COMPILER_VERSION

It is possible?

July 29
Special tokens: https://dlang.org/spec/lex.html#special-token-sequence

You can also determine the compiler by a version.
July 29
On Friday, 29 July 2022 at 09:37:09 UTC, rikki cattermole wrote:
> Special tokens: https://dlang.org/spec/lex.html#special-token-sequence
>
> You can also determine the compiler by a version.

Thank you!
July 29

On Friday, 29 July 2022 at 09:29:47 UTC, Kirill wrote:

>
Built with COMPILER_NAME COMPILER_VERSION

Something like this:

version(DigitalMars) enum compiler = "DMD";
else version(LDC)    enum compiler = "LDC";
else version(GNU)    enum compiler = "GDC";
else enum compiler = "Unknown compiler";

enum buildInfo = "Built with "~compiler~" "~__VERSION__.stringof;

pragma(msg, buildInfo); // "Built with DMD 2099L"

With a bit more effort you could format the version nicely as "2.099".

July 29

On Friday, 29 July 2022 at 09:57:43 UTC, Dennis wrote:

>

On Friday, 29 July 2022 at 09:29:47 UTC, Kirill wrote:

>
Built with COMPILER_NAME COMPILER_VERSION

Something like this:

version(DigitalMars) enum compiler = "DMD";
else version(LDC)    enum compiler = "LDC";
else version(GNU)    enum compiler = "GDC";
else enum compiler = "Unknown compiler";

enum buildInfo = "Built with "~compiler~" "~__VERSION__.stringof;

pragma(msg, buildInfo); // "Built with DMD 2099L"

With a bit more effort you could format the version nicely as "2.099".

Or just import std.compiler;

https://dlang.org/phobos/std_compiler.html