-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
53 lines (46 loc) · 1.54 KB
/
build.rs
File metadata and controls
53 lines (46 loc) · 1.54 KB
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
44
45
46
47
48
49
50
51
52
53
use std::process::Command;
fn main() {
println!("cargo:rustc-link-arg-bins=--nmagic");
// println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tlink-ram.x");
git();
}
fn git() {
let rev = Command::new("git")
.args([
"-c",
"core.abbrev=8",
"rev-parse",
"--verify",
"--short",
"HEAD",
])
.output()
.unwrap();
let rev = String::from_utf8(rev.stdout).unwrap();
let rev = rev.trim();
assert_eq!(rev.len(), 8);
// Determine local directory changes
let modified = Command::new("git")
.args(["ls-files", "--modified"])
.output()
.unwrap();
let modified = String::from_utf8(modified.stdout).unwrap();
let modified = modified.trim();
let dirty = if modified.is_empty() { "" } else { "-dirty" };
println!("cargo::rustc-env=GIT_REV={rev}{dirty}");
// Find git directory
let path_res = Command::new("git")
.args(["rev-parse", "--path-format=relative", "--git-dir"])
.output()
.map(|o| String::from_utf8(o.stdout).unwrap().trim().to_string());
if let Ok(path) = path_res {
println!("cargo:rerun-if-changed={path}/HEAD");
}
// Workaround for
// https://github.com/rust-lang/cargo/issues/4587
// since setting any rerun-if-changed clears the default set.
println!("cargo::rerun-if-changed=src");
println!("cargo::rerun-if-changed=Cargo.lock");
println!("cargo::rerun-if-changed=Cargo.toml");
}