Skip to content

Commit

Permalink
Check more features and targets in CI when linting
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Jul 17, 2024
1 parent 3729923 commit 67dfdb6
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 91 deletions.
2 changes: 1 addition & 1 deletion esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions esp-metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
60 changes: 55 additions & 5 deletions esp-metadata/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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(),
}
Expand Down
1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
64 changes: 1 addition & 63 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
97 changes: 75 additions & 22 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -475,34 +473,81 @@ 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(
&path,
&["-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",
Expand All @@ -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:
Expand Down

0 comments on commit 67dfdb6

Please sign in to comment.