diff --git a/esp-config/src/generate.rs b/esp-config/src/generate.rs index ede216f5d27..129af7dbd7a 100644 --- a/esp-config/src/generate.rs +++ b/esp-config/src/generate.rs @@ -273,7 +273,7 @@ pub fn generate_config( .iter() .flat_map(|(name, _description, _default, validator)| { if let Some(validator) = validator { - let name = format!("{prefix}_{}", screaming_snake_case(name)); + let name = format!("{prefix}__{}", screaming_snake_case(name)); Some((name, validator)) } else { None @@ -341,7 +341,7 @@ fn create_config( let mut configs = HashMap::new(); for (name, description, default, _validator) in config { - let name = format!("{prefix}_{}", screaming_snake_case(name)); + let name = format!("{prefix}__{}", screaming_snake_case(name)); configs.insert(name.clone(), default.clone()); // Write documentation table line: @@ -388,7 +388,7 @@ fn emit_configuration( selected_config: &mut String, ) { for (name, value) in configs.iter() { - let cfg_name = snake_case(name.trim_start_matches(&format!("{prefix}_"))); + let cfg_name = snake_case(name.trim_start_matches(&format!("{prefix}__"))); println!("cargo:rustc-check-cfg=cfg({cfg_name})"); if let Value::Bool(true) = value { @@ -464,10 +464,10 @@ mod test { fn env_override() { temp_env::with_vars( [ - ("ESP_TEST_NUMBER", Some("0xaa")), - ("ESP_TEST_NUMBER_SIGNED", Some("-999")), - ("ESP_TEST_STRING", Some("Hello world!")), - ("ESP_TEST_BOOL", Some("true")), + ("ESP_TEST__NUMBER", Some("0xaa")), + ("ESP_TEST__NUMBER_SIGNED", Some("-999")), + ("ESP_TEST__STRING", Some("Hello world!")), + ("ESP_TEST__BOOL", Some("true")), ], || { let configs = generate_config( @@ -491,28 +491,28 @@ mod test { // some values have changed assert_eq!( - match configs.get("ESP_TEST_NUMBER").unwrap() { + match configs.get("ESP_TEST__NUMBER").unwrap() { Value::Integer(num) => *num, _ => unreachable!(), }, 0xaa ); assert_eq!( - match configs.get("ESP_TEST_NUMBER_SIGNED").unwrap() { + match configs.get("ESP_TEST__NUMBER_SIGNED").unwrap() { Value::Integer(num) => *num, _ => unreachable!(), }, -999 ); assert_eq!( - match configs.get("ESP_TEST_STRING").unwrap() { + match configs.get("ESP_TEST__STRING").unwrap() { Value::String(val) => val, _ => unreachable!(), }, "Hello world!" ); assert_eq!( - match configs.get("ESP_TEST_BOOL").unwrap() { + match configs.get("ESP_TEST__BOOL").unwrap() { Value::Bool(val) => *val, _ => unreachable!(), }, @@ -521,21 +521,21 @@ mod test { // the rest are the defaults assert_eq!( - match configs.get("ESP_TEST_NUMBER_DEFAULT").unwrap() { + match configs.get("ESP_TEST__NUMBER_DEFAULT").unwrap() { Value::Integer(num) => *num, _ => unreachable!(), }, 999 ); assert_eq!( - match configs.get("ESP_TEST_STRING_DEFAULT").unwrap() { + match configs.get("ESP_TEST__STRING_DEFAULT").unwrap() { Value::String(val) => val, _ => unreachable!(), }, "Demo" ); assert_eq!( - match configs.get("ESP_TEST_BOOL_DEFAULT").unwrap() { + match configs.get("ESP_TEST__BOOL_DEFAULT").unwrap() { Value::Bool(val) => *val, _ => unreachable!(), }, @@ -549,10 +549,10 @@ mod test { fn builtin_validation_passes() { temp_env::with_vars( [ - ("ESP_TEST_POSITIVE_NUMBER", Some("7")), - ("ESP_TEST_NEGATIVE_NUMBER", Some("-1")), - ("ESP_TEST_NON_NEGATIVE_NUMBER", Some("0")), - ("ESP_TEST_RANGE", Some("9")), + ("ESP_TEST__POSITIVE_NUMBER", Some("7")), + ("ESP_TEST__NEGATIVE_NUMBER", Some("-1")), + ("ESP_TEST__NON_NEGATIVE_NUMBER", Some("0")), + ("ESP_TEST__RANGE", Some("9")), ], || { generate_config( @@ -591,7 +591,7 @@ mod test { #[test] fn custom_validation_passes() { - temp_env::with_vars([("ESP_TEST_NUMBER", Some("13"))], || { + temp_env::with_vars([("ESP_TEST__NUMBER", Some("13"))], || { generate_config( "esp-test", &[( @@ -615,7 +615,7 @@ mod test { #[test] #[should_panic] fn builtin_validation_bails() { - temp_env::with_vars([("ESP_TEST_POSITIVE_NUMBER", Some("-99"))], || { + temp_env::with_vars([("ESP_TEST__POSITIVE_NUMBER", Some("-99"))], || { generate_config( "esp-test", &[( @@ -632,7 +632,7 @@ mod test { #[test] #[should_panic] fn custom_validation_bails() { - temp_env::with_vars([("ESP_TEST_NUMBER", Some("37"))], || { + temp_env::with_vars([("ESP_TEST__NUMBER", Some("37"))], || { generate_config( "esp-test", &[( @@ -658,8 +658,8 @@ mod test { fn env_unknown_bails() { temp_env::with_vars( [ - ("ESP_TEST_NUMBER", Some("0xaa")), - ("ESP_TEST_RANDOM_VARIABLE", Some("")), + ("ESP_TEST__NUMBER", Some("0xaa")), + ("ESP_TEST__RANDOM_VARIABLE", Some("")), ], || { generate_config( @@ -674,7 +674,18 @@ mod test { #[test] #[should_panic] fn env_invalid_values_bails() { - temp_env::with_vars([("ESP_TEST_NUMBER", Some("Hello world"))], || { + temp_env::with_vars([("ESP_TEST__NUMBER", Some("Hello world"))], || { + generate_config( + "esp-test", + &[("number", "NA", Value::Integer(999), None)], + false, + ); + }); + } + + #[test] + fn env_unknown_prefix_is_ignored() { + temp_env::with_vars([("ESP_TEST_OTHER__NUMBER", Some("Hello world"))], || { generate_config( "esp-test", &[("number", "NA", Value::Integer(999), None)], diff --git a/esp-ieee802154/src/lib.rs b/esp-ieee802154/src/lib.rs index 65400db64da..255495f50c0 100644 --- a/esp-ieee802154/src/lib.rs +++ b/esp-ieee802154/src/lib.rs @@ -67,7 +67,7 @@ struct QueueConfig { } pub(crate) const CONFIG: QueueConfig = QueueConfig { - rx_queue_size: esp_config_int!(usize, "ESP_IEEE802154_RX_QUEUE_SIZE"), + rx_queue_size: esp_config_int!(usize, "ESP_IEEE802154__RX_QUEUE_SIZE"), }; /// IEEE 802.15.4 driver configuration diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index 9b968c7d8b7..7e9f1842cea 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -185,27 +185,27 @@ struct Config { } pub(crate) const CONFIG: config::EspWifiConfig = config::EspWifiConfig { - rx_queue_size: esp_config_int!(usize, "ESP_WIFI_RX_QUEUE_SIZE"), - tx_queue_size: esp_config_int!(usize, "ESP_WIFI_TX_QUEUE_SIZE"), - static_rx_buf_num: esp_config_int!(usize, "ESP_WIFI_STATIC_RX_BUF_NUM"), - dynamic_rx_buf_num: esp_config_int!(usize, "ESP_WIFI_DYNAMIC_RX_BUF_NUM"), - static_tx_buf_num: esp_config_int!(usize, "ESP_WIFI_STATIC_TX_BUF_NUM"), - dynamic_tx_buf_num: esp_config_int!(usize, "ESP_WIFI_DYNAMIC_TX_BUF_NUM"), - csi_enable: esp_config_bool!("ESP_WIFI_CSI_ENABLE"), - ampdu_rx_enable: esp_config_bool!("ESP_WIFI_AMPDU_RX_ENABLE"), - ampdu_tx_enable: esp_config_bool!("ESP_WIFI_AMPDU_TX_ENABLE"), - amsdu_tx_enable: esp_config_bool!("ESP_WIFI_AMSDU_TX_ENABLE"), - rx_ba_win: esp_config_int!(usize, "ESP_WIFI_RX_BA_WIN"), - max_burst_size: esp_config_int!(usize, "ESP_WIFI_MAX_BURST_SIZE"), - country_code: esp_config_str!("ESP_WIFI_COUNTRY_CODE"), - country_code_operating_class: esp_config_int!(u8, "ESP_WIFI_COUNTRY_CODE_OPERATING_CLASS"), - mtu: esp_config_int!(usize, "ESP_WIFI_MTU"), - tick_rate_hz: esp_config_int!(u32, "ESP_WIFI_TICK_RATE_HZ"), - listen_interval: esp_config_int!(u16, "ESP_WIFI_LISTEN_INTERVAL"), - beacon_timeout: esp_config_int!(u16, "ESP_WIFI_BEACON_TIMEOUT"), - ap_beacon_timeout: esp_config_int!(u16, "ESP_WIFI_AP_BEACON_TIMEOUT"), - failure_retry_cnt: esp_config_int!(u8, "ESP_WIFI_FAILURE_RETRY_CNT"), - scan_method: esp_config_int!(u32, "ESP_WIFI_SCAN_METHOD"), + rx_queue_size: esp_config_int!(usize, "ESP_WIFI__RX_QUEUE_SIZE"), + tx_queue_size: esp_config_int!(usize, "ESP_WIFI__TX_QUEUE_SIZE"), + static_rx_buf_num: esp_config_int!(usize, "ESP_WIFI__STATIC_RX_BUF_NUM"), + dynamic_rx_buf_num: esp_config_int!(usize, "ESP_WIFI__DYNAMIC_RX_BUF_NUM"), + static_tx_buf_num: esp_config_int!(usize, "ESP_WIFI__STATIC_TX_BUF_NUM"), + dynamic_tx_buf_num: esp_config_int!(usize, "ESP_WIFI__DYNAMIC_TX_BUF_NUM"), + csi_enable: esp_config_bool!("ESP_WIFI__CSI_ENABLE"), + ampdu_rx_enable: esp_config_bool!("ESP_WIFI__AMPDU_RX_ENABLE"), + ampdu_tx_enable: esp_config_bool!("ESP_WIFI__AMPDU_TX_ENABLE"), + amsdu_tx_enable: esp_config_bool!("ESP_WIFI__AMSDU_TX_ENABLE"), + rx_ba_win: esp_config_int!(usize, "ESP_WIFI__RX_BA_WIN"), + max_burst_size: esp_config_int!(usize, "ESP_WIFI__MAX_BURST_SIZE"), + country_code: esp_config_str!("ESP_WIFI__COUNTRY_CODE"), + country_code_operating_class: esp_config_int!(u8, "ESP_WIFI__COUNTRY_CODE_OPERATING_CLASS"), + mtu: esp_config_int!(usize, "ESP_WIFI__MTU"), + tick_rate_hz: esp_config_int!(u32, "ESP_WIFI__TICK_RATE_HZ"), + listen_interval: esp_config_int!(u16, "ESP_WIFI__LISTEN_INTERVAL"), + beacon_timeout: esp_config_int!(u16, "ESP_WIFI__BEACON_TIMEOUT"), + ap_beacon_timeout: esp_config_int!(u16, "ESP_WIFI__AP_BEACON_TIMEOUT"), + failure_retry_cnt: esp_config_int!(u8, "ESP_WIFI__FAILURE_RETRY_CNT"), + scan_method: esp_config_int!(u32, "ESP_WIFI__SCAN_METHOD"), }; // Validate the configuration at compile time