field_lib

Cross-platform Rust runtime for Radroots iOS and Android apps
git clone https://radroots.dev/git/field_lib.git
Log | Files | Refs | README | LICENSE

build.rs (1538B)


      1 use std::{
      2     env,
      3     process::Command,
      4     time::{SystemTime, UNIX_EPOCH},
      5 };
      6 
      7 fn main() {
      8     println!("cargo:rerun-if-changed=build.rs");
      9     println!("cargo:rerun-if-env-changed=RUSTC");
     10     println!("cargo:rerun-if-env-changed=PROFILE");
     11 
     12     let rustc = env::var("RUSTC").expect("missing required env var RUSTC");
     13     if let Ok(out) = Command::new(rustc).arg("--version").output() {
     14         if out.status.success() {
     15             if let Ok(ver) = String::from_utf8(out.stdout) {
     16                 println!("cargo:rustc-env=RUSTC_VERSION={}", ver.trim());
     17             }
     18         }
     19     }
     20 
     21     if let Ok(out) = Command::new("git")
     22         .args(["rev-parse", "--short=12", "HEAD"])
     23         .output()
     24     {
     25         if out.status.success() {
     26             let mut sha = String::from_utf8_lossy(&out.stdout).trim().to_string();
     27             let dirty = Command::new("git")
     28                 .args(["status", "--porcelain"])
     29                 .output()
     30                 .ok()
     31                 .map_or(false, |o| o.status.success() && !o.stdout.is_empty());
     32             if dirty {
     33                 sha.push_str("-dirty");
     34             }
     35             println!("cargo:rustc-env=GIT_HASH={sha}");
     36         }
     37     }
     38 
     39     let profile = env::var("PROFILE").expect("missing required env var PROFILE");
     40     println!("cargo:rustc-env=PROFILE={profile}");
     41 
     42     let epoch = SystemTime::now()
     43         .duration_since(UNIX_EPOCH)
     44         .map(|d| d.as_secs())
     45         .expect("system time before unix epoch");
     46     println!("cargo:rustc-env=BUILD_TIME_UNIX={epoch}");
     47 }