12 releases

Uses old Rust 2015

0.9.5 Jul 25, 2024
0.9.4 Dec 29, 2021
0.9.3 Mar 16, 2021
0.9.2 May 24, 2020
0.1.0 Jan 15, 2017

#8 in Build Utils

Download history 2511615/week @ 2024-08-03 2587682/week @ 2024-08-10 2533618/week @ 2024-08-17 2589364/week @ 2024-08-24 2545586/week @ 2024-08-31 2601159/week @ 2024-09-07 2408202/week @ 2024-09-14 2767030/week @ 2024-09-21 2802331/week @ 2024-09-28 3311777/week @ 2024-10-05 3257336/week @ 2024-10-12 3287190/week @ 2024-10-19 2670490/week @ 2024-10-26 2677480/week @ 2024-11-02 2709102/week @ 2024-11-09 2381055/week @ 2024-11-16

10,885,170 downloads per month
Used in 45,407 crates (157 directly)

MIT/Apache

48KB
577 lines

version_check

Build Status Current Crates.io Version rustdocs on docs.rs

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:

[build-dependencies]
version_check = "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 rustc::is_min_version("1.13.0").unwrap_or(false) {
    println!("cargo:rustc-cfg=question_mark_operator");
}

Check that the running compiler was released on or after 2018-12-18:

extern crate version_check as rustc;

match rustc::is_min_date("2018-12-18") {
    Some(true) => "Yep! It's recent!",
    Some(false) => "No, it's older.",
    None => "Couldn't determine the rustc version."
};

Check that the running compiler supports feature flags:

extern crate version_check as rustc;

match rustc::is_feature_flaggable() {
    Some(true) => "Yes! It's a dev or nightly release!",
    Some(false) => "No, it's stable or beta.",
    None => "Couldn't determine the rustc version."
};

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:

No runtime deps