1const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
2const PKG_NAME: &str = env!("CARGO_PKG_NAME");
3const PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
4const PKG_AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
5const PKG_HOMEPAGE: Option<&str> = option_env!("CARGO_PKG_HOMEPAGE");
6const PKG_REPOSITORY: Option<&str> = option_env!("CARGO_PKG_REPOSITORY");
7const PKG_LICENSE: Option<&str> = option_env!("CARGO_PKG_LICENSE");
8const BUILD_TARGET: Option<&str> = option_env!("RUN_BUILD_TARGET");
9const BUILD_PROFILE: Option<&str> = option_env!("RUN_BUILD_PROFILE");
10const BUILD_TIMESTAMP: Option<&str> = option_env!("RUN_BUILD_TIMESTAMP");
11const GIT_SHA: Option<&str> = option_env!("RUN_GIT_SHA");
12const GIT_DIRTY: Option<&str> = option_env!("RUN_GIT_DIRTY");
13const GIT_DATE: Option<&str> = option_env!("RUN_GIT_DATE");
14const RUSTC_VERSION: Option<&str> = option_env!("RUN_RUSTC_VERSION");
15
16pub fn describe() -> String {
17 let mut lines = Vec::new();
18 lines.push(format!("{PKG_NAME} {PKG_VERSION}"));
19 lines.push(PKG_DESCRIPTION.to_string());
20
21 let authors = PKG_AUTHORS
22 .split(':')
23 .filter(|part| !part.trim().is_empty())
24 .map(str::trim)
25 .collect::<Vec<_>>()
26 .join(", ");
27 if !authors.is_empty() {
28 lines.push(format!("author: {authors}"));
29 }
30
31 if let Some(homepage) = PKG_HOMEPAGE {
32 lines.push(format!("homepage: {homepage}"));
33 }
34 if let Some(repo) = PKG_REPOSITORY {
35 lines.push(format!("repository: {repo}"));
36 }
37 if let Some(license) = PKG_LICENSE {
38 lines.push(format!("license: {license}"));
39 }
40
41 lines.push(format!(
42 "commit: {} ({}, dirty: {})",
43 GIT_SHA.unwrap_or("unknown"),
44 GIT_DATE.unwrap_or("unknown date"),
45 GIT_DIRTY.unwrap_or("unknown"),
46 ));
47 lines.push(format!(
48 "built: {} [{} for {}]",
49 BUILD_TIMESTAMP.unwrap_or("unknown time"),
50 BUILD_PROFILE.unwrap_or("unknown profile"),
51 BUILD_TARGET.unwrap_or("unknown target"),
52 ));
53 lines.push(format!(
54 "rustc: {}",
55 RUSTC_VERSION.unwrap_or("unknown rustc")
56 ));
57 lines.join("\n")
58}