Get Rust compiler version at compilation time

There is a thread regarding rustc_version at the board. I also found another crate, as rustversion on crates.io. However, after looking in the code of the solutions, I concluded that there is no built-in constant like std::env::consts::CompilerVer for the purpose. Is it true, or I missed other constants block?

PS AI response was similar, either use crates.io, or just run rustc -V>ver_info.txt and then insert the version using include.

There is not. From my understanding, it is also unlikely that the compiler version will be available as the language wouldn't be providing implementation information.

There are proposals for built-in language version cfg expressions, maybe even a cfg value. A cfg value could be read by a build script but there is also an idea floating around about a cfg_value macro for const access to a cfgs value.

What is different between a language and compiler version? They are thinking of including the patch value but not whether it is nightly or not. It is unspecified how to treat nightly but likely it will be that they are the previous version and not next.

I think cuviper has this as part of AutoCfg looking through the code made me smile at how he managed it. Although the public API only exposes a way to check "at least x.y" and not "tell me the version".

[EDIT: Looking at the who the author of rustversion is, I'd implicitly trust that as well :wink: ]

Strange, rustc is very conscious on the subject which version of rustc used to generate rlib. However, it is hidden in rustc itself. Anyway, not a big deal for now.