Skip to main content

Crate compile_time

Crate compile_time 

Source
Expand description

This crate provides macros for getting compile time information.

You can get the compile time either as time::Date, time::Time, time::OffsetDateTime, string, or UNIX timestamp.

You can get the Rust compiler version either as semver::Version or string, and the individual version parts as integer literals or strings, respectively.

You can run arbitrary command at compile time and get its output as bytes or string.

§Examples

Getting the compile time and Rust version:

const COMPILE_DATETIME: &str = compile_time::datetime_str!();
const RUSTC_VERSION: &str = compile_time::rustc_version_str!();

println!("Compiled using Rust {RUSTC_VERSION} on {COMPILE_DATETIME}.");

Running an arbitrary command at compile time:

const MAGIC_NUMBER: &str = compile_time::command_str!("echo", "42");

assert_eq!(MAGIC_NUMBER, "42\n");

Macros§

command_bytes
Runs the given command and returns its standard output as a &'static [u8].
command_str
Runs the given command and returns its standard output as a &'static str.
date
Returns the compile date as time::Date.
date_str
Returns the compile date as &'static str in yyyy-MM-dd format.
datetime
Returns the compile date and time as time::OffsetDateTime.
datetime_str
Returns the compile date and time as &'static str in yyyy-MM-ddThh:mm:ssZ format.
rustc_version
Returns the Rust compiler version as [semver::Version].
rustc_version_build
Returns the Rust compiler build version as a &'static str.
rustc_version_major
Returns the Rust compiler major version as integer literal.
rustc_version_minor
Returns the Rust compiler minor version as integer literal.
rustc_version_patch
Returns the Rust compiler patch version as integer literal.
rustc_version_pre
Returns the Rust compiler pre version as &'static str.
rustc_version_str
Returns the Rust compiler version as &'static str.
time
Returns the compile time as time::Time.
time_str
Returns the compile time as &'static str in hh:mm:ss format.
unix
Returns the compile date and time as UNIX timestamp in seconds.

Constants§

HOST
The host platform triple.
TARGET
The target platform triple.