initial commit

This commit is contained in:
2023-02-26 17:59:35 +03:00
parent 85ce59c478
commit 24185f677e
15 changed files with 634 additions and 0 deletions

41
alterego/build.rs Normal file
View File

@ -0,0 +1,41 @@
use std::env;
fn main() {
let rev = get_value_from_env("GIT_VERSION")
.or_else(|| get_value_from_command("git", &["rev-parse", "--short", "HEAD"]))
.unwrap_or_else(|| "unknown".to_owned());
let branch = get_value_from_env("GIT_BRANCH")
.or_else(|| get_value_from_command("git", &["rev-parse", "--abbrev-ref", "HEAD"]))
.unwrap_or_else(|| "unknown".to_owned());
println!("cargo:rustc-env=GIT_REVISION={}", rev);
println!("cargo:rustc-env=GIT_BRANCH={}", branch);
println!("cargo:rerun-if-env-changed=GIT_REVISION");
}
fn get_value_from_env(key: &str) -> Option<String> {
env::var(key).map_or_else(|_| None, Some)
}
fn get_value_from_command<I: IntoIterator<Item = S>, S: AsRef<std::ffi::OsStr>>(
cmd: &str,
args: I,
) -> Option<String> {
std::process::Command::new(cmd)
.args(args)
.output()
.map_or_else(
|_| None,
|out| {
if !out.status.success() {
return None;
}
match std::str::from_utf8(&out.stdout) {
Ok(value) => Some(value.to_owned()),
Err(_) => None,
}
},
)
}