1rustc-version-rs 2================ 3 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) 7 8A library for querying the version of a `rustc` compiler. 9 10This can be used by build scripts or other tools dealing with Rust sources 11to make decisions based on the version of the compiler. Current MSRV is 1.32.0. 12 13If this is of interest, also consider looking at these other crates: 14 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 17 18# Getting Started 19 20[rustc-version-rs is available on crates.io](https://crates.io/crates/rustc_version). 21It is recommended to look there for the newest released version, as well as links to the newest builds of the docs. 22 23At the point of the last update of this README, the latest published version could be used like this: 24 25Add the following dependency to your Cargo manifest... 26 27```toml 28[build-dependencies] 29rustc_version = "0.2" 30``` 31 32... and see the [docs](https://docs.rs/rustc_version) for how to use it. 33 34# Example 35 36```rust 37// This could be a cargo build script 38 39use rustc_version::{version, version_meta, Channel, Version}; 40 41fn main() { 42 // Assert we haven't travelled back in time 43 assert!(version().unwrap().major >= 1); 44 45 // Set cfg flags depending on release channel 46 match version_meta().unwrap().channel { 47 Channel::Stable => { 48 println!("cargo:rustc-cfg=RUSTC_IS_STABLE"); 49 } 50 Channel::Beta => { 51 println!("cargo:rustc-cfg=RUSTC_IS_BETA"); 52 } 53 Channel::Nightly => { 54 println!("cargo:rustc-cfg=RUSTC_IS_NIGHTLY"); 55 } 56 Channel::Dev => { 57 println!("cargo:rustc-cfg=RUSTC_IS_DEV"); 58 } 59 } 60 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"); 64 } 65} 66``` 67 68## License 69 70Licensed under either of 71 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) 74 75at your option. 76 77### Contribution 78 79Unless you explicitly state otherwise, any contribution intentionally submitted 80for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any 81additional terms or conditions. 82