Skip to content

Commit 3019260

Browse files
committed
fix: Use version number from Cargo.toml for release versions
1 parent 9dc2b0c commit 3019260

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

build.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@ include!("src/utils/cli.rs");
1414
include!("src/utils/denylist_default.rs");
1515

1616
fn get_git_version() {
17-
let output = Command::new("git")
17+
let version = Command::new("git")
1818
.args(["describe", "--tags", "--always", "--dirty"])
1919
.output()
20-
.expect("Failed to execute git");
21-
22-
let git_version = String::from_utf8(output.stdout).expect("Cannot get git version");
23-
println!("cargo:rustc-env=GIT_VERSION={}", git_version.trim());
24-
20+
.ok()
21+
.filter(|o| o.status.success())
22+
.and_then(|o| String::from_utf8(o.stdout).ok())
23+
.map(|s| s.trim().to_owned())
24+
.filter(|s| !s.is_empty())
25+
.unwrap_or_else(|| {
26+
format!(
27+
"v{}",
28+
std::env::var("CARGO_PKG_VERSION").unwrap_or_default()
29+
)
30+
});
31+
32+
println!("cargo:rustc-env=GIT_VERSION={version}");
2533
println!("cargo:rerun-if-changed=.git/HEAD");
2634
println!("cargo:rerun-if-changed=.git/refs/");
2735
}

0 commit comments

Comments
 (0)