# Get Rust compiler version at compilation time

**URL:** <https://users.rust-lang.org/t/get-rust-compiler-version-at-compilation-time/140469>\
**Category:** help\
**Created:** [June 4, 2026, 7:36pm UTC](https://users.rust-lang.org/t/get-rust-compiler-version-at-compilation-time/140469 "2026-06-04T19:36:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [June 4, 2026, 7:36pm UTC](https://users.rust-lang.org/t/get-rust-compiler-version-at-compilation-time/140469/1 "2026-06-04T19:36:49Z")

</div>

There is a thread regarding rustc\_version at the board. I also found another crate, as rustversion on [crates.io](http://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](http://crates.io), or just run `rustc -V>ver_info.txt` and then insert the version using `include`.

---

<div class="post-metadata">

**Author:** ![epage](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/epage/32/5550_2.png) [@epage](https://users.rust-lang.org/u/epage)\
**Post date:** [June 5, 2026, 12:52am UTC](https://users.rust-lang.org/t/get-rust-compiler-version-at-compilation-time/140469/2 "2026-06-05T00:52:50Z")

</div>

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 `cfg`s 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.

---

<div class="post-metadata">

**Author:** ![MusicalNinjaDad](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/musicalninjadad/32/41229_2.png) [@MusicalNinjaDad](https://users.rust-lang.org/u/MusicalNinjaDad)\
**Post date:** [June 5, 2026, 3:35pm UTC](https://users.rust-lang.org/t/get-rust-compiler-version-at-compilation-time/140469/3 "2026-06-05T15:35:05Z")

</div>

I think cuviper has this as part of [AutoCfg](https://docs.rs/autocfg/1.5.1/autocfg/struct.AutoCfg.html#method.probe_rustc_version) 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 😉]

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [June 5, 2026, 8:12pm UTC](https://users.rust-lang.org/t/get-rust-compiler-version-at-compilation-time/140469/4 "2026-06-05T20:12:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [September 3, 2026, 8:12pm UTC](https://users.rust-lang.org/t/get-rust-compiler-version-at-compilation-time/140469/5 "2026-09-03T20:12:31Z")

</div>

Closed on September 3, 2026, 8:12pm UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
