diff options
Diffstat (limited to 'embassy-executor/build.rs')
| -rw-r--r-- | embassy-executor/build.rs | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/embassy-executor/build.rs b/embassy-executor/build.rs index 8a41d7503..37becde3e 100644 --- a/embassy-executor/build.rs +++ b/embassy-executor/build.rs | |||
| @@ -1,99 +1,7 @@ | |||
| 1 | use std::collections::HashMap; | ||
| 2 | use std::fmt::Write; | ||
| 3 | use std::path::PathBuf; | ||
| 4 | use std::{env, fs}; | ||
| 5 | |||
| 6 | #[path = "./build_common.rs"] | 1 | #[path = "./build_common.rs"] |
| 7 | mod common; | 2 | mod common; |
| 8 | 3 | ||
| 9 | static CONFIGS: &[(&str, usize)] = &[ | ||
| 10 | // BEGIN AUTOGENERATED CONFIG FEATURES | ||
| 11 | // Generated by gen_config.py. DO NOT EDIT. | ||
| 12 | ("TASK_ARENA_SIZE", 4096), | ||
| 13 | // END AUTOGENERATED CONFIG FEATURES | ||
| 14 | ]; | ||
| 15 | |||
| 16 | struct ConfigState { | ||
| 17 | value: usize, | ||
| 18 | seen_feature: bool, | ||
| 19 | seen_env: bool, | ||
| 20 | } | ||
| 21 | |||
| 22 | fn main() { | 4 | fn main() { |
| 23 | let crate_name = env::var("CARGO_PKG_NAME") | ||
| 24 | .unwrap() | ||
| 25 | .to_ascii_uppercase() | ||
| 26 | .replace('-', "_"); | ||
| 27 | |||
| 28 | // only rebuild if build.rs changed. Otherwise Cargo will rebuild if any | ||
| 29 | // other file changed. | ||
| 30 | println!("cargo:rerun-if-changed=build.rs"); | ||
| 31 | |||
| 32 | // Rebuild if config envvar changed. | ||
| 33 | for (name, _) in CONFIGS { | ||
| 34 | println!("cargo:rerun-if-env-changed={crate_name}_{name}"); | ||
| 35 | } | ||
| 36 | |||
| 37 | let mut configs = HashMap::new(); | ||
| 38 | for (name, default) in CONFIGS { | ||
| 39 | configs.insert( | ||
| 40 | *name, | ||
| 41 | ConfigState { | ||
| 42 | value: *default, | ||
| 43 | seen_env: false, | ||
| 44 | seen_feature: false, | ||
| 45 | }, | ||
| 46 | ); | ||
| 47 | } | ||
| 48 | |||
| 49 | let prefix = format!("{crate_name}_"); | ||
| 50 | for (var, value) in env::vars() { | ||
| 51 | if let Some(name) = var.strip_prefix(&prefix) { | ||
| 52 | let Some(cfg) = configs.get_mut(name) else { | ||
| 53 | panic!("Unknown env var {name}") | ||
| 54 | }; | ||
| 55 | |||
| 56 | let Ok(value) = value.parse::<usize>() else { | ||
| 57 | panic!("Invalid value for env var {name}: {value}") | ||
| 58 | }; | ||
| 59 | |||
| 60 | cfg.value = value; | ||
| 61 | cfg.seen_env = true; | ||
| 62 | } | ||
| 63 | |||
| 64 | if let Some(feature) = var.strip_prefix("CARGO_FEATURE_") { | ||
| 65 | if let Some(i) = feature.rfind('_') { | ||
| 66 | let name = &feature[..i]; | ||
| 67 | let value = &feature[i + 1..]; | ||
| 68 | if let Some(cfg) = configs.get_mut(name) { | ||
| 69 | let Ok(value) = value.parse::<usize>() else { | ||
| 70 | panic!("Invalid value for feature {name}: {value}") | ||
| 71 | }; | ||
| 72 | |||
| 73 | // envvars take priority. | ||
| 74 | if !cfg.seen_env { | ||
| 75 | if cfg.seen_feature { | ||
| 76 | panic!("multiple values set for feature {}: {} and {}", name, cfg.value, value); | ||
| 77 | } | ||
| 78 | |||
| 79 | cfg.value = value; | ||
| 80 | cfg.seen_feature = true; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | let mut data = String::new(); | ||
| 88 | |||
| 89 | for (name, cfg) in &configs { | ||
| 90 | writeln!(&mut data, "pub const {}: usize = {};", name, cfg.value).unwrap(); | ||
| 91 | } | ||
| 92 | |||
| 93 | let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 94 | let out_file = out_dir.join("config.rs").to_string_lossy().to_string(); | ||
| 95 | fs::write(out_file, data).unwrap(); | ||
| 96 | |||
| 97 | let mut rustc_cfgs = common::CfgSet::new(); | 5 | let mut rustc_cfgs = common::CfgSet::new(); |
| 98 | common::set_target_cfgs(&mut rustc_cfgs); | 6 | common::set_target_cfgs(&mut rustc_cfgs); |
| 99 | } | 7 | } |
