-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
56 lines (48 loc) · 1.86 KB
/
Copy pathbuild.rs
File metadata and controls
56 lines (48 loc) · 1.86 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
54
55
56
use std::process::Command;
use jiff::{Unit, Zoned};
fn git_stdout(args: &[&str]) -> Option<String> {
let output = Command::new("git").args(args).output().ok()?;
if !output.status.success() {
return None;
}
let stdout = String::from_utf8(output.stdout).ok()?;
let trimmed = stdout.trim();
if trimmed.is_empty() {
None
} else {
Some(trimmed.to_owned())
}
}
fn main() {
pyo3_build_config::use_pyo3_cfgs();
println!("cargo:rerun-if-env-changed=RY_GIT_SHA");
println!("cargo:rerun-if-changed=python/ry/.git-sha");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs");
println!("cargo:rerun-if-changed=.git/packed-refs");
// OPT_LEVEL is available directly
let opt_level =
std::env::var("OPT_LEVEL").expect("OPT_LEVEL env var not found which is SUPER strange!");
println!("cargo:rustc-env=OPT_LEVEL={opt_level}");
// env var build profile
let profile =
std::env::var("PROFILE").expect("PROFILE env var not found which is SUPER strange!");
println!("cargo:rustc-env=PROFILE={profile}");
let build_ts = Zoned::now()
.round(Unit::Second)
.expect("oh no, build time error");
// build timestamp
println!("cargo:rustc-env=BUILD_TIMESTAMP={build_ts}");
// set the TARGET
let target = std::env::var("TARGET").expect("TARGET env var not found");
println!("cargo:rustc-env=TARGET={target}");
let git_sha = std::env::var("RY_GIT_SHA")
.ok()
.filter(|sha| !sha.trim().is_empty())
.or_else(|| std::fs::read_to_string("python/ry/.git-sha").ok())
.map(|sha| sha.trim().to_owned())
.filter(|sha| !sha.is_empty())
.or_else(|| git_stdout(&["rev-parse", "HEAD"]))
.unwrap_or_else(|| "unknown".to_owned());
println!("cargo:rustc-env=GIT_SHA={git_sha}");
}