-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.rs
35 lines (32 loc) · 1.1 KB
/
build.rs
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
35
use std::env;
use std::fs;
use std::path::Path;
const CONFIG: &str = "config.rs";
const LOCAL_API_URL: &str = "https://login.screenly.local";
const STAGE_API_URL: &str = "https://api.screenlyappstage.com";
const PROD_API_URL: &str = "https://api.screenlyapp.com";
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join(CONFIG);
let api_server = match env::var_os("API_SERVER_NAME") {
Some(val) => {
let api_server_name = val.into_string().unwrap();
match api_server_name.as_str() {
"local" => LOCAL_API_URL,
"stage" => STAGE_API_URL,
"prod" => PROD_API_URL,
_ => {
panic!("Invalid API_SERVER_NAME. Use one of: local, stage, prod");
}
}
}
None => PROD_API_URL,
};
fs::write(
dest_path,
format!("pub const API_BASE_URL: &str = \"{}\";", api_server),
)
.unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=API_SERVER_NAME");
}