Skip to content

Commit

Permalink
XTASK: add a way to activate features per chip (docs)
Browse files Browse the repository at this point in the history
  • Loading branch information
playfulFence committed Oct 7, 2024
1 parent 3e16c5c commit e35c884
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -152,6 +146,28 @@ pub fn build_documentation(
Ok(docs_path)
}

fn apply_feature_rules(chip: &Chip, package: &Package) -> Vec<String> {
// 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<fn(&Chip, &Package) -> Vec<String>> = 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<Vec<Metadata>> {
let mut examples = Vec::new();
Expand Down

0 comments on commit e35c884

Please sign in to comment.