Skip to content

Make the update check an optional feature - #1080

Open
virzak wants to merge 3 commits into
esp-rs:mainfrom
virzak:feature/optional-update-check
Open

virzak wants to merge 3 commits into
esp-rs:mainfrom
virzak:feature/optional-update-check

Conversation

@virzak

@virzak virzak commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

The update check contacts crates.io on every run and pulls in update-informer with an HTTP and TLS stack. This moves it out of the cli feature into a new update-check feature, which is enabled by default, so nothing changes for cargo install espflash.

Distributions can now build the CLI without it via --no-default-features --features cli. OpenWrt asked for exactly that when packaging espflash (openwrt/packages#30659). There it also takes about 1 MB off the binary.

--skip-update-check is kept, so scripts that pass it keep working when the feature is off.

The update check contacts crates.io on every run and pulls in an HTTP
and TLS stack. Move it from the cli feature into a new update-check
feature, enabled by default, so distributions can build the CLI
without it via --no-default-features --features cli.

The --skip-update-check option is kept, so existing scripts that pass
it keep working when the feature is disabled.

Signed-off-by: Victor Irzak <victor@irzak.com>
Comment thread espflash/Cargo.toml

[features]
default = ["cli"]
default = ["cli", "update-check"]

@SergioGasquez SergioGasquez Oct 1, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the change, but, in theory, it would require a major version bump. Although I don't think any library user would be affected by this change.

A minor-compatible alternative: keep pub mod update gated on cli, and gate only the dependency and the function body on update-check:

  /// Check for updates
  #[cfg(feature = "cli")]
  pub mod update {
      /// Check for updates to the espflash crate.
      ///
      /// Does nothing unless the `update-check` feature is enabled.
      pub fn check_for_update(name: &str, version: &str) {
          #[cfg(feature = "update-check")]
          {
              use std::time::Duration;

              use log::info;
              use update_informer::{Check, registry::Crates};

              let informer =
                  update_informer::new(Crates, name, version).interval(Duration::from_secs(0));
              if let Some(version) = informer.check_version().ok().flatten() {
                  info!("🚀 A new version of {name} is available: {version}");
              }
          }
          #[cfg(not(feature = "update-check"))]
          let _ = (name, version);
      }
  }

This would still drop the HTTP and TSL stack on OpenWrt build.

We still have to decide if the next espflash version would be 5.0.0 or a minor version. We will have a plan for this at the end of the mont

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done in 247ef74: update and check_for_update() stay under cli, only the update-informer call is gated on update-check, and the binary change is reverted. Built with --no-default-features --features cli the binary still has no HTTP/TLS code.

Removing espflash::update when only cli is enabled would be a breaking
change for library users. Keep the module and check_for_update() under
cli, and gate only the update-informer call on update-check, so the
function does nothing when the feature is disabled.

Signed-off-by: Victor Irzak <victor@irzak.com>
@virzak virzak mentioned this pull request Oct 1, 2026
4 tasks done

@SergioGasquez SergioGasquez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we dont test this config, we should add

  - run: RUSTFLAGS="-D warnings" cargo check -p espflash --no-default-features --features cli

To https://github.com/esp-rs/espflash/blob/main/.github/workflows/ci.yml#L89-L90

Comment thread espflash/Cargo.toml Outdated
]

# Checks crates.io for a newer release on every run of the CLI
update-check = ["dep:update-informer"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
update-check = ["dep:update-informer"]
update-check = ["cli", "dep:update-informer"]

Otherwise update-check doesn't turn on cli and with --no-default-features --features update-check, the dependency gets pulled in but the update module isn't compiled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 267d78b, together with the CI step for --no-default-features --features cli.

Without cli, update-check pulled in update-informer but did not compile
the update module. Also add a CI step for --no-default-features
--features cli, which builds the CLI without the update check.

Signed-off-by: Victor Irzak <victor@irzak.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants