rustversion_detect/
lib.rs

1//! This crate provides a simple API for detecting the rustc
2//! compiler version.
3//!
4//! It is primarily intended for build scripts, but is also usable at runtime.
5//!
6//! The implementation is forked from the [`rustversion` crate], but with proc-macro code removed.
7//!
8//! [`rustversion` crate]: https://github.com/dtolnay/rustversion
9//!
10//! # Dependency
11//! Add the following to your build script:
12//! ```toml
13//! [build-dependencies]
14//! rustversion-detect = "0.1"
15//! ```
16#![cfg_attr(not(test), no_std)]
17#![deny(missing_docs)]
18
19#[macro_use]
20mod macros;
21pub mod date;
22pub mod version;
23
24pub use crate::date::Date;
25pub use crate::version::{Channel, RustVersion, StableVersionSpec};
26
27/// The detected rust compiler version.
28pub const RUST_VERSION: RustVersion = self::detected::DETECTED_VERSION;
29
30/// Version detected by build script.
31#[allow(unused_imports)]
32mod detected {
33    use crate::date::Date;
34    use crate::version::Channel::*;
35    use crate::version::RustVersion as Version;
36
37    #[cfg(not(host_os = "windows"))]
38    pub const DETECTED_VERSION: Version = include!(concat!(env!("OUT_DIR"), "/version.expr"));
39
40    #[cfg(host_os = "windows")]
41    pub const DETECTED_VERSION: Version = include!(concat!(env!("OUT_DIR"), "\\version.expr"));
42}