Skip to content

Commit

Permalink
XTASK: add a way to activate features per chip (docs) (#2287)
Browse files Browse the repository at this point in the history
* XTASK: add a way to activate features per chip (docs)

* Address reviews
  • Loading branch information
playfulFence authored Oct 14, 2024
1 parent 7aa8145 commit 0dc8dcf
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,9 @@ 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());
}
}

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()
Expand Down Expand Up @@ -174,6 +147,37 @@ pub fn build_documentation(
Ok(docs_path)
}

fn apply_feature_rules(package: &Package, config: &Config) -> Vec<String> {
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
}
_ => vec![],
}
}

/// 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 0dc8dcf

Please sign in to comment.