#metadata #format #block #utility

shadow-formatted-version

Version information in a preformatted block

2 releases (1 stable)

1.0.0 Feb 8, 2025
0.1.0 Dec 8, 2024

#579 in Debugging

Download history 209/week @ 2024-12-14 2/week @ 2024-12-28 50/week @ 2025-01-04 59/week @ 2025-01-11 20/week @ 2025-01-18 99/week @ 2025-01-25 198/week @ 2025-02-01 320/week @ 2025-02-08 38/week @ 2025-02-15 279/week @ 2025-02-22 105/week @ 2025-03-01 93/week @ 2025-03-08 63/week @ 2025-03-15 99/week @ 2025-03-22 77/week @ 2025-03-29

333 downloads per month

Apache-2.0

12KB

shadow-formatted-version

Convenience crate to provide detailed version information in a preformatted block:

  Version:       0.1.0
  Target:        x86_64-unknown-linux-gnu
  Commit:        8f29a49b54ca3e94070d244511d8e4a64a69f083
  Commit-Date:   2023-12-31 23:59:59 +00:00
  Build-Date:    2024-12-31 23:59:59 +00:00
  Build-Clean:   No uncommitted changes in build.
  Rust-Version:  rustc 1.76.0 (07dca489a 2024-02-04)

This version information can be logged at the start of a long-running service or
printed when passing --version to a CLI.

For example, when using clap, you can use it like so:

#[derive(Parser)]
#[command(about, version, long_version=crate::FORMATTED_VERSION)]
struct Args {
    // ...
}

Setup

This crate is based on shadow-rs, which we will setup as well.

  1. Add shadow-rs and shadow-formatted-version to your dependencies:
[dependencies]
shadow-rs = "0"
shadow-formatted-version = "1.0"

[build-dependencies]
shadow-rs = "0"
  1. Add the following code to your build.rs file:
fn main() {
    shadow_rs::ShadowBuilder::builder()
        .build().unwrap();
}

If you don't yet have a build.rs file, place it next to your Cargo.toml file:

.
├── build.rs
├── Cargo.toml
└── src
    └── ...
  1. Place these two lines in your main.rs or lib.rs, underneath your module definitions:
shadow_rs::shadow!(build)
formatted_version::from_shadow!(build);

Then you can retrieve the formatted version information with crate::FORMATTED_VERSION.
You can also retrieve additional constants from crate::build, as generated by shadow-rs.

Dependencies

~15MB
~323K SLoC