Files
AZKi/client/build.rs
2026-01-17 18:08:16 -05:00

38 lines
917 B
Rust

use dotenv::dotenv;
use std::env;
use std::fs::File;
use std::io::Write;
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_prost_build::configure()
.build_server(false)
.build_client(true)
.build_transport(false)
.compile_protos(
&["../AZKiServer/Protos/azki.proto", "../AZKiServer/Protos/types.proto"],
&["../AZKiServer"],
)?;
forward_env();
Ok(())
}
fn forward_env() {
let dest_path = "./src/env.rs";
let mut f = File::create(&dest_path).unwrap();
f.write_all(b"// This file is automatically generated by build.rs\n\n")
.unwrap();
dotenv().ok();
for (key, value) in env::vars() {
if key.starts_with("APP_") {
f.write_all("#[allow(dead_code)]\n".as_bytes()).unwrap();
let line = format!(
"pub const {}: &'static str = \"{}\";\n",
key,
value.replace("\"", "\\\"")
);
f.write_all(line.as_bytes()).unwrap();
}
}
}