summaryrefslogtreecommitdiffstats
path: root/build.rs
blob: 27e016414071ef24ae49489c606340e050c3ac5a (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
33
34
#!/usr/bin/env -S -- bash -Eeuo pipefail
// || rustc --edition=2021 -o "${T:="$(mktemp)"}" -- "$0" && exec -a "$0" -- "$T" "$0" "$@"
#![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(())
}