From dfdc20077b689621d59673925cb74af806bf3faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 15 Sep 2023 13:12:13 +0200 Subject: [PATCH] Featurize defmt --- .github/workflows/ci.yml | 16 ++++++++++++++++ .github/workflows/release.yml | 9 +++++++-- espflash/Cargo.toml | 8 ++++++-- espflash/src/cli/monitor/mod.rs | 13 ++++++++++--- espflash/src/cli/monitor/parser/mod.rs | 1 + 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b21c4b41..fc36d88c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,10 @@ jobs: target: "armv7-unknown-linux-gnueabihf" arch: "armhf" features: "--features=raspberry" + - os: "ubuntu-22.04" + target: "x86_64-unknown-linux-gnu" + arch: "x86_64" + features: "--features=defmt" runs-on: ${{ matrix.platform.os }} steps: @@ -69,6 +73,9 @@ jobs: platform: - target: "x86_64-unknown-linux-gnu" arch: "x86_64" + - target: "x86_64-unknown-linux-gnu" + arch: "x86_64" + features: "--features=defmt" - target: "aarch64-unknown-linux-gnu" arch: "arm64" features: "--features=raspberry" @@ -96,6 +103,9 @@ jobs: platform: - target: "x86_64-unknown-linux-gnu" arch: "x86_64" + - target: "x86_64-unknown-linux-gnu" + arch: "x86_64" + features: "--features=defmt" - target: "aarch64-unknown-linux-gnu" arch: "arm64" features: "--features=raspberry" @@ -127,6 +137,9 @@ jobs: platform: - target: "x86_64-unknown-linux-gnu" arch: "x86_64" + - target: "x86_64-unknown-linux-gnu" + arch: "x86_64" + features: "--features=defmt" - target: "aarch64-unknown-linux-gnu" arch: "arm64" features: "--features=raspberry" @@ -157,6 +170,9 @@ jobs: platform: - target: "x86_64-unknown-linux-gnu" arch: "x86_64" + - target: "x86_64-unknown-linux-gnu" + arch: "x86_64" + features: "--features=defmt" - target: "aarch64-unknown-linux-gnu" arch: "arm64" features: "--features=raspberry" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 301be25d..05ae237c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,29 +18,34 @@ jobs: - os: "ubuntu-22.04" target: "x86_64-unknown-linux-gnu" arch: "x86_64" + features: "--features=defmt" - os: "ubuntu-22.04" target: "x86_64-unknown-linux-musl" arch: "x86_64" + features: "--features=defmt" - os: "ubuntu-22.04" target: "aarch64-unknown-linux-gnu" arch: "arm64" - features: "--features=raspberry" + features: "--features=raspberry,defmt" - os: "ubuntu-22.04" target: "armv7-unknown-linux-gnueabihf" arch: "armhf" - features: "--features=raspberry" + features: "--features=raspberry,defmt" # Windows - os: "windows-2022" target: "x86_64-pc-windows-msvc" arch: "x86_64" + features: "--features=defmt" # macOs - os: "macos-12" target: "aarch64-apple-darwin" # This is not true, but simplifies the logic of the action. arch: "x86_64" + features: "--features=defmt" - os: "macos-12" target: "x86_64-apple-darwin" arch: "x86_64" + features: "--features=defmt" runs-on: ${{ matrix.platform.os }} steps: diff --git a/espflash/Cargo.toml b/espflash/Cargo.toml index f244c86e..9787f944 100644 --- a/espflash/Cargo.toml +++ b/espflash/Cargo.toml @@ -40,8 +40,8 @@ clap_complete = { version = "4.3", optional = true } comfy-table = { version = "7.0.1", optional = true } crossterm = { version = "0.25.0", optional = true } # 0.26.x causes issues on Windows ctrlc = { version = "3.4.0", optional = true } -defmt-decoder = { version = "=0.3.8", features = ["unstable"] } -defmt-parser = { version = "=0.3.3", features = ["unstable"] } +defmt-decoder = { version = "=0.3.8", features = ["unstable"], optional = true } +defmt-parser = { version = "=0.3.3", features = ["unstable"], optional = true } dialoguer = { version = "0.10.4", optional = true } directories = { version = "5.0.1", optional = true } env_logger = { version = "0.10.0", optional = true } @@ -84,4 +84,8 @@ cli = [ "dep:regex", "dep:update-informer", ] +defmt = [ + "dep:defmt-decoder", + "dep:defmt-parser", +] raspberry = ["dep:rppal"] diff --git a/espflash/src/cli/monitor/mod.rs b/espflash/src/cli/monitor/mod.rs index 946d77c7..3e08b0fe 100644 --- a/espflash/src/cli/monitor/mod.rs +++ b/espflash/src/cli/monitor/mod.rs @@ -23,13 +23,14 @@ use log::error; use miette::{IntoDiagnostic, Result}; use crate::{ - cli::monitor::parser::{esp_defmt::EspDefmt, InputParser, ResolvingPrinter}, + cli::monitor::parser::{InputParser, ResolvingPrinter}, connection::reset_after_flash, interface::Interface, }; +pub mod parser; + mod line_endings; -mod parser; mod symbols; /// Type that ensures that raw mode is disabled when dropped. @@ -57,7 +58,13 @@ pub fn monitor( pid: u16, baud: u32, ) -> serialport::Result<()> { - monitor_with(serial, elf, pid, baud, EspDefmt::new(elf)) + #[cfg(feature = "defmt")] + let parser = parser::esp_defmt::EspDefmt::new(elf); + + #[cfg(not(feature = "defmt"))] + let parser = parser::serial::Serial; + + monitor_with(serial, elf, pid, baud, parser) } /// Open a serial monitor on the given interface, using the given input parser. diff --git a/espflash/src/cli/monitor/parser/mod.rs b/espflash/src/cli/monitor/parser/mod.rs index 1ae9c85a..a5491764 100644 --- a/espflash/src/cli/monitor/parser/mod.rs +++ b/espflash/src/cli/monitor/parser/mod.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "defmt")] pub mod esp_defmt; pub mod serial;