Crate rustc_version [] [src]

Simple library for getting the version information of a rustc compiler.

This calls $RUSTC --version and parses the output, falling back to rustc if $RUSTC is not set.

Example

// This could be a cargo build script

extern crate rustc_version;
use rustc_version::{version, version_matches, version_meta, Channel};

fn main() {
    // Assert we haven't travelled back in time
    assert!(version().major >= 1);

    // Set cfg flags depending on release channel
    match version_meta().channel {
        Channel::Stable => {
            println!("cargo:rustc-cfg=RUSTC_IS_STABLE");
        }
        Channel::Beta => {
            println!("cargo:rustc-cfg=RUSTC_IS_BETA");
        }
        Channel::Nightly => {
            println!("cargo:rustc-cfg=RUSTC_IS_NIGHTLY");
        }
        Channel::Dev => {
            println!("cargo:rustc-cfg=RUSTC_IS_DEV");
        }
    }

    // Directly check a semver version requirment
    if version_matches(">= 1.4.0") {
        println!("cargo:rustc-cfg=compiler_has_important_bugfix");
    }
}

Structs

VersionMeta

Rustc version plus metada like git short hash and build date.

Enums

Channel

Release channel of the compiler.

Functions

version

Returns the rustc SemVer version.

version_matches

Check wether the rustc version matches the given SemVer version requirement.

version_meta

Returns the rustc SemVer version and additional metadata like the git short hash and build date.