main
rs 44 lines 1.37 KB
Raw
1 fn main() {
2 // Load .env for local builds. In CI these vars already come from the environment.
3 let _ = dotenvy::dotenv();
4
5 // These must be present or the build should fail.
6 for var in [
7 "ONDE_APP_ID",
8 "ONDE_APP_SECRET",
9 "GRESIQ_API_KEY",
10 "GRESIQ_API_SECRET",
11 ] {
12 println!("cargo:rerun-if-env-changed={var}");
13
14 match std::env::var(var) {
15 Ok(val) => {
16 println!("cargo:rustc-env={var}={val}");
17 }
18 Err(_) => {
19 eprintln!("error: required build variable `{var}` is not set.");
20 eprintln!(" → Add it to .env for local builds.");
21 eprintln!(" → Add it as a GitHub Actions secret for CI builds.");
22 std::process::exit(1);
23 }
24 }
25 }
26
27 // Optional vars: bake them in when present, use an empty string otherwise.
28 {
29 let var = "HF_TOKEN";
30 println!("cargo:rerun-if-env-changed={var}");
31 match std::env::var(var) {
32 Ok(val) => {
33 println!("cargo:rustc-env={var}={val}");
34 }
35 Err(_) => {
36 // Keep env!() happy even when the token is missing.
37 println!("cargo:rustc-env={var}=");
38 }
39 }
40 }
41
42 // Re-run the build script if .env changes.
43 println!("cargo:rerun-if-changed=.env");
44 }