From 67dfdb6c361a99cbc82469adac47897c24842820 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Wed, 17 Jul 2024 16:40:17 +0100 Subject: [PATCH] Check more features and targets in CI when linting --- esp-hal/Cargo.toml | 2 +- esp-metadata/Cargo.toml | 2 + esp-metadata/src/lib.rs | 60 ++++++++++++++++++++++--- xtask/Cargo.toml | 1 + xtask/src/lib.rs | 64 +-------------------------- xtask/src/main.rs | 97 +++++++++++++++++++++++++++++++---------- 6 files changed, 135 insertions(+), 91 deletions(-) diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index 798ab828eb3..5a52e612af2 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -182,7 +182,7 @@ opsram-8m = [] opsram-16m = [] # This feature is intended for testing; you probably don't want to enable it: -ci = ["async", "embedded-hal-02", "embedded-io", "ufmt"] +ci = ["async", "embedded-hal-02", "embedded-io", "ufmt", "defmt", "bluetooth", "place-spi-driver-in-ram"] [lints.clippy] mixed_attributes_style = "allow" diff --git a/esp-metadata/Cargo.toml b/esp-metadata/Cargo.toml index 8172a98f0df..2ed01a4bc6f 100644 --- a/esp-metadata/Cargo.toml +++ b/esp-metadata/Cargo.toml @@ -8,6 +8,8 @@ repository = "https://github.com/esp-rs/esp-hal" license = "MIT OR Apache-2.0" [dependencies] +anyhow = "1.0.86" +clap = { version = "4.5.4", features = ["derive"] } # TODO remove this dep here basic-toml = "0.1.9" lazy_static = "1.5.0" serde = { version = "1.0.204", features = ["derive"] } diff --git a/esp-metadata/src/lib.rs b/esp-metadata/src/lib.rs index 44db919ad4b..d31c4358607 100644 --- a/esp-metadata/src/lib.rs +++ b/esp-metadata/src/lib.rs @@ -1,5 +1,7 @@ //! Metadata for Espressif devices, primarily intended for use in build scripts. +use anyhow::{bail, Result}; + const ESP32_TOML: &str = include_str!("../devices/esp32.toml"); const ESP32C2_TOML: &str = include_str!("../devices/esp32c2.toml"); const ESP32C3_TOML: &str = include_str!("../devices/esp32c3.toml"); @@ -84,9 +86,10 @@ pub enum Cores { strum::Display, strum::EnumIter, strum::EnumString, + clap::ValueEnum, )] -#[serde(rename_all = "lowercase")] -#[strum(serialize_all = "lowercase")] +#[serde(rename_all = "kebab-case")] +#[strum(serialize_all = "kebab-case")] pub enum Chip { /// ESP32 Esp32, @@ -98,14 +101,62 @@ pub enum Chip { Esp32c6, /// ESP32-H2 Esp32h2, - /// ESP32-P4 - Esp32p4, /// ESP32-S2 Esp32s2, /// ESP32-S3 Esp32s3, } +impl Chip { + pub fn target(&self) -> &str { + use Chip::*; + + match self { + Esp32 => "xtensa-esp32-none-elf", + Esp32c2 | Esp32c3 => "riscv32imc-unknown-none-elf", + Esp32c6 | Esp32h2 => "riscv32imac-unknown-none-elf", + Esp32s2 => "xtensa-esp32s2-none-elf", + Esp32s3 => "xtensa-esp32s3-none-elf", + } + } + + pub fn has_lp_core(&self) -> bool { + use Chip::*; + + matches!(self, Esp32c6 | Esp32s2 | Esp32s3) + } + + pub fn lp_target(&self) -> Result<&str> { + use Chip::*; + + match self { + Esp32c6 => Ok("riscv32imac-unknown-none-elf"), + Esp32s2 | Esp32s3 => Ok("riscv32imc-unknown-none-elf"), + _ => bail!("Chip does not contain an LP core: '{}'", self), + } + } + + pub fn pretty_name(&self) -> &str { + match self { + Chip::Esp32 => "ESP32", + Chip::Esp32c2 => "ESP32-C2", + Chip::Esp32c3 => "ESP32-C3", + Chip::Esp32c6 => "ESP32-C6", + Chip::Esp32h2 => "ESP32-H2", + Chip::Esp32s2 => "ESP32-S2", + Chip::Esp32s3 => "ESP32-S3", + } + } + + pub fn is_xtensa(&self) -> bool { + matches!(self, Chip::Esp32 | Chip::Esp32s2 | Chip::Esp32s3) + } + + pub fn is_riscv(&self) -> bool { + !self.is_xtensa() + } +} + #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] struct Device { pub name: String, @@ -130,7 +181,6 @@ impl Config { Chip::Esp32c3 => ESP32C3_CFG.clone(), Chip::Esp32c6 => ESP32C6_CFG.clone(), Chip::Esp32h2 => ESP32H2_CFG.clone(), - Chip::Esp32p4 => ESP32P4_CFG.clone(), Chip::Esp32s2 => ESP32S2_CFG.clone(), Chip::Esp32s3 => ESP32S3_CFG.clone(), } diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 8384c4487d0..06b9ce793c0 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -17,3 +17,4 @@ semver = { version = "1.0.23", features = ["serde"] } serde = { version = "1.0.203", features = ["derive"] } strum = { version = "0.26.2", features = ["derive"] } toml_edit = "0.22.13" +esp-metadata = { path = "../esp-metadata" } diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index fd035ef2a1d..94d157a36b8 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -9,6 +9,7 @@ use std::{ use anyhow::{bail, Result}; use cargo::CargoAction; use clap::ValueEnum; +use esp_metadata::Chip; use strum::{Display, EnumIter, IntoEnumIterator as _}; use self::cargo::CargoArgsBuilder; @@ -50,69 +51,6 @@ pub enum Package { HilTest, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Display, EnumIter, ValueEnum, serde::Serialize)] -#[serde(rename_all = "kebab-case")] -#[strum(serialize_all = "kebab-case")] -pub enum Chip { - Esp32, - Esp32c2, - Esp32c3, - Esp32c6, - Esp32h2, - Esp32s2, - Esp32s3, -} - -impl Chip { - pub fn target(&self) -> &str { - use Chip::*; - - match self { - Esp32 => "xtensa-esp32-none-elf", - Esp32c2 | Esp32c3 => "riscv32imc-unknown-none-elf", - Esp32c6 | Esp32h2 => "riscv32imac-unknown-none-elf", - Esp32s2 => "xtensa-esp32s2-none-elf", - Esp32s3 => "xtensa-esp32s3-none-elf", - } - } - - pub fn has_lp_core(&self) -> bool { - use Chip::*; - - matches!(self, Esp32c6 | Esp32s2 | Esp32s3) - } - - pub fn lp_target(&self) -> Result<&str> { - use Chip::*; - - match self { - Esp32c6 => Ok("riscv32imac-unknown-none-elf"), - Esp32s2 | Esp32s3 => Ok("riscv32imc-unknown-none-elf"), - _ => bail!("Chip does not contain an LP core: '{}'", self), - } - } - - pub fn pretty_name(&self) -> &str { - match self { - Chip::Esp32 => "ESP32", - Chip::Esp32c2 => "ESP32-C2", - Chip::Esp32c3 => "ESP32-C3", - Chip::Esp32c6 => "ESP32-C6", - Chip::Esp32h2 => "ESP32-H2", - Chip::Esp32s2 => "ESP32-S2", - Chip::Esp32s3 => "ESP32-S3", - } - } - - pub fn is_xtensa(&self) -> bool { - matches!(self, Chip::Esp32 | Chip::Esp32s2 | Chip::Esp32s3) - } - - pub fn is_riscv(&self) -> bool { - !self.is_xtensa() - } -} - #[derive(Debug, Default, Clone)] pub struct Metadata { example_path: PathBuf, diff --git a/xtask/src/main.rs b/xtask/src/main.rs index bc8eae358c9..3e197b4ab11 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -7,14 +7,12 @@ use std::{ use anyhow::{bail, Result}; use clap::{Args, Parser}; +use esp_metadata::{Chip, Config}; use minijinja::Value; use strum::IntoEnumIterator; use xtask::{ cargo::{CargoAction, CargoArgsBuilder}, - Chip, - Metadata, - Package, - Version, + Metadata, Package, Version, }; // ---------------------------------------------------------------------------- @@ -475,26 +473,45 @@ fn lint_packages(workspace: &Path, _args: LintPackagesArgs) -> Result<()> { // Since different files/modules can be included/excluded // depending on the target, we must lint *all* targets: for chip in Chip::iter() { + let device = Config::for_chip(&chip); + let mut features = format!("--features={chip},ci"); + + // Cover all esp-hal features where a device is supported + if device.contains(&"usb0".to_owned()) { + features.push_str(",usb-otg") + } + if device.contains(&"psram".to_owned()) { + // TODO this doesn't test octal psram as it would require a separate build + features.push_str(",psram-4m,psram-80mhz") + } + if matches!(chip, Chip::Esp32c6 | Chip::Esp32h2) { + features.push_str(",flip-link") + } + lint_package( &path, &[ "-Zbuild-std=core", &format!("--target={}", chip.target()), - &format!("--features={chip}"), + &features, ], )?; } } Package::EspHalEmbassy => { - lint_package( - &path, - &[ - "-Zbuild-std=core", - "--target=riscv32imac-unknown-none-elf", - "--features=esp32c6", - ], - )?; + // Since different files/modules can be included/excluded + // depending on the target, we must lint *all* targets: + for chip in Chip::iter() { + lint_package( + &path, + &[ + "-Zbuild-std=core", + &format!("--target={}", chip.target()), + &format!("--features={chip},executors,defmt,integrated-timers"), + ], + )?; + } } Package::EspHalProcmacros | Package::EspRiscvRt => lint_package( @@ -502,7 +519,35 @@ fn lint_packages(workspace: &Path, _args: LintPackagesArgs) -> Result<()> { &["-Zbuild-std=core", "--target=riscv32imc-unknown-none-elf"], )?, - Package::EspHalSmartled | Package::EspIeee802154 | Package::EspLpHal => lint_package( + Package::EspIeee802154 => { + for chip in Chip::iter() + .filter(|chip| Config::for_chip(chip).contains(&"ieee802154".to_owned())) + { + lint_package( + &path, + &[ + "-Zbuild-std=core", + &format!("--target={}", chip.target()), + &format!("--features={chip}"), + ], + )?; + } + } + Package::EspLpHal => { + for chip in Chip::iter() + .filter(|chip| Config::for_chip(chip).contains(&"lp_core".to_owned())) + { + lint_package( + &path, + &[ + "-Zbuild-std=core", + &format!("--target={}", chip.lp_target().unwrap()), + &format!("--features={chip},embedded-io,embedded-hal-02"), + ], + )?; + } + } + Package::EspHalSmartled => lint_package( &path, &[ "-Zbuild-std=core", @@ -529,14 +574,22 @@ fn lint_packages(workspace: &Path, _args: LintPackagesArgs) -> Result<()> { ], )?, - Package::EspWifi => lint_package( - &path, - &[ - "-Zbuild-std=core", - "--target=riscv32imc-unknown-none-elf", - "--features=esp32c3,wifi-default,ble,esp-now,async,embassy-net", - ], - )?, + Package::EspWifi => { + // Since different files/modules can be included/excluded + // depending on the target, we must lint *all* targets: + for chip in Chip::iter() { + lint_package( + &path, + &[ + "-Zbuild-std=core", + &format!("--target={}", chip.target()), + &format!( + "--features={chip},wifi-default,ble,esp-now,async,embassy-net,embedded-svc,coex,ps-min-modem,defmt,dump-packets" + ), + ], + )?; + } + } // We will *not* check the following packages with `clippy`; this // may or may not change in the future: