use std::env::var;
use std::path::Path;
use std::process::Command;
fn main() {
let manifest_dir = var("CARGO_MANIFEST_DIR").unwrap();
let nobody_crt: String = format!("{}/.resources/tls/users-nobody.pem", manifest_dir);
let nobody_key: String = format!("{}/.resources/tls/users-nobody-key.pem", manifest_dir);
let output = Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
let vars = match (var("GL_CUSTOM_NOBODY_KEY"), var("GL_CUSTOM_NOBODY_CERT")) {
(Ok(a), Ok(b)) => (a, b),
(Err(_), Err(_)) => {
println!("cargo:warning=Using default NOBODY cert.");
println!("cargo:warning=Set \"GL_CUSTOM_NOBODY_KEY\" and \"GL_CUSTOM_NOBODY_CERT\" to use a custom cert.");
(nobody_key.to_owned(), nobody_crt.to_owned())
}
(Ok(_), Err(_)) => {
println!("Missing GL_CUSTOM_NOBODY_CERT, since you are using GL_CUSTOM_NOBODY_KEY");
std::process::exit(1);
}
(Err(_), Ok(_)) => {
println!("Missing GL_CUSTOM_NOBODY_KEY, since you are using GL_CUSTOM_NOBODY_CERT");
std::process::exit(1);
}
};
println!("cargo:rustc-env=GL_NOBODY_KEY={}", vars.0);
println!("cargo:rustc-env=GL_NOBODY_CRT={}", vars.1);
let key_path = Path::new(&vars.0);
let cert_path = Path::new(&vars.1);
match (key_path.exists(), cert_path.exists()) {
(true, true) => (),
(_, _) => {
println!(
"Could not find cert and key files: {:?}, {:?}",
key_path, cert_path
);
std::process::exit(1);
}
}
println!("cargo:rerun-if-env-changed=GL_CUSTOM_NOBODY_CERT");
println!("cargo:rerun-if-env-changed=GL_CUSTOM_NOBODY_KEY");
let builder = tonic_build::configure();
builder
.type_attribute(".", "#[derive(serde::Serialize,serde::Deserialize)]")
.protoc_arg("--experimental_allow_proto3_optional")
.compile(
&[
".resources/proto/glclient/greenlight.proto",
".resources/proto/glclient/scheduler.proto",
".resources/proto/node.proto",
],
&[".resources/proto"],
)
.unwrap();
}