-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.rs
More file actions
39 lines (35 loc) · 1022 Bytes
/
build.rs
File metadata and controls
39 lines (35 loc) · 1022 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
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: Apache-2.0 OR MIT
use std::process::Command;
fn run_git(args: &[&str]) -> String {
// It's simpler to rely on the git command instead of a crate for just this
// use case.
Command::new("git")
.args(args)
.output()
.ok()
.filter(|output| output.status.success())
.map(|output| {
String::from_utf8_lossy(&output.stdout)
.chars()
.filter(|c| c.is_alphanumeric() || *c == '-')
.collect()
})
.unwrap_or_else(|| "unknown".to_string())
}
fn main() {
println!(
"cargo:rustc-env=GIT_COMMIT={}",
run_git(&[
"describe",
"--always",
// Do not rely on local configuration (i.e. core.abbrev) for length.
"--abbrev=12",
"--exclude=*",
"--dirty",
])
);
println!(
"cargo:rustc-env=GIT_DATE={}",
run_git(&["log", "--max-count=1", "--format=%cs"])
);
}