digitalmars.D - How to get compiler name and version from D code?
- Kirill (6/6) Jul 29 2022 I'd like to get the compiler name and version from within the D
- rikki cattermole (2/2) Jul 29 2022 Special tokens: https://dlang.org/spec/lex.html#special-token-sequence
- Kirill (2/5) Jul 29 2022 Thank you!
- Dennis (12/15) Jul 29 2022 Something like this:
- Iain Buclaw (3/19) Jul 29 2022 Or just `import std.compiler;`
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
Special tokens: https://dlang.org/spec/lex.html#special-token-sequence You can also determine the compiler by a version.
Jul 29 2022
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
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
On Friday, 29 July 2022 at 09:57:43 UTC, Dennis wrote:On Friday, 29 July 2022 at 09:29:47 UTC, Kirill wrote:Or just `import std.compiler;` https://dlang.org/phobos/std_compiler.html``` 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