Repository: esp-rs/espflash (language: rust)

Issue:
Investigate if we need to depend on libudev
`serialport` can now work without `libudev`, see https://github.com/serialport/serialport-rs/pull/220, this can lead to weird ports being shown but it might be worth to explore how this performs, some initial tests show good signs, see https://github.com/esp-rs/espflash/pull/709


Discussion / hints:
Do we know how/if this affects Linux systems based on MUSL? IIRC we have some custom logic for these systems in our port detection code, perhaps it is no longer necessary if `serialport` is now reading port info directly from `/sys/`.
> Do we know how/if this affects Linux systems based on MUSL? 

No idea, @sirhcel sorry for the ping, do you have any idea on this?


> Do we know how/if this affects Linux systems based on MUSL? IIRC we have some custom logic for these systems in our port detection code, perhaps it is no longer necessary if `serialport` is now reading port info directly from `/sys/`.

Especially since https://github.com/serialport/serialport-rs/pull/220 things look almost shiny even without libudev. On my test system, two serial ports from a PCIe card are missing, but `ttyS0` from the main board and the USB ports are reported identically now (as of [944e9e9](https://github.com/serialport/serialport-rs/commits/944e9e9a50164c784c8ed1e3293dd955c5ef2294/), serial numbers redacted):

```
$ cargo run --target x86_64-unknown-linux-gnu --features usbportinfo-interface --example list_ports
[...]
Found 7 ports:
    /dev/ttyS0
        Type: Unknown
    /dev/ttyS4
        Type: PCI
    /dev/ttyS5
        Type: PCI
    /dev/ttyUSB2
        Type: USB
        VID: 0403
        PID: 6001
        Interface: 00
        Serial Number: FTFOO
        Manufacturer: FTDI
        Product: UT232R
    /dev/ttyUSB3
        Type: USB
        VID: 0403
        PID: 6010
        Interface: 00
        Serial Number: FTBAR
        Manufacturer: FTDI
        Product: FT2232H MiniModule
    /dev/ttyUSB4
        Type: USB
        VID: 0403
        PID: 6010
        Interface: 01
        Serial Number: FTBAR
        Manufacturer: FTDI
        Product: FT2232H MiniModule
    /dev/ttyUSB5
        Type: USB
        VID: 10c4
        PID: ea60
        Interface: 00
        Serial Number: YOURCP2102NSERIALHERE
        Manufacturer: Silicon Labs
        Product: CP2102N USB to UART Bridge Controller
```
```
$ cargo run --target x86_64-unknown-linux-musl --no-default-features --features usbportinfo-interface --example list_ports
[...]
Found 5 ports:
    /dev/ttyS0
        Type: Unknown
    /dev/ttyUSB2
        Type: USB
        VID: 0403
        PID: 6001
        Interface: 00
        Serial Number: FTFOO
        Manufacturer: FTDI
        Product: UT232R
    /dev/ttyUSB3
        Type: USB
        VID: 0403
        PID: 6010
        Interface: 00
        Serial Number: FTBAR
        Manufacturer: FTDI
        Product: FT2232H MiniModule
    /dev/ttyUSB4
        Type: USB
        VID: 0403
        PID: 6010
        Interface: 01
        Serial Number: FTBAR
        Manufacturer: FTDI
        Product: FT2232H MiniModule
    /dev/ttyUSB5
        Type: USB
        VID: 10c4
        PID: ea60
        Interface: 00
        Serial Number: YOURCP2102NSERIALHERE
        Manufacturer: Silicon Labs
        Product: CP2102N USB to UART Bridge Controller
``` 

Do you have some secret sauce for PCI port detection in place at espflash you can give we a reference to? I would love to get the port enumeration with and without libudev at a par.
> Do you have some secret sauce for PCI port detection in place at espflash you can give we a reference to? I would love to get the port enumeration with and without libudev at a par.

[Here is where all the finding/selecting of serial ports](https://github.com/esp-rs/espflash/blob/main/espflash/src/cli/serial.rs)  happens, the only "magic" that we do is with linux-musl that we parse sysfs, see the two implementations of `detect_usb_serial_ports`



Thank you for the reference @SergioGasquez! At a first glance, it looks like the USB ports enumerated by espflash should be enumerated by serialport-rs as well. But the enumeration will additionally return some more ports from the motherboard of my Linux machine from https://github.com/esp-rs/espflash/issues/711#issuecomment-2557658853. So the result from using the non-libudev enumeration from serialport-rs will be "between" espflash's enumeration without and with libudev.

The discrepancy between the devices enumerated by libudev and our manual for MUSL/non-libudev is bugging me since a while and I found some time to look into it and https://github.com/serialport/serialport-rs/pull/238 sets out to close this gap and should bring the enumeration en par with libudev.

Do you have some interesting corner cases from the enumeration done by espflash? May be there is something relevant for serialport-rs too.
> Do you have some interesting corner cases from the enumeration done by espflash?

I dont recall any

https://github.com/serialport/serialport-rs/pull/238 looks promising, maybe we can do some tests after it lands. We are working on planning espflash v4, so this should definitely be investigated.

Fix patch:
diff --git a/.github/actions/setup-target/action.yml b/.github/actions/setup-target/action.yml
index 3b9befaa..18d4ecab 100644
--- a/.github/actions/setup-target/action.yml
+++ b/.github/actions/setup-target/action.yml
@@ -50,9 +50,6 @@ runs:
           git \
           "libc6:${{ inputs.arch }}" \
           "libgcc-s1:${{ inputs.arch }}" \
-          libudev-dev \
-          "libudev-dev:${{ inputs.arch }}" \
-          "libudev1:${{ inputs.arch }}" \
           musl-tools \
           pkg-config
 
@@ -60,7 +57,7 @@ runs:
       if: inputs.target == 'x86_64-unknown-linux-gnu' || inputs.target == 'x86_64-unknown-linux-musl'
       shell: bash
       run: |
-        sudo apt-get update && sudo apt-get -y install musl-tools libudev-dev pkg-config
+        sudo apt-get update && sudo apt-get -y install musl-tools pkg-config
 
     - name: Set environment variables
       if: inputs.arch != 'x86_64'
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index c6d73bb7..d916ced0 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -41,7 +41,6 @@ jobs:
             arch: "x86_64"
     runs-on: ${{ matrix.platform.os }}
     steps:
-
       - uses: actions/checkout@v4
 
       - uses: ./.github/actions/package
@@ -51,12 +50,10 @@ jobs:
           target: ${{ matrix.platform.target }}
           runs_on: ${{ matrix.platform.os }}
 
-
   publish-cratesio:
     name: Publish to Crates.io
     runs-on: ubuntu-20.04
     steps:
-
       - uses: actions/checkout@v4
 
       - name: Install Rust toolchain
@@ -68,7 +65,7 @@ jobs:
         uses: Swatinem/rust-cache@v2
 
       - name: Install dependencies
-        run: sudo apt-get update && sudo apt-get install musl-tools libudev-dev
+        run: sudo apt-get update && sudo apt-get install musl-tools
 
       - name: Publish espflash
         run: |
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6485bae0..f835a521 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,11 +12,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Changed
 
 ### Fixed
+
 - Update the app image SHA in the correct location for padded images (#715)
 - Fix `-s` argument collision (#731)
 
 ### Removed
 
+- Removed the `libudev` feature (#742)
+
 ## [3.3.0] - 2025-01-13
 
 ### Added
diff --git a/Cargo.lock b/Cargo.lock
index 1ca51f4a..8d145b8b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2899,26 +2899,6 @@ dependencies = [
  "vcpkg",
 ]
 
-[[package]]
-name = "libudev"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "78b324152da65df7bb95acfcaab55e3097ceaab02fb19b228a9eb74d55f135e0"
-dependencies = [
- "libc",
- "libudev-sys",
-]
-
-[[package]]
-name = "libudev-sys"
-version = "0.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324"
-dependencies = [
- "libc",
- "pkg-config",
-]
-
 [[package]]
 name = "libz-sys"
 version = "1.1.21"
@@ -4022,16 +4002,15 @@ dependencies = [
 
 [[package]]
 name = "serialport"
-version = "4.6.1"
+version = "4.7.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "779e2977f0cc2ff39708fef48f96f3768ac8ddd8c6caaaab82e83bd240ef99b2"
+checksum = "5ecfc4858c2266c7695d8b8460bbd612fa81bd2e250f5f0dd16195e4b4f8b3d8"
 dependencies = [
  "bitflags 2.7.0",
  "cfg-if",
  "core-foundation",
  "core-foundation-sys",
  "io-kit-sys",
- "libudev",
  "mach2",
  "nix 0.26.4",
  "scopeguard",
diff --git a/cargo-espflash/README.md b/cargo-espflash/README.md
index 0c94f177..308dabf6 100644
--- a/cargo-espflash/README.md
+++ b/cargo-espflash/README.md
@@ -25,16 +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.76.0` installed on your system.
-
-If you are running **Linux** then [libudev] must also be installed; this is available via most popular package managers. If you are running **Windows** or **macOS** you can ignore this step.
-
-```bash
-# Debian/Ubuntu/etc.
-apt-get install libudev-dev
-# Fedora
-dnf install systemd-devel
-```
+If you are installing `cargo-espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.82.0` installed on your system.
 
 To install:
 
@@ -54,7 +45,6 @@ By default, in Unix systems, we use the [`vendored-openssl` Cargo feature] which
 OPENSSL_NO_VENDOR=1 cargo install cargo-espflash
 ```
 
-[libudev]: https://www.freedesktop.org/software/systemd/man/latest/libudev.html
 [cargo-binstall]: https://github.com/cargo-bins/cargo-binstall
 [releases]: https://github.com/esp-rs/espflash/releases
 [`vendored-openssl` Cargo feature]: https://github.com/rust-lang/cargo#compiling-from-source
diff --git a/espflash/Cargo.toml b/espflash/Cargo.toml
index c49d3c05..530e02bf 100644
--- a/espflash/Cargo.toml
+++ b/espflash/Cargo.toml
@@ -47,7 +47,7 @@ miette          = "7.4.0"
 parse_int       = { version = "0.6.0", optional = true }
 regex           = { version = "1.11.1", optional = true }
 serde           = { version = "1.0.217", features = ["derive"] }
-serialport      = { version = "4.6.1", default-features = false, optional = true }
+serialport      = { version = "4.7.0", default-features = false, optional = true }
 sha2            = "0.10.8"
 slip-codec      = { version = "0.4.0", optional = true }
 strum           = { version = "0.26.3", features = ["derive"] }
@@ -60,8 +60,7 @@ xmas-elf        = "0.9.1"
 libc = "0.2.169"
 
 [features]
-default = ["cli", "libudev"]
-libudev = ["serialport?/libudev"]
+default = ["cli"]
 cli = [
     "dep:addr2line",
     "dep:clap",
diff --git a/espflash/README.md b/espflash/README.md
index fa3f8218..ead03e6e 100644
--- a/espflash/README.md
+++ b/espflash/README.md
@@ -27,16 +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.76.0` installed on your system.
-
-If you are running **Linux** then [libudev] must also be installed; this is available via most popular package managers. If you are running **Windows** or **macOS** you can ignore this step.
-
-```bash
-# Debian/Ubuntu/etc.
-apt-get install libudev-dev
-# Fedora
-dnf install systemd-devel
-```
+If you are installing `espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.82.0` installed on your system.
 
 To install:
 
@@ -50,7 +41,6 @@ Alternatively, you can use [cargo-binstall] to download pre-compiled artifacts f
 cargo binstall espflash
 ```
 
-[libudev]: https://www.freedesktop.org/software/systemd/man/latest/libudev.html
 [cargo-binstall]: https://github.com/cargo-bins/cargo-binstall
 [releases]: https://github.com/esp-rs/espflash/releases
 


Test patch: