Skip to content

Update to Rust 2024 edition #843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

env:
CARGO_TERM_COLOR: always
MSRV: "1.82"
MSRV: "1.85"

# Cancel any currently running workflows from the same PR, branch, or
# tag when a new workflow is triggered.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `--non-interactive` may now react to key events (user input, Ctrl-C, Ctrl-R) if possible (#819)
- Removed `get_` prefix from any functions which previously had it (#824)
- Take elf data as bytes rather than `ElfFile` struct when creating an image format (#825)
- Updated to Rust 2024 edition (#843)

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions cargo-espflash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "cargo-espflash"
version = "4.0.0-dev"
edition = "2021"
rust-version = "1.82"
edition = "2024"
rust-version = "1.85"
description = "Cargo subcommand for interacting with Espressif devices"
repository = "https://github.com/esp-rs/espflash"
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions cargo-espflash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# cargo-espflash

[![Crates.io](https://img.shields.io/crates/v/cargo-espflash?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/cargo-espflash)
![MSRV](https://img.shields.io/badge/MSRV-1.82-blue?labelColor=1C2C2E&logo=Rust&style=flat-square)
![MSRV](https://img.shields.io/badge/MSRV-1.85-blue?labelColor=1C2C2E&logo=Rust&style=flat-square)
![Crates.io](https://img.shields.io/crates/l/cargo-espflash?labelColor=1C2C2E&style=flat-square)

Cross-compiler and Cargo extension for flashing Espressif devices.
Expand All @@ -25,7 +25,7 @@ Supports the **ESP32**, **ESP32-C2/C3/C6**, **ESP32-H2**, **ESP32-P4**, and **ES

## Installation

If you are installing `cargo-espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.82.0` installed on your system.
If you are installing `cargo-espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.85.0` installed on your system.

To install:

Expand Down
6 changes: 1 addition & 5 deletions cargo-espflash/src/cargo_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,5 @@ fn config_path(path: &Path) -> Option<PathBuf> {
}

let toml = path.join(".cargo/config.toml");
if toml.exists() {
Some(toml)
} else {
None
}
if toml.exists() { Some(toml) } else { None }
}
15 changes: 9 additions & 6 deletions cargo-espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ pub enum Error {
#[error("No executable artifact found")]
#[diagnostic(
code(cargo_espflash::no_artifact),
help("If you're trying to run an example you need to specify it using the `--example` argument.\n\
If you're in a Cargo workspace, specify the binary package with `--package`.")
help(
"If you're trying to run an example you need to specify it using the `--example` argument.\n\
If you're in a Cargo workspace, specify the binary package with `--package`."
)
)]
NoArtifact,

Expand All @@ -46,8 +48,10 @@ pub enum Error {
#[error("No package could be located in the current workspace")]
#[diagnostic(
code(cargo_espflash::no_package),
help("Ensure that you are executing from a valid package, and that the specified package name \
exists in the current workspace.")
help(
"Ensure that you are executing from a valid package, and that the specified package name \
exists in the current workspace."
)
)]
NoPackage,

Expand Down Expand Up @@ -145,7 +149,6 @@ impl Diagnostic for NoTargetError {
chip.into_target().supported_build_targets().join(", ")
),
None => "Specify the target in `.cargo/config.toml`".into(),
}
))
}))
}
}
6 changes: 3 additions & 3 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::{
fs,
path::PathBuf,
process::{exit, Command, ExitStatus, Stdio},
process::{Command, ExitStatus, Stdio, exit},
};

use cargo_metadata::{Message, MetadataCommand};
use clap::{Args, CommandFactory, Parser, Subcommand};
use espflash::{
Error as EspflashError,
cli::{
self,
config::Config,
Expand All @@ -17,9 +18,8 @@ use espflash::{
logging::initialize_logger,
targets::{Chip, XtalFrequency},
update::check_for_update,
Error as EspflashError,
};
use log::{debug, info, LevelFilter};
use log::{LevelFilter, debug, info};
use miette::{IntoDiagnostic, Result, WrapErr};

use crate::{
Expand Down
4 changes: 2 additions & 2 deletions espflash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "espflash"
version = "4.0.0-dev"
edition = "2021"
rust-version = "1.82"
edition = "2024"
rust-version = "1.85"
description = "A command-line tool for interacting with Espressif devices"
repository = "https://github.com/esp-rs/espflash"
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions espflash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[![Crates.io](https://img.shields.io/crates/v/espflash?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/espflash)
[![docs.rs](https://img.shields.io/docsrs/espflash?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/espflash)
![MSRV](https://img.shields.io/badge/MSRV-1.82-blue?labelColor=1C2C2E&logo=Rust&style=flat-square)
![MSRV](https://img.shields.io/badge/MSRV-1.85-blue?labelColor=1C2C2E&logo=Rust&style=flat-square)
![Crates.io](https://img.shields.io/crates/l/espflash?labelColor=1C2C2E&style=flat-square)

A library and command-line tool for flashing Espressif devices.
Expand All @@ -27,7 +27,7 @@ Supports the **ESP32**, **ESP32-C2/C3/C6**, **ESP32-H2**, **ESP32-P4**, and **ES

## Installation

If you are installing `espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.82.0` installed on your system.
If you are installing `espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.85.0` installed on your system.

To install:

Expand Down
4 changes: 2 additions & 2 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{fs, path::PathBuf};

use clap::{Args, CommandFactory, Parser, Subcommand};
use espflash::{
Error,
cli::{
self,
config::Config,
Expand All @@ -12,9 +13,8 @@ use espflash::{
logging::initialize_logger,
targets::{Chip, XtalFrequency},
update::check_for_update,
Error,
};
use log::{debug, info, LevelFilter};
use log::{LevelFilter, debug, info};
use miette::{IntoDiagnostic, Result, WrapErr};

#[derive(Debug, Parser)]
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use miette::{IntoDiagnostic, Result, WrapErr};
use serde::{Deserialize, Serialize};
use serialport::UsbPortInfo;

use crate::{flasher::FlashSettings, Error};
use crate::{Error, flasher::FlashSettings};

/// A configured, known serial connection
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
Expand Down
8 changes: 4 additions & 4 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ use std::{

use clap::{Args, ValueEnum};
use clap_complete::Shell;
use comfy_table::{modifiers, presets::UTF8_FULL, Attribute, Cell, Color, Table};
use comfy_table::{Attribute, Cell, Color, Table, modifiers, presets::UTF8_FULL};
use esp_idf_part::{DataType, Partition, PartitionTable};
use indicatif::{style::ProgressStyle, HumanBytes, HumanCount, ProgressBar};
use indicatif::{HumanBytes, HumanCount, ProgressBar, style::ProgressStyle};
use log::{debug, info, warn};
use miette::{IntoDiagnostic, Result, WrapErr};
use serialport::{FlowControl, SerialPortInfo, SerialPortType, UsbPortInfo};

use self::{
config::Config,
monitor::{check_monitor_args, monitor, LogFormat},
monitor::{LogFormat, check_monitor_args, monitor},
};
use crate::{
connection::reset::{ResetAfterOperation, ResetBeforeOperation},
error::{Error, MissingPartition, MissingPartitionTable},
flasher::{
FLASH_SECTOR_SIZE,
FlashData,
FlashFrequency,
FlashMode,
FlashSettings,
FlashSize,
Flasher,
ProgressCallbacks,
FLASH_SECTOR_SIZE,
},
image_format::Metadata,
targets::{Chip, XtalFrequency},
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/cli/monitor/external_processors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//!
//! Example processor which turns some letters into uppercase
//! ```rust,no_run
//! use std::io::{stdin, stdout, Read, Write};
//! use std::io::{Read, Write, stdin, stdout};
//!
//! fn main() {
//! let args: Vec<String> = std::env::args().collect();
Expand Down
20 changes: 13 additions & 7 deletions espflash/src/cli/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
//! in our monitor the output is displayed immediately upon reading.

use std::{
io::{stdout, ErrorKind, Read, Write},
io::{ErrorKind, Read, Write, stdout},
time::Duration,
};

use crossterm::{
event::{poll, read, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers, poll, read},
terminal::{disable_raw_mode, enable_raw_mode},
};
use external_processors::ExternalProcessors;
Expand All @@ -28,10 +28,10 @@ use strum::{Display, EnumIter, EnumString, VariantNames};

use crate::{
cli::{
monitor::parser::{InputParser, ResolvingPrinter},
MonitorConfigArgs,
monitor::parser::{InputParser, ResolvingPrinter},
},
connection::{reset::reset_after_flash, Port},
connection::{Port, reset::reset_after_flash},
image_format::Metadata,
};

Expand Down Expand Up @@ -271,20 +271,26 @@ pub fn check_monitor_args(monitor: &bool, monitor_args: &MonitorConfigArgs) -> R
|| monitor_args.no_reset
|| monitor_args.monitor_baud != 115_200)
{
warn!("Monitor options were provided, but `--monitor/-M` flag isn't set. These options will be ignored.");
warn!(
"Monitor options were provided, but `--monitor/-M` flag isn't set. These options will be ignored."
);
}

// Check if log-format is used with serial but output-format is specified
if let Some(LogFormat::Serial) = monitor_args.log_format {
if monitor_args.output_format.is_some() {
warn!("Output format specified but log format is serial. The output format option will be ignored.");
warn!(
"Output format specified but log format is serial. The output format option will be ignored."
);
}
}

// Check if log-format is defmt but no ELF file is provided
if let Some(LogFormat::Defmt) = monitor_args.log_format {
if monitor_args.elf.is_none() {
warn!("Log format `defmt` requires an ELF file. Please provide one with the `--elf` option.");
warn!(
"Log format `defmt` requires an ELF file. Please provide one with the `--elf` option."
);
}
}

Expand Down
10 changes: 6 additions & 4 deletions espflash/src/cli/monitor/parser/esp_defmt.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::io::Write;

use crossterm::{style::Print, QueueableCommand};
use crossterm::{QueueableCommand, style::Print};
use defmt_decoder::{
log::format::{Formatter, FormatterConfig, FormatterFormat},
Frame,
Table,
log::format::{Formatter, FormatterConfig, FormatterFormat},
};
use log::warn;
use miette::{bail, ensure, Context, Diagnostic, Result};
use miette::{Context, Diagnostic, Result, bail, ensure};
use thiserror::Error;

use crate::cli::monitor::parser::InputParser;
Expand Down Expand Up @@ -144,7 +144,9 @@ impl DefmtData {
.map_err(|_e| DefmtError::LocationDataParseFailed)?;

let locs = if !table.is_empty() && locs.is_empty() {
warn!("Insufficient DWARF info; compile your program with `debug = 2` to enable location info.");
warn!(
"Insufficient DWARF info; compile your program with `debug = 2` to enable location info."
);
None
} else if table.indices().all(|idx| locs.contains_key(&(idx as u64))) {
Some(locs)
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/cli/monitor/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{borrow::Cow, io::Write, sync::LazyLock};

use crossterm::{
style::{Color, Print, PrintStyledContent, Stylize},
QueueableCommand,
style::{Color, Print, PrintStyledContent, Stylize},
};
use regex::Regex;

Expand Down
4 changes: 2 additions & 2 deletions espflash/src/cli/monitor/symbols.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::error::Error;

use addr2line::{
gimli::{self, Dwarf, EndianSlice, LittleEndian, SectionId},
Context,
LookupResult,
gimli::{self, Dwarf, EndianSlice, LittleEndian, SectionId},
};
use object::{read::File, Object, ObjectSection, ObjectSegment, ObjectSymbol};
use object::{Object, ObjectSection, ObjectSegment, ObjectSymbol, read::File};

// Wrapper around addr2line that allows to look up function names and
// locations from a given address.
Expand Down
6 changes: 3 additions & 3 deletions espflash/src/cli/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
use std::fs;

use crossterm::style::Stylize;
use dialoguer::{theme::ColorfulTheme, Confirm, Select};
use dialoguer::{Confirm, Select, theme::ColorfulTheme};
use log::{error, info};
use miette::{IntoDiagnostic, Result};
use serialport::{available_ports, SerialPortInfo, SerialPortType};
use serialport::{SerialPortInfo, SerialPortType, available_ports};

use crate::{
cli::{config::UsbDevice, Config, ConnectArgs},
Error,
cli::{Config, ConnectArgs, config::UsbDevice},
};

/// Return the information of a serial port taking into account the different
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/connection/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{io::Write, mem::size_of, time::Duration};

use bytemuck::{bytes_of, Pod, Zeroable};
use bytemuck::{Pod, Zeroable, bytes_of};
use strum::Display;

use crate::flasher::{SpiAttachParams, SpiSetParams};
Expand Down
12 changes: 6 additions & 6 deletions espflash/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ use self::{
command::{Command, CommandType},
encoder::SlipEncoder,
reset::{
construct_reset_strategy_sequence,
hard_reset,
reset_after_flash,
soft_reset,
ClassicReset,
ResetAfterOperation,
ResetBeforeOperation,
ResetStrategy,
UsbJtagSerialReset,
construct_reset_strategy_sequence,
hard_reset,
reset_after_flash,
soft_reset,
},
};
use crate::{
Expand Down Expand Up @@ -267,7 +267,7 @@ impl Connection {
return Err(Error::RomError(RomError::new(
CommandType::Sync,
RomErrorKind::InvalidMessage,
)))
)));
}
}
}
Expand Down Expand Up @@ -345,7 +345,7 @@ impl Connection {
return Err(Error::UnsupportedFeature {
chip,
feature: "watchdog reset".into(),
})
});
}
}

Expand Down
Loading
Loading