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 {
18 let mut lines = Vec::new();
19 lines.push(format!("{PKG_NAME} {PKG_VERSION}"));
20 lines.push(PKG_DESCRIPTION.to_string());
21
22 let authors = PKG_AUTHORS
23 .split(':')
24 .filter(|part| !part.trim().is_empty())
25 .map(str::trim)
26 .collect::<Vec<_>>()
27 .join(", ");
28 if !authors.is_empty() {
29 lines.push(format!("author: {authors}"));
30 }
31
32 if let Some(homepage) = PKG_HOMEPAGE {
33 lines.push(format!("homepage: {homepage}"));
34 }
35 if let Some(repo) = PKG_REPOSITORY {
36 lines.push(format!("repository: {repo}"));
37 }
38 if let Some(license) = PKG_LICENSE {
39 lines.push(format!("license: {license}"));
40 }
41
42 lines.push(format!(
43 "commit: {} ({}, dirty: {})",
44 GIT_SHA.unwrap_or("unknown"),
45 GIT_DATE.unwrap_or("unknown date"),
46 GIT_DIRTY.unwrap_or("unknown"),
47 ));
48 lines.push(format!(
49 "built: {} [{} for {}]",
50 BUILD_TIMESTAMP.unwrap_or("unknown time"),
51 BUILD_PROFILE.unwrap_or("unknown profile"),
52 BUILD_TARGET.unwrap_or("unknown target"),
53 ));
54 lines.push(format!(
55 "rustc: {}",
56 RUSTC_VERSION.unwrap_or("unknown rustc")
57 ));
58 lines.join("\n")
59}