summaryrefslogtreecommitdiffstats
path: root/build.rs
blob: 9da3e2dd63e9ab3afa03a7a36de4c2a369d4dc5b (plain)
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
#![deny(clippy::all, clippy::cargo, clippy::nursery, clippy::pedantic)]
#![allow(clippy::cargo_common_metadata, clippy::wildcard_dependencies)]

use std::{
  error::Error,
  process::{Command, Stdio},
};

fn uuid() -> Result<String, Box<dyn Error>> {
  #[cfg(target_family = "windows")]
  let py = "python.exe";
  #[cfg(target_family = "unix")]
  let py = "python3";
  let proc = Command::new(py)
    .arg("-c")
    .arg("import uuid; print(uuid.uuid4())")
    .stdout(Stdio::piped())
    .output()?;
  assert!(proc.status.success());
  let uuid = String::from_utf8(proc.stdout)?.trim().into();
  Ok(uuid)
}

fn main() -> Result<(), Box<dyn Error>> {
  println!("cargo:rustc-env=SAD_ARGV_UUID={uuid}", uuid = uuid()?);

  println!("cargo:rustc-env=SAD_PREVIEW_UUID={uuid}", uuid = uuid()?);

  println!("cargo:rustc-env=SAD_PATCH_UUID={uuid}", uuid = uuid()?);

  Ok(())
}