shadow_formatted_version/
lib.rs

1
2/// Generates a constant containing a preformatted version string.
3///
4/// Use this together with [shadow-rs](https://crates.io/crates/shadow-rs), by placing the following into your `main.rs` or `lib.rs`:
5/// ```text
6/// shadow_rs::shadow!(build);
7/// shadow_formatted_version::from_shadow!(build);
8/// ```
9/// The name "build" is of the module that shadow-rs generates. You can choose a different name, if you prefer.
10#[macro_export]
11macro_rules! from_shadow {
12    ($shadow_module:ident) => {
13        /// Detailed crate version information in a preformatted block.
14        ///
15        /// It looks like this, for example:
16        /// ```text
17        ///   Version:       0.1.0
18        ///   Target:        x86_64-unknown-linux-gnu
19        ///   Commit:        8f29a49b54ca3e94070d244511d8e4a64a69f083
20        ///   Commit-Date:   2023-12-31 23:59:59 +00:00
21        ///   Build-Date:    2024-12-31 23:59:59 +00:00
22        ///   Build-Clean:   No uncommitted changes in build.
23        ///   Rust-Version:  rustc 1.76.0 (07dca489a 2024-02-04)
24        /// ```
25        ///
26        /// See [shadow_formatted_version](https://crates.io/crates/shadow-formatted-version) for more information.
27        pub(crate) const FORMATTED_VERSION: &'static str =
28            shadow_rs::formatcp!(
29"
30  Version:       {crate_version}
31  Target:        {build_target}
32  Commit:        {commit}
33  Commit-Date:   {commit_date}
34  Build-Date:    {build_date}
35  Build-Clean:   {build_clean}
36  Rust-Version:  {rust_version}
37",
38            crate_version = $shadow_module::PKG_VERSION,
39            build_target = $shadow_module::BUILD_TARGET,
40            commit = $shadow_module::COMMIT_HASH,
41            commit_date = $shadow_module::COMMIT_DATE,
42            build_date = $shadow_module::BUILD_TIME,
43            build_clean = if $shadow_module::GIT_CLEAN {
44                "No uncommitted changes in build."
45            } else {
46                "Distribution was built with uncommitted changes! Commit does not reflect actual application code!"
47            },
48            rust_version = $shadow_module::RUST_VERSION,
49
50        );
51    }
52}