Laura Abbott | bb8c8d1 | 2020-02-24 15:04:54 -0500 | [diff] [blame] | 1 | use std::env; |
| 2 | |
| 3 | fn main() { |
| 4 | static APP_HEAP_SIZE: &str = "APP_HEAP_SIZE"; |
| 5 | |
| 6 | println!("cargo:rerun-if-env-changed={}", APP_HEAP_SIZE); |
| 7 | |
| 8 | set_default_env(APP_HEAP_SIZE, "1024"); |
| 9 | } |
| 10 | |
| 11 | fn set_default_env(env_var: &str, default: &str) { |
| 12 | if let Some(s) = read_env_var(env_var) { |
| 13 | println!("cargo:rustc-env={}={}", env_var, s); |
| 14 | } else { |
| 15 | // Just use a default of 1024 if nothing is passed in |
| 16 | println!("cargo:rustc-env={}={}", env_var, default); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | fn read_env_var(env_var: &str) -> Option<String> { |
| 21 | env::var_os(env_var).map(|os_string| os_string.into_string().unwrap()) |
| 22 | } |