mirror of
https://github.com/esp-rs/espflash.git
synced 2026-03-19 05:45:12 +00:00
Fix building as a library, add CI check to avoid breaking again in the future (#282)
* Refactor to allow building as a library, without the `cli` feature * Build `espflash` as a library in CI * Make more dependencies optional
This commit is contained in:
4
.github/workflows/raspberry_rust.yml
vendored
4
.github/workflows/raspberry_rust.yml
vendored
@@ -27,6 +27,10 @@ jobs:
|
||||
toolchain: stable
|
||||
cargo-command: check
|
||||
args: --features=raspberry
|
||||
- name: Check (lib)
|
||||
toolchain: stable
|
||||
cargo-command: check
|
||||
args: --lib --no-default-features --features=raspberry
|
||||
- name: Check MSRV
|
||||
toolchain: "1.62"
|
||||
cargo-command: check
|
||||
|
||||
21
.github/workflows/rust.yml
vendored
21
.github/workflows/rust.yml
vendored
@@ -31,6 +31,27 @@ jobs:
|
||||
with:
|
||||
command: check
|
||||
|
||||
check-lib:
|
||||
name: Check (lib)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Change apt mirror and install dependencies
|
||||
run: |
|
||||
sudo sed -i 's/azure.archive.ubuntu.com/archive.ubuntu.com/' /etc/apt/sources.list
|
||||
sudo apt-get update
|
||||
sudo apt-get install musl-tools libudev-dev
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --lib --no-default-features
|
||||
|
||||
msrv:
|
||||
name: Check MSRV
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -35,27 +35,27 @@ path = "./src/bin/espflash.rs"
|
||||
required-features = ["cli"]
|
||||
|
||||
[dependencies]
|
||||
addr2line = "0.18.0"
|
||||
addr2line = { version = "0.18.0", optional = true }
|
||||
base64 = "0.13.1"
|
||||
binread = "2.2.0"
|
||||
bytemuck = { version = "1.12.1", features = ["derive"] }
|
||||
clap = { version = "4.0.18", features = ["derive"], optional = true }
|
||||
comfy-table = "6.1.2"
|
||||
comfy-table = { version = "6.1.2", optional = true }
|
||||
crossterm = { version = "0.25.0", optional = true }
|
||||
dialoguer = { version = "0.10.2", optional = true }
|
||||
directories-next = "2.0.0"
|
||||
directories-next = { version = "2.0.0", optional = true }
|
||||
esp-idf-part = "0.1.1"
|
||||
env_logger = { version = "0.9.1", optional = true }
|
||||
flate2 = "1.0.24"
|
||||
indicatif = "0.17.1"
|
||||
lazy_static = "1.4.0"
|
||||
lazy_static = { version = "1.4.0", optional = true }
|
||||
log = "0.4.17"
|
||||
miette = { version = "5.3.0", features = ["fancy"] }
|
||||
parse_int = "0.6.0"
|
||||
regex = "1.6.0"
|
||||
parse_int = { version = "0.6.0", optional = true }
|
||||
regex = { version = "1.6.0", optional = true }
|
||||
rppal = { version = "0.13.1", optional = true }
|
||||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
serde-hex = "0.1.0"
|
||||
serde-hex = { version = "0.1.0", optional = true }
|
||||
serialport = "4.2.0"
|
||||
sha2 = "0.10.6"
|
||||
slip-codec = "0.3.3"
|
||||
@@ -67,5 +67,9 @@ xmas-elf = "0.8.0"
|
||||
|
||||
[features]
|
||||
default = ["cli"]
|
||||
cli = ["dep:clap", "dep:crossterm", "dep:dialoguer", "dep:env_logger", "dep:update-informer"]
|
||||
cli = [
|
||||
"dep:addr2line", "dep:clap", "dep:comfy-table", "dep:crossterm", "dep:dialoguer",
|
||||
"dep:directories-next", "dep:env_logger", "dep:lazy_static", "dep:parse_int",
|
||||
"dep:regex", "dep:serde-hex", "dep:update-informer"
|
||||
]
|
||||
raspberry = ["dep:rppal"]
|
||||
|
||||
@@ -176,7 +176,15 @@ pub fn connect(args: &ConnectArgs, config: &Config) -> Result<Flasher> {
|
||||
info!("Serial port: '{}'", port_info.port_name);
|
||||
info!("Connecting...");
|
||||
|
||||
let interface = Interface::new(&port_info, args, config)
|
||||
#[cfg(feature = "raspberry")]
|
||||
let (dtr, rts) = (
|
||||
args.dtr.or(config.connection.dtr),
|
||||
args.rts.or(config.connection.rts),
|
||||
);
|
||||
#[cfg(not(feature = "raspberry"))]
|
||||
let (dtr, rts) = (None, None);
|
||||
|
||||
let interface = Interface::new(&port_info, dtr, rts)
|
||||
.wrap_err_with(|| format!("Failed to open serial port {}", port_info.port_name))?;
|
||||
|
||||
// NOTE: since `get_serial_port_info` filters out all PCI Port and Bluetooth
|
||||
|
||||
@@ -5,17 +5,13 @@ use miette::{Context, Result};
|
||||
use rppal::gpio::{Gpio, OutputPin};
|
||||
use serialport::{FlowControl, SerialPort, SerialPortInfo};
|
||||
|
||||
use crate::{
|
||||
cli::{config::Config, ConnectArgs},
|
||||
error::Error,
|
||||
};
|
||||
use crate::error::Error;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum SerialConfigError {
|
||||
#[cfg(feature = "raspberry")]
|
||||
#[error("You need to specify both DTR and RTS pins when using an internal UART peripheral")]
|
||||
MissingDtrRtsForInternalUart,
|
||||
|
||||
#[cfg(feature = "raspberry")]
|
||||
#[error("GPIO {0} is not available")]
|
||||
GpioUnavailable(u8),
|
||||
@@ -55,14 +51,11 @@ impl Interface {
|
||||
#[cfg(feature = "raspberry")]
|
||||
pub(crate) fn new(
|
||||
port_info: &SerialPortInfo,
|
||||
args: &ConnectArgs,
|
||||
config: &Config,
|
||||
dtr: Option<u8>,
|
||||
rts: Option<u8>,
|
||||
) -> Result<Self> {
|
||||
let rts_gpio = args.rts.or(config.connection.rts);
|
||||
let dtr_gpio = args.dtr.or(config.connection.dtr);
|
||||
|
||||
if port_info.port_type == serialport::SerialPortType::Unknown
|
||||
&& (dtr_gpio.is_none() || rts_gpio.is_none())
|
||||
&& (dtr.is_none() || rts.is_none())
|
||||
{
|
||||
// Assume internal UART, which has no DTR pin and usually no RTS either.
|
||||
return Err(Error::from(SerialConfigError::MissingDtrRtsForInternalUart).into());
|
||||
@@ -70,7 +63,7 @@ impl Interface {
|
||||
|
||||
let gpios = Gpio::new().unwrap();
|
||||
|
||||
let rts = if let Some(gpio) = rts_gpio {
|
||||
let rts = if let Some(gpio) = rts {
|
||||
match gpios.get(gpio) {
|
||||
Ok(pin) => Some(pin.into_output()),
|
||||
Err(_) => return Err(Error::from(SerialConfigError::GpioUnavailable(gpio)).into()),
|
||||
@@ -79,7 +72,7 @@ impl Interface {
|
||||
None
|
||||
};
|
||||
|
||||
let dtr = if let Some(gpio) = dtr_gpio {
|
||||
let dtr = if let Some(gpio) = dtr {
|
||||
match gpios.get(gpio) {
|
||||
Ok(pin) => Some(pin.into_output()),
|
||||
Err(_) => return Err(Error::from(SerialConfigError::GpioUnavailable(gpio)).into()),
|
||||
@@ -98,8 +91,8 @@ impl Interface {
|
||||
#[cfg(not(feature = "raspberry"))]
|
||||
pub(crate) fn new(
|
||||
port_info: &SerialPortInfo,
|
||||
_args: &ConnectArgs,
|
||||
_config: &Config,
|
||||
_dtr: Option<u8>,
|
||||
_rts: Option<u8>,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
serial_port: open_port(port_info)?,
|
||||
|
||||
Reference in New Issue
Block a user