4 [![Documentation](https://docs.rs/rustc_version/badge.svg)](https://docs.rs/rustc_version/)
5 [![Crates.io](https://img.shields.io/crates/v/rustc_version.svg)](https://crates.io/crates/rustc_version)
6 [![Build status](https://github.com/Kimundi/rustc-version-rs/workflows/CI/badge.svg)](https://github.com/Kimundi/rustc-version-rs/actions?query=workflow%3ACI)
8 A library for querying the version of a `rustc` compiler.
10 This can be used by build scripts or other tools dealing with Rust sources
11 to make decisions based on the version of the compiler. Current MSRV is 1.32.0.
13 If this is of interest, also consider looking at these other crates:
15 * [autocfg](https://crates.io/crates/autocfg/), which helps with feature detection instead of depending on compiler versions
16 * [rustversion](https://github.com/dtolnay/rustversion) provides a procedural macro with no other dependencies
20 [rustc-version-rs is available on crates.io](https://crates.io/crates/rustc_version).
21 It is recommended to look there for the newest released version, as well as links to the newest builds of the docs.
23 At the point of the last update of this README, the latest published version could be used like this:
25 Add the following dependency to your Cargo manifest...
32 ... and see the [docs](https://docs.rs/rustc_version) for how to use it.
37 // This could be a cargo build script
39 use rustc_version::{version, version_meta, Channel, Version};
42 // Assert we haven't travelled back in time
43 assert!(version().unwrap().major >= 1);
45 // Set cfg flags depending on release channel
46 match version_meta().unwrap().channel {
48 println!("cargo:rustc-cfg=RUSTC_IS_STABLE");
51 println!("cargo:rustc-cfg=RUSTC_IS_BETA");
54 println!("cargo:rustc-cfg=RUSTC_IS_NIGHTLY");
57 println!("cargo:rustc-cfg=RUSTC_IS_DEV");
61 // Check for a minimum version
62 if version().unwrap() >= Version::parse("1.4.0").unwrap() {
63 println!("cargo:rustc-cfg=compiler_has_important_bugfix");
70 Licensed under either of
72 * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
73 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
79 Unless you explicitly state otherwise, any contribution intentionally submitted
80 for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
81 additional terms or conditions.