16acc7838Sopenharmony_ci# version\_check
26acc7838Sopenharmony_ci
36acc7838Sopenharmony_ci[![Build Status](https://github.com/SergioBenitez/version_check/workflows/CI/badge.svg)](https://github.com/SergioBenitez/version_check/actions)
46acc7838Sopenharmony_ci[![Current Crates.io Version](https://img.shields.io/crates/v/version_check.svg)](https://crates.io/crates/version_check)
56acc7838Sopenharmony_ci[![rustdocs on docs.rs](https://docs.rs/version_check/badge.svg)](https://docs.rs/version_check)
66acc7838Sopenharmony_ci
76acc7838Sopenharmony_ciThis tiny crate checks that the running or installed `rustc` meets some version
86acc7838Sopenharmony_cirequirements. The version is queried by calling the Rust compiler with
96acc7838Sopenharmony_ci`--version`. The path to the compiler is determined first via the `RUSTC`
106acc7838Sopenharmony_cienvironment variable. If it is not set, then `rustc` is used. If that fails, no
116acc7838Sopenharmony_cidetermination is made, and calls return `None`.
126acc7838Sopenharmony_ci
136acc7838Sopenharmony_ci## Usage
146acc7838Sopenharmony_ci
156acc7838Sopenharmony_ciAdd to your `Cargo.toml` file, typically as a build dependency:
166acc7838Sopenharmony_ci
176acc7838Sopenharmony_ci```toml
186acc7838Sopenharmony_ci[build-dependencies]
196acc7838Sopenharmony_civersion_check = "0.9"
206acc7838Sopenharmony_ci```
216acc7838Sopenharmony_ci
226acc7838Sopenharmony_ci`version_check` is compatible and compiles with Rust 1.0.0 and beyond.
236acc7838Sopenharmony_ci
246acc7838Sopenharmony_ci## Examples
256acc7838Sopenharmony_ci
266acc7838Sopenharmony_ciSet a `cfg` flag in `build.rs` if the running compiler was determined to be
276acc7838Sopenharmony_ciat least version `1.13.0`:
286acc7838Sopenharmony_ci
296acc7838Sopenharmony_ci```rust
306acc7838Sopenharmony_ciextern crate version_check as rustc;
316acc7838Sopenharmony_ci
326acc7838Sopenharmony_ciif rustc::is_min_version("1.13.0").unwrap_or(false) {
336acc7838Sopenharmony_ci    println!("cargo:rustc-cfg=question_mark_operator");
346acc7838Sopenharmony_ci}
356acc7838Sopenharmony_ci```
366acc7838Sopenharmony_ci
376acc7838Sopenharmony_ciCheck that the running compiler was released on or after `2018-12-18`:
386acc7838Sopenharmony_ci
396acc7838Sopenharmony_ci```rust
406acc7838Sopenharmony_ciextern crate version_check as rustc;
416acc7838Sopenharmony_ci
426acc7838Sopenharmony_cimatch rustc::is_min_date("2018-12-18") {
436acc7838Sopenharmony_ci    Some(true) => "Yep! It's recent!",
446acc7838Sopenharmony_ci    Some(false) => "No, it's older.",
456acc7838Sopenharmony_ci    None => "Couldn't determine the rustc version."
466acc7838Sopenharmony_ci};
476acc7838Sopenharmony_ci```
486acc7838Sopenharmony_ci
496acc7838Sopenharmony_ciCheck that the running compiler supports feature flags:
506acc7838Sopenharmony_ci
516acc7838Sopenharmony_ci```rust
526acc7838Sopenharmony_ciextern crate version_check as rustc;
536acc7838Sopenharmony_ci
546acc7838Sopenharmony_cimatch rustc::is_feature_flaggable() {
556acc7838Sopenharmony_ci    Some(true) => "Yes! It's a dev or nightly release!",
566acc7838Sopenharmony_ci    Some(false) => "No, it's stable or beta.",
576acc7838Sopenharmony_ci    None => "Couldn't determine the rustc version."
586acc7838Sopenharmony_ci};
596acc7838Sopenharmony_ci```
606acc7838Sopenharmony_ci
616acc7838Sopenharmony_ciSee the [rustdocs](https://docs.rs/version_check) for more examples and complete
626acc7838Sopenharmony_cidocumentation.
636acc7838Sopenharmony_ci
646acc7838Sopenharmony_ci## Alternatives
656acc7838Sopenharmony_ci
666acc7838Sopenharmony_ciThis crate is dead simple with no dependencies. If you need something more and
676acc7838Sopenharmony_cidon't care about panicking if the version cannot be obtained, or if you don't
686acc7838Sopenharmony_cimind adding dependencies, see [rustc_version]. If you'd instead prefer a feature
696acc7838Sopenharmony_cidetection library that works by dynamically invoking `rustc` with a
706acc7838Sopenharmony_cirepresentative code sample, see [autocfg].
716acc7838Sopenharmony_ci
726acc7838Sopenharmony_ci[rustc_version]: https://crates.io/crates/rustc_version
736acc7838Sopenharmony_ci[autocfg]: https://crates.io/crates/autocfg
746acc7838Sopenharmony_ci
756acc7838Sopenharmony_ci## License
766acc7838Sopenharmony_ci
776acc7838Sopenharmony_ci`version_check` is licensed under either of the following, at your option:
786acc7838Sopenharmony_ci
796acc7838Sopenharmony_ci * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
806acc7838Sopenharmony_ci * MIT License ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
81