From e35c884dd94c7efe652c752433ddb80cb81a31a0 Mon Sep 17 00:00:00 2001 From: Kirill Mikhailov Date: Mon, 7 Oct 2024 13:13:35 +0200 Subject: [PATCH] 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 6c42ac120b3..dd46f920986 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)); // Build up an array of command-line arguments to pass to `cargo`: let builder = CargoArgsBuilder::default() @@ -152,6 +146,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();