MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / main

Function main

nodedb/build.rs:6–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4use std::time::{SystemTime, UNIX_EPOCH};
5
6fn main() {
7 // Invalidate when the current commit changes.
8 println!("cargo:rerun-if-changed=.git/HEAD");
9
10 // --- git commit ---
11 let git_commit = Command::new("git")
12 .args(["rev-parse", "--short", "HEAD"])
13 .output()
14 .ok()
15 .and_then(|o| {
16 if o.status.success() {
17 String::from_utf8(o.stdout).ok()
18 } else {
19 None
20 }
21 })
22 .map(|s| s.trim().to_owned())
23 .filter(|s| !s.is_empty())
24 .unwrap_or_else(|| "unknown".to_owned());
25
26 println!("cargo:rustc-env=NODEDB_GIT_COMMIT={git_commit}");
27
28 // --- build date ---
29 let secs = SystemTime::now()
30 .duration_since(UNIX_EPOCH)
31 .expect("system clock is before Unix epoch")
32 .as_secs();
33
34 let date = civil_from_days(secs / 86400);
35 println!("cargo:rustc-env=NODEDB_BUILD_DATE={date}");
36
37 // --- build profile ---
38 let profile = std::env::var("PROFILE").unwrap_or_else(|_| "unknown".to_owned());
39 println!("cargo:rustc-env=NODEDB_BUILD_PROFILE={profile}");
40
41 // --- rust version ---
42 let rust_version = Command::new("rustc")
43 .arg("--version")
44 .output()
45 .ok()
46 .and_then(|o| {
47 if o.status.success() {
48 String::from_utf8(o.stdout).ok()
49 } else {
50 None
51 }
52 })
53 .map(|s| s.trim().to_owned())
54 .filter(|s| !s.is_empty())
55 .unwrap_or_else(|| "unknown".to_owned());
56
57 println!("cargo:rustc-env=NODEDB_RUST_VERSION={rust_version}");
58}
59
60/// Howard Hinnant's civil_from_days algorithm.
61/// Converts a day count since the Unix epoch (1970-01-01) to a `YYYY-MM-DD` string.

Callers

nothing calls this directly

Calls 8

nowFunction · 0.85
civil_from_daysFunction · 0.85
successMethod · 0.80
duration_sinceMethod · 0.80
argMethod · 0.80
okMethod · 0.45
is_emptyMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected