-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathbuild.rs
37 lines (32 loc) · 1.33 KB
/
build.rs
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
27
28
29
30
31
32
33
34
35
36
37
use std::process::Command;
fn main() {
let version = match std::env::var("WLUMA_VERSION") {
Ok(v) => v,
Err(_) => {
let version = "$Format:%(describe)$"; // Replaced by git-archive.
let version = if version.starts_with('$') {
match Command::new("git").args(["describe", "--tags"]).output() {
Ok(o) if o.status.success() => {
String::from_utf8_lossy(&o.stdout).trim().to_string()
}
Ok(o) => panic!("git-describe exited non-zero: {}", o.status),
Err(err) => panic!("failed to execute git-describe: {err}"),
}
} else {
version.to_string()
};
let version = version.strip_prefix('v').unwrap_or(&version);
println!("cargo:rustc-env=WLUMA_VERSION={version}");
version.to_string()
}
};
let parts = version
.split(|c: char| !c.is_ascii_digit())
.collect::<Vec<_>>();
if parts.len() < 3 {
panic!("Unable to parse 'major.minor.patch' from version: {version}");
}
println!("cargo:rustc-env=WLUMA_VERSION_MAJOR={}", parts[0]);
println!("cargo:rustc-env=WLUMA_VERSION_MINOR={}", parts[1]);
println!("cargo:rustc-env=WLUMA_VERSION_PATCH={}", parts[2]);
}