www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How to get compiler name and version from D code?

reply Kirill <kirill.saidov.d yahoo.com> writes:
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?
Jul 29 2022
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
Special tokens: https://dlang.org/spec/lex.html#special-token-sequence

You can also determine the compiler by a version.
Jul 29 2022
parent Kirill <kirill.saidov.d yahoo.com> writes:
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!
Jul 29 2022
prev sibling parent reply Dennis <dkorpel gmail.com> writes:
On Friday, 29 July 2022 at 09:29:47 UTC, Kirill wrote:
 ```
 Built with COMPILER_NAME COMPILER_VERSION
 ```
Something like this: ```D 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".
Jul 29 2022
parent Iain Buclaw <ibuclaw gdcproject.org> writes:
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: ```D 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
Jul 29 2022