build_info/lib.rs
1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3#![cfg_attr(not(feature = "runtime"), no_std)]
4
5#[cfg(feature = "runtime")]
6pub use build_info_common::{
7 BuildInfo, CompilerChannel, CompilerInfo, CpuInfo, CrateInfo, Endianness, GitInfo, OptimizationLevel, TargetInfo,
8 VersionControl, chrono, semver,
9};
10/// This crate defines macro_rules that pass `$crate` (i.e., this crate) to the proc-macros doing the actual work
11/// The proc-macro crate that contains said proc-macros is reexported here, to be found in the macro_rules.
12#[doc(hidden)]
13pub use build_info_proc as proc;
14
15/**
16Generates a function that returns a reference to the `BuildInfo` structure for the crate.
17
18Usage: `build_info!(fn build_info_function);`
19*/
20#[cfg(feature = "runtime")]
21#[macro_export]
22macro_rules! build_info {
23 ($($tokens:tt)*) => { $crate::proc::build_info!{$crate $($tokens)*} };
24}
25
26/// Used by the function generated by `build_info!` to deserialize the build information
27#[cfg(feature = "runtime")]
28#[doc(hidden)]
29pub use bincode;
30/**
31Generates a string at compile-time that includes build information.
32
33This function-like macro takes a single string-literal as its argument, on which it performs string interpolation with
34the current build information. To do so, you can use a subset of the normal format language, with the special
35"variable" `$` that denotes the `BuildInfo` object. For example, `build_info::format!("Built at {}", $.timestamp)`
36might return "Built at 2020-05-28 20:09:40Z".`
37
38You can use `?` to unwrap `Option`s and some additional types can be formatted this way (e.g., `Vec<T>`).
39
40Literal curly braces can be printed by doubling them up: `build_info::format!("{{}}") // yields "{}"`.
41*/
42pub use build_info_proc::format;