-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathbuild.rs
More file actions
26 lines (21 loc) · 739 Bytes
/
build.rs
File metadata and controls
26 lines (21 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fn main() {
println!("cargo:rerun-if-env-changed=VITE_PLUS_VERSION");
let version = std::env::var("VITE_PLUS_VERSION")
.ok()
.filter(|v| !v.is_empty())
.or_else(version_from_git)
.unwrap_or_else(|| std::env::var("CARGO_PKG_VERSION").unwrap());
println!("cargo:rustc-env=VITE_PLUS_VERSION={version}");
}
fn version_from_git() -> Option<String> {
let output = std::process::Command::new("git")
.args(["describe", "--tags", "--match", "v*", "--abbrev=0"])
.output()
.ok()?;
if !output.status.success() {
return None;
}
let tag = String::from_utf8(output.stdout).ok()?;
let tag = tag.trim();
tag.strip_prefix('v').map(|s| s.to_owned())
}