[][src]Crate rustc_version

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

This can be used by build scripts or other tools dealing with Rust sources to make decisions based on the version of the compiler.

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

Example

// This could be a cargo build script

use rustc_version::{version, version_meta, Channel, Version};

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

// Set cfg flags depending on release channel
match version_meta().unwrap().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");
    }
}

// Check for a minimum version
if version().unwrap() >= Version::parse("1.4.0").unwrap() {
    println!("cargo:rustc-cfg=compiler_has_important_bugfix");
}

Structs

LlvmVersion

LLVM version

Version

Represents a version number conforming to the semantic versioning scheme.

VersionMeta

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

Enums

Channel

Release channel of the compiler.

Error

The error type for this crate.

LlvmVersionParseError

LLVM Version Parse Error

Functions

version

Returns the rustc SemVer version.

version_meta

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

version_meta_for

Parses a "rustc -vV" output string and returns the SemVer version and additional metadata like the git short hash and build date.

Type Definitions

Result

The result type for this crate.