version_check
This tiny crate checks that the running or installed rustc
meets some version
requirements. The version is queried by calling the Rust compiler with
--version
. The path to the compiler is determined first via the RUSTC
environment variable. If it is not set, then rustc
is used. If that fails, no
determination is made, and calls return None
.
Usage
Add to your Cargo.toml
file, typically as a build dependency:
[]
= "0.9"
version_check
is compatible and compiles with Rust 1.0.0 and beyond.
Examples
Set a cfg
flag in build.rs
if the running compiler was determined to be
at least version 1.13.0
:
extern crate version_check as rustc;
if is_min_version.unwrap_or
Check that the running compiler was released on or after 2018-12-18
:
extern crate version_check as rustc;
match is_min_date ;
Check that the running compiler supports feature flags:
extern crate version_check as rustc;
match is_feature_flaggable ;
See the rustdocs for more examples and complete documentation.
Alternatives
This crate is dead simple with no dependencies. If you need something more and
don't care about panicking if the version cannot be obtained, or if you don't
mind adding dependencies, see rustc_version. If you'd instead prefer a feature
detection library that works by dynamically invoking rustc
with a
representative code sample, see autocfg.
License
version_check
is licensed under either of the following, at your option:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)