field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

build.rs (2056B)


      1 use std::{env, process::Command};
      2 
      3 #[path = "src/provenance.rs"]
      4 mod provenance;
      5 
      6 fn main() {
      7     println!("cargo:rerun-if-changed=build.rs");
      8     println!("cargo:rerun-if-env-changed=RUSTC");
      9     println!("cargo:rerun-if-env-changed=PROFILE");
     10     println!("cargo:rerun-if-env-changed=RADROOTS_LIB_REVISION");
     11     println!("cargo:rerun-if-env-changed=TERA_CONSUMER_REVISION");
     12     println!("cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH");
     13 
     14     let rustc = env::var("RUSTC").expect("missing required env var RUSTC");
     15     if let Ok(output) = Command::new(rustc).arg("--version").output()
     16         && output.status.success()
     17         && let Ok(version) = String::from_utf8(output.stdout)
     18     {
     19         println!("cargo:rustc-env=RUSTC_VERSION={}", version.trim());
     20     }
     21 
     22     let lib_revision = optional_full_revision("RADROOTS_LIB_REVISION");
     23     let consumer_revision = optional_full_revision("TERA_CONSUMER_REVISION");
     24     assert!(
     25         consumer_revision.is_none() || lib_revision.is_some(),
     26         "TERA_CONSUMER_REVISION requires RADROOTS_LIB_REVISION"
     27     );
     28     if let Some(revision) = lib_revision {
     29         println!("cargo:rustc-env=RADROOTS_LIB_REVISION={revision}");
     30     }
     31     if let Some(revision) = consumer_revision {
     32         println!("cargo:rustc-env=TERA_CONSUMER_REVISION={revision}");
     33     }
     34 
     35     let profile = env::var("PROFILE").expect("missing required env var PROFILE");
     36     println!("cargo:rustc-env=PROFILE={profile}");
     37 
     38     if let Some(epoch) = optional_source_date_epoch() {
     39         println!("cargo:rustc-env=BUILD_TIME_UNIX={epoch}");
     40     }
     41 }
     42 
     43 fn optional_full_revision(name: &str) -> Option<String> {
     44     let value = env::var(name).ok()?;
     45     assert!(
     46         provenance::is_full_revision(&value),
     47         "{name} must contain exactly 40 lowercase hexadecimal characters"
     48     );
     49     Some(value)
     50 }
     51 
     52 fn optional_source_date_epoch() -> Option<u64> {
     53     let value = env::var("SOURCE_DATE_EPOCH").ok()?;
     54     Some(
     55         value
     56             .parse()
     57             .expect("SOURCE_DATE_EPOCH must be an unsigned Unix timestamp"),
     58     )
     59 }