From 0b220e922268602e3b5d950be849471eea0266e7 Mon Sep 17 00:00:00 2001 From: Kirill Mikhailov Date: Mon, 7 Oct 2024 13:13:35 +0200 Subject: [PATCH 1/2] XTASK: add a way to activate features per chip (docs) --- xtask/src/lib.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 1f0059df43f..8862a2b7e19 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -116,14 +116,8 @@ pub fn build_documentation( let mut features = vec![chip.to_string()]; - // future enhancement: see https://github.com/esp-rs/esp-hal/issues/2195 - if matches!(package, Package::EspHal) { - features.push("ci".to_owned()); - - if [Chip::Esp32, Chip::Esp32s2, Chip::Esp32s3].contains(&chip) { - features.push("quad-psram".to_owned()); - } - } + // Add chip-specific features for a package. + features.extend(apply_feature_rules(&chip, &package)); let chip = Config::for_chip(&chip); @@ -174,6 +168,28 @@ pub fn build_documentation( Ok(docs_path) } +fn apply_feature_rules(chip: &Chip, package: &Package) -> Vec { + // If we need to activate a feature for documentation build for particular + // package for chip, add a matching by chip/package/both according to the + // existing example. + let rules: Vec Vec> = vec![|chip, pkg| { + if matches!(pkg, Package::EspHal) { + let mut features = vec!["ci".to_owned()]; + if matches!(chip, Chip::Esp32 | Chip::Esp32s2 | Chip::Esp32s3) { + features.push("quad-psram".to_owned()); + } + features + } else { + vec![] + } + }]; + + rules + .into_iter() + .flat_map(|rule| rule(chip, package)) + .collect() +} + /// Load all examples at the given path, and parse their metadata. pub fn load_examples(path: &Path, action: CargoAction) -> Result> { let mut examples = Vec::new(); From e0e3627a79365b9eec61e9eaf7c6093d2d866a78 Mon Sep 17 00:00:00 2001 From: Kirill Mikhailov Date: Fri, 11 Oct 2024 15:30:34 +0200 Subject: [PATCH 2/2] Address reviews --- xtask/src/lib.rs | 66 ++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 8862a2b7e19..043cdda2e77 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -116,30 +116,9 @@ pub fn build_documentation( let mut features = vec![chip.to_string()]; - // Add chip-specific features for a package. - features.extend(apply_feature_rules(&chip, &package)); - let chip = Config::for_chip(&chip); - if matches!(package, Package::EspWifi) { - let wifi = chip.contains("wifi"); - let ble = chip.contains("ble"); - if wifi { - features.push("wifi".to_owned()); - features.push("wifi-default".to_owned()); - features.push("esp-now".to_owned()); - features.push("sniffer".to_owned()); - features.push("utils".to_owned()); - features.push("embassy-net".to_owned()); - } - if ble { - features.push("ble".to_owned()); - } - if wifi && ble { - features.push("coex".to_owned()); - } - features.push("async".to_owned()); - } + features.extend(apply_feature_rules(&package, chip)); // Build up an array of command-line arguments to pass to `cargo`: let builder = CargoArgsBuilder::default() @@ -168,26 +147,35 @@ pub fn build_documentation( Ok(docs_path) } -fn apply_feature_rules(chip: &Chip, package: &Package) -> Vec { - // If we need to activate a feature for documentation build for particular - // package for chip, add a matching by chip/package/both according to the - // existing example. - let rules: Vec Vec> = vec![|chip, pkg| { - if matches!(pkg, Package::EspHal) { - let mut features = vec!["ci".to_owned()]; - if matches!(chip, Chip::Esp32 | Chip::Esp32s2 | Chip::Esp32s3) { - features.push("quad-psram".to_owned()); +fn apply_feature_rules(package: &Package, config: &Config) -> Vec { + let chip_name = &config.name(); + + match (package, chip_name.as_str()) { + (Package::EspHal, "esp32") => vec!["quad-psram".to_owned(), "ci".to_owned()], + (Package::EspHal, "esp32s2") => vec!["quad-psram".to_owned(), "ci".to_owned()], + (Package::EspHal, "esp32s3") => vec!["quad-psram".to_owned(), "ci".to_owned()], + (Package::EspHal, _) => vec!["ci".to_owned()], + (Package::EspWifi, _) => { + let mut features = vec![]; + if config.contains("wifi") { + features.push("wifi".to_owned()); + features.push("wifi-default".to_owned()); + features.push("esp-now".to_owned()); + features.push("sniffer".to_owned()); + features.push("utils".to_owned()); + features.push("embassy-net".to_owned()); } + if config.contains("ble") { + features.push("ble".to_owned()); + } + if config.contains("wifi") && config.contains("ble") { + features.push("coex".to_owned()); + } + features.push("async".to_owned()); features - } else { - vec![] } - }]; - - rules - .into_iter() - .flat_map(|rule| rule(chip, package)) - .collect() + _ => vec![], + } } /// Load all examples at the given path, and parse their metadata.