-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
43 lines (36 loc) · 1.04 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
38
39
40
41
42
43
// build.rs
fn report_build_profile() {
println!(
"cargo:rustc-env=BUILD_PROFILE={}",
std::env::var("PROFILE").unwrap()
);
}
fn report_enabled_features() {
let mut enabled_features: Vec<&str> = Vec::new();
if enabled_features.is_empty() {
enabled_features.push("none");
}
println!(
"cargo:rustc-env=BUILD_FEATURES={}",
enabled_features.join(",")
);
}
fn report_repository_version() {
let version = match std::env::var("CI_BUILD_REF") {
Ok(val) if !val.is_empty() => val,
_ => {
let git_describe = std::process::Command::new("git")
.args(["describe", "--always", "--dirty", "--long", "--tags"])
.output()
.unwrap();
String::from_utf8(git_describe.stdout).unwrap()
}
};
println!("cargo:rustc-env=REPO_VERSION={}", version);
}
fn main() {
println!("cargo:rerun-if-changed=build.rs");
report_build_profile();
report_enabled_features();
report_repository_version();
}