-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
34 lines (28 loc) · 1.22 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
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=src/s0_lexer/lexer.rs");
println!("cargo:rerun-if-changed=src/s1_parser/modelica.lalrpop");
println!("cargo:rerun-if-changed=src/s1_parser/ast.rs");
lalrpop::process_root().unwrap();
// Attempt to retrieve the current Git version
let output = Command::new("git")
.args(["describe", "--dirty", "--tags", "--long"])
.output()
.expect("Failed to execute git command");
if output.status.success() {
// Convert the hash to a String and trim it
let git_ver = String::from_utf8_lossy(&output.stdout).trim().to_string();
// Pass the Git hash to your Rust code via an environment variable
println!("cargo:rustc-env=GIT_VER={}", git_ver);
// Optionally, display a warning during the build with the hash
println!("cargo:warning=Using Git version: {}", git_ver);
} else {
eprintln!(
"Failed to retrieve Git version: {}",
String::from_utf8_lossy(&output.stderr)
);
}
// Rerun this build script if `.git/HEAD` or its references change
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs/");
}