2024-03-06 20:50:32 +03:00
|
|
|
fn main() -> Result<(), String> {
|
|
|
|
// Ensure that we rebuild if the version is specified.
|
|
|
|
println!("cargo:rerun-if-env-changed=RELEASE_VERSION");
|
|
|
|
|
|
|
|
// On release builds, use the Git commit as a backup if the version is not set.
|
|
|
|
// On debug builds, use "dev".
|
|
|
|
// If we fail to get the Git information, fail.
|
|
|
|
let build_profile = std::env::var("PROFILE").map_err(|err| err.to_string())?;
|
|
|
|
let release_version = if build_profile == "release" {
|
2024-05-31 16:01:10 +03:00
|
|
|
if let Some(version) = option_env!("RELEASE_VERSION") {
|
|
|
|
version.to_string()
|
|
|
|
} else {
|
|
|
|
let git_commit_ref = build_data::get_git_commit_short()?;
|
|
|
|
let git_dirty = build_data::get_git_dirty().unwrap_or(false);
|
|
|
|
if git_dirty {
|
|
|
|
format!("{git_commit_ref}-dirty")
|
|
|
|
} else {
|
|
|
|
git_commit_ref
|
2024-03-06 20:50:32 +03:00
|
|
|
}
|
|
|
|
}
|
2024-01-25 11:53:24 +03:00
|
|
|
} else {
|
2024-03-06 20:50:32 +03:00
|
|
|
"dev".to_string()
|
|
|
|
};
|
|
|
|
println!("cargo:rustc-env=CARGO_V3_ENGINE_VERSION={release_version}");
|
|
|
|
Ok(())
|
2024-01-09 10:13:02 +03:00
|
|
|
}
|