| 7 | use std::process::Command; |
| 8 | |
| 9 | fn main() { |
| 10 | let mut version = "v".to_owned() + env!("CARGO_PKG_VERSION"); |
| 11 | |
| 12 | if let Ok(git_out) = Command::new("git").args(["describe", "--dirty"]).output() |
| 13 | && git_out.status.success() |
| 14 | && let Ok(git_out_str) = String::from_utf8(git_out.stdout) |
| 15 | { |
| 16 | version = git_out_str; |
| 17 | // Pop the trailing newline. |
| 18 | version.pop(); |
| 19 | } |
| 20 | |
| 21 | // Append CH_EXTRA_VERSION to version if it is set. |
| 22 | if let Ok(extra_version) = env::var("CH_EXTRA_VERSION") { |
| 23 | println!("cargo:rerun-if-env-changed=CH_EXTRA_VERSION"); |
| 24 | version.push_str(&format!("-{extra_version}")); |
| 25 | } |
| 26 | |
| 27 | // This println!() has a special behavior, as it will set the environment |
| 28 | // variable BUILD_VERSION, so that it can be reused from the binary. |
| 29 | // Particularly, this is used from src/main.rs to display the exact |
| 30 | // version. |
| 31 | println!("cargo:rustc-env=BUILD_VERSION={version}"); |
| 32 | } |