Skip to content

perf(deploy): make espflash a build-time-optional cargo feature#139

Merged
zackees merged 1 commit intomainfrom
spike/espflash-native-verify
Apr 19, 2026
Merged

perf(deploy): make espflash a build-time-optional cargo feature#139
zackees merged 1 commit intomainfrom
spike/espflash-native-verify

Conversation

@zackees
Copy link
Copy Markdown
Member

@zackees zackees commented Apr 19, 2026

Summary

Touches issue #66 but not in the originally-requested direction. The espflash-based verify+write migration already landed in PRs #74 / #106 — the remaining observable cost is that every fbuild build pulls espflash (and its ~30 transitive deps: strum, deku, miette, esp-idf-part, ...) whether or not the operator ever sets FBUILD_USE_ESPFLASH_*.

This PR walks that back: espflash + md-5 become optional in fbuild-deploy, and a new espflash-native cargo feature on fbuild-deploy + fbuild-daemon gates them in.

Change

Default build (new behaviour):

  • espflash, md-5, and their transitive deps are not compiled.
  • esp32_native.rs is not compiled.
  • FBUILD_USE_ESPFLASH_VERIFY / FBUILD_USE_ESPFLASH_WRITE are ignored; the daemon always takes the esptool-subprocess path.
  • Sole trade-off: operators who relied on those env vars on a stock build need to rebuild with --features fbuild-daemon/espflash-native.

--features espflash-native build:

  • Identical runtime behaviour to today's main. Env vars still pick native-vs-esptool.

Feature gates (what is cfg-gated)

  • fbuild-deploy: pub mod esp32_native; Esp32Deployer::{use_native_verify, use_native_write} struct fields; Esp32Deployer::{with_native_verify, with_native_write} builders; try_verify_deployment_native, try_deploy_native helper fns. Native-path dispatch arms inside the public methods are also #[cfg(feature = "espflash-native")].
  • fbuild-daemon: native_verify_enabled / native_write_enabled helper fns, plus the sole call site that wires with_native_{verify,write}.

Quality gates (verified locally on Windows 10)

  • uv run cargo clippy --workspace --all-targets -- -D warnings — clean (default, no feature).
  • uv run cargo clippy --workspace --all-targets --features fbuild-daemon/espflash-native -- -D warnings — clean.
  • uv run cargo test -p fbuild-deploy — 36 pass, 0 fail, 8 ignored.
  • uv run cargo fmt --all --check — clean.

Scope / Non-goals

  • Does not remove any existing code paths.
  • Does not drop esptool as a dep.
  • Does not change the env-var contract (besides "only honoured when the feature is on").
  • Does not attempt to measure the binary-size / build-time delta — that's for a follow-up once CI picks it up.

Test plan

  • CI green across Linux / macOS / Windows.
  • Build-time delta on the default profile is measurable vs current main (expect several seconds faster cold build, ~30 fewer crates downloaded).

🤖 Generated with Claude Code

The espflash crate (pulled in by PRs #74, #106, and the FLASH_MD5SUM
verify path) ships with ~30 transitive deps (strum, deku, miette,
esp-idf-part, ...). Those deps were being pulled into every fbuild
build whether or not the operator ever set FBUILD_USE_ESPFLASH_*.

Make espflash and md-5 optional in fbuild-deploy, introduce an
`espflash-native` cargo feature that turns them on, and forward the
feature from fbuild-daemon. Gate the runtime toggles (`with_native_*`
builders, env-var check helpers, call sites) behind the same cfg, so
the struct layout, helper fns, and daemon routing only pay their
cost when the feature is enabled.

Runtime behaviour when the feature IS enabled is unchanged: the
FBUILD_USE_ESPFLASH_VERIFY / FBUILD_USE_ESPFLASH_WRITE env vars
still control the native-vs-esptool choice.

Runtime behaviour when the feature is disabled (the new default):
FBUILD_USE_ESPFLASH_* are ignored; esptool subprocess is the only
path. Operators who relied on those env vars on a stock build need
to rebuild with `--features fbuild-daemon/espflash-native`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

Warning

Rate limit exceeded

@zackees has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 9 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 14 minutes and 9 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4f4f640c-08fb-4344-8da7-66264ed7d0e0

📥 Commits

Reviewing files that changed from the base of the PR and between 6e03e9b and 32e11ab.

📒 Files selected for processing (5)
  • crates/fbuild-daemon/Cargo.toml
  • crates/fbuild-daemon/src/handlers/operations.rs
  • crates/fbuild-deploy/Cargo.toml
  • crates/fbuild-deploy/src/esp32.rs
  • crates/fbuild-deploy/src/lib.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch spike/espflash-native-verify

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees zackees merged commit 41de280 into main Apr 19, 2026
3 of 77 checks passed
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.

1 participant