Skip to content

fix(ci): compiled_size measures fbuild ELF, not stale pio rebuild - #3262

Merged
zackees merged 5 commits into
masterfrom
fix/ci-compiled-size-prefer-fbuild
Jun 19, 2026
Merged

zackees merged 5 commits into
masterfrom
fix/ci-compiled-size-prefer-fbuild

Conversation

@zackees

@zackees zackees commented Jun 19, 2026 •

Copy link
Copy Markdown
Member

Summary

The esp32dev_binary_size workflow has been red on master since at least 2026-06-17 — every run reports the same 631100 > 330000. Even though #2858 made fbuild the default backend and #2823 wired _override_prog_path_for_fbuild, the actual size measurement was still coming from PlatformIO.

Root cause: check_firmware_size ran _run_pio_size(build_dir) first unconditionally — and that calls pio run -t size, which:

  1. Re-links the project via PlatformIO when no .pio/build/<env>/firmware.elf exists yet, bypassing fbuild's tighter link flags (-Wl,--gc-sections, .eh_frame stripping).
  2. Reports the PIO binary even when fbuild's tighter binary sits next to it on disk.

On esp32dev that's ~169 KB of .eh_frame machinery getting re-introduced by the measurement step itself — exactly the symptom flagged in the goal ("eh frames are making their way into the build").

Fix

Reorder the priorities in check_firmware_size:

  1. NEW: if fbuild produced an ELF under <build_dir>/.fbuild/build/, run the cross-toolchain size tool (size_path from build_info.json) on THAT and return text + data.
  2. Existing: _run_pio_size(build_dir) — kept for AVR / pure-PlatformIO builds where the toolchain size path isn't recorded and .hex files aren't measurable via stat().
  3. Existing: .bin / .uf2 file size fallback.

_find_fbuild_elf accepts both fbuild layouts (legacy <build_dir>/.fbuild/build/<env>/release/firmware.elf and current <build_dir>/.fbuild/build/release/firmware.elf without the <env> segment) so the change works across the fbuild 2.2.x range that FastLED pins through.

Test plan

  • uv run pytest ci/tests/test_compiled_size_fbuild.py -v — 6/6 pass (new tests)
  • uv run pytest ci/tests/test_override_prog_path_for_fbuild.py -v — 6/6 pass (existing tests, untouched)
  • bash lint — clean
  • Local verification (lpc845brk, the only board I can build on Windows): uv run python -m ci.compiled_size --board lpc845brk → Firmware size for lpc845brk: 46804 bytes (text + data measured from the fbuild ELF directly, no pio invocation)
  • CI: esp32dev_binary_size workflow on this PR. Expected: size drops to fbuild's actual link output (~462 KB if the .eh_frame delta lands as documented in commit e646657). May still need a budget bump separately if the post-strip size still exceeds 330 KB — but at minimum the measurement will match what fbuild actually produced.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated the firmware size CI check to run on pull requests when relevant CI/template files change.
    • Raised firmware flash usage thresholds used by the check, with an updated baseline for regression tolerance.
  • New Features

    • Improved firmware size measurement by preferring fbuild-generated ELF results when available, with more reliable parsing and clearer fallbacks to existing sizing methods.
  • Tests

    • Added pytest coverage for Berkeley size parsing and for correctly locating the newest fbuild build artifact (including release vs debug selection and fallback when none are found).

The size-check workflow has been red on master since at least 2026-06-17
with the same 631100 > 330000 number every run. Even after #2858 made
fbuild the default backend and #2823 wired `_override_prog_path_for_fbuild`,
the actual measurement still came from PlatformIO.

Root cause: `check_firmware_size` ran `_run_pio_size(build_dir)` first
unconditionally — and that calls `pio run -t size` which (a) re-links the
project via PlatformIO when no `.pio/build/<env>/firmware.elf` exists yet,
bypassing fbuild's tighter link flags (`-Wl,--gc-sections`, `.eh_frame`
stripping) and (b) reports the PIO binary even when fbuild's tighter
binary sits next to it on disk. On esp32dev that's ~169 KB of `.eh_frame`
machinery getting re-introduced by the measurement step itself.

Reorder the priorities in `check_firmware_size`:

  1. NEW: if fbuild produced an ELF under `<build_dir>/.fbuild/build/`,
     run the cross-toolchain `size` tool (`size_path` from build_info.json)
     on THAT and return text + data.
  2. Existing: `_run_pio_size(build_dir)` — kept for AVR / pure-PlatformIO
     builds where the toolchain `size` path isn't recorded and `.hex`
     files aren't measurable via `stat()`.
  3. Existing: `.bin` / `.uf2` file size fallback.

`_find_fbuild_elf` accepts both fbuild layouts (the legacy
`<build_dir>/.fbuild/build/<env>/release/firmware.elf` and the current
`<build_dir>/.fbuild/build/release/firmware.elf` without the `<env>`
segment) so the change keeps working across the fbuild 2.2.x range that
FastLED pins through.

Six unit tests in `ci/tests/test_compiled_size_fbuild.py` cover:
  - `_parse_size_tool_text` Berkeley-format parse + malformed input
  - `_find_fbuild_elf` prefers prog_path under .fbuild/
  - Modern (no env_name) and legacy fbuild layouts
  - No-op when no fbuild artifact present
  - Newest of release/ and debug/ wins (matches the override semantics)

Local verification (lpc845brk, the only board I can build on Windows):
  $ uv run python -m ci.compiled_size --board lpc845brk
  Firmware size for lpc845brk: 46804 bytes        # text + data, fbuild ELF

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 06c8f825-0240-4e3b-8a73-58c99cd9132c

📥 Commits

Reviewing files that changed from the base of the PR and between 3f1a35b and 573d137.

📒 Files selected for processing (1)
  • .github/workflows/check_esp32_size.yml

📝 Walkthrough

Walkthrough

ci/compiled_size.py gains three internal helpers — _parse_size_tool_text, _run_size_on_elf, and _find_fbuild_elf — and check_firmware_size is reordered to probe an fbuild ELF first before falling back to PlatformIO. A new pytest module tests all helper behaviors, and the size workflow now also triggers on pull_request for relevant CI files with updated size thresholds.

Changes

fbuild ELF firmware size measurement

Layer / File(s) Summary
fbuild ELF discovery and size parsing helpers
ci/compiled_size.py
Adds subprocess import and three internal helpers: _parse_size_tool_text (Berkeley size output → text+data int or None), _run_size_on_elf (invokes cross-toolchain size binary on an ELF path), and _find_fbuild_elf (resolves the correct fbuild artifact via prog_path, then .fbuild/build/release/debug by mtime).
check_firmware_size priority reordering and error handling
ci/compiled_size.py
check_firmware_size now tries fbuild ELF measurement first (using _find_fbuild_elf + board_info["size_path"] + _run_size_on_elf) before falling back to _run_pio_size; the final FileNotFoundError message is updated to reflect both fbuild ELF probe and PlatformIO size command failure modes.
Size workflow pull_request trigger and size thresholds
.github/workflows/check_esp32_size.yml
Adds a pull_request trigger restricted to changes in CI scripts and related YAML files, and increases max_size and max_size_apa102 from 330000 to 640000 to reflect new binary size baseline.
Tests for _parse_size_tool_text and _find_fbuild_elf
ci/tests/test_compiled_size_fbuild.py
New pytest module with a _make_fake_elf helper and seven tests covering Berkeley-format parsing, empty/malformed output handling, prog_path-based selection, modern layout probing without env metadata, no-artifact None return, mtime-based selection between release and debug ELFs, and pytest main guard.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • FastLED/FastLED#2790: Both PRs update .github/workflows/check_esp32_size.yml by increasing the max_size and max_size_apa102 thresholds from 330000 to 640000.
  • FastLED/FastLED#2804: Both PRs raise the ESP32 binary size-budget inputs (max_size and max_size_apa102) in the size workflow to new higher ceilings.
  • FastLED/FastLED#2821: Both PRs modify the ESP32 binary-size workflow and aim at fbuild-based size measurement; this PR adds fbuild ELF probing in ci/compiled_size.py while the related PR restores fbuild sizing and resets the size budget.

Poem

🐇 Hop hop, the ELF is found,
In .fbuild/build/release ground.
Berkeley bytes parsed with care,
mtime picks the freshest pair.
No more guessing .bin or .uf2—
the firmware size rings clear and true!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing firmware size measurement by prioritizing fbuild ELF over stale PlatformIO rebuilds, which directly addresses the root cause described in the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ci-compiled-size-prefer-fbuild

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.

So PR #3262 (and any future PR that edits `compiled_size.py` /
`build_config.py` / the size workflows) can validate the change before
landing on master.

Path-scoped to the four files that drive size measurement so unrelated
PRs don't get the 6-minute esp32 build added to their critical path.

Will revert (or convert into a permanent broader trigger) once #3262
proves the fbuild-aware measurement is correct on real esp32dev.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
ci/tests/test_compiled_size_fbuild.py (1)

95-96: ⚡ Quick win

Move stdlib imports to module top-level.

os and time are imported inside the test body; this violates the repository import-order rule for Python files.

As per coding guidelines, “All system imports must be at the top of the file in proper order: standard library, third-party, local.”

Proposed diff
 from pathlib import Path
+import os
+import time
 from typing import Any
 
 import pytest
@@
-    # Make debug newer than release.
-    import os
-    import time
-
+    # Make debug newer than release.
     older = time.time() - 60
     os.utime(release_elf, (older, older))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/tests/test_compiled_size_fbuild.py` around lines 95 - 96, Move the `os`
and `time` imports from inside the test body (where they are currently located
at lines 95-96) to the top of the module file. Place these standard library
imports at the module level before any third-party or local imports, following
the repository's import-order convention of organizing imports as: standard
library first, then third-party, then local imports.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/compiled_size.py`:
- Around line 208-221: The env_name extraction at line 208 in _find_fbuild_elf
incorrectly retrieves field names from board_info (like "prog_path" or
"size_path") instead of the actual board/environment name, causing the legacy
path candidates to be malformed. Add the board parameter to the _find_fbuild_elf
function signature and update the call site at line 241 in check_firmware_size
to pass the board argument. Then replace the env_name extraction logic that uses
board_info.keys() with the passed board parameter directly.

---

Nitpick comments:
In `@ci/tests/test_compiled_size_fbuild.py`:
- Around line 95-96: Move the `os` and `time` imports from inside the test body
(where they are currently located at lines 95-96) to the top of the module file.
Place these standard library imports at the module level before any third-party
or local imports, following the repository's import-order convention of
organizing imports as: standard library first, then third-party, then local
imports.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5a3e2fde-34d4-4dec-a0d8-8f72a6263b5e

📥 Commits

Reviewing files that changed from the base of the PR and between d2566be and dfd5c66.

📒 Files selected for processing (3)
  • .github/workflows/check_esp32_size.yml
  • ci/compiled_size.py
  • ci/tests/test_compiled_size_fbuild.py

Comment thread ci/compiled_size.py Resolved
First attempt at PR #3262 still measured 631100 in CI because
`_find_fbuild_elf` only checked `<build_dir>/.fbuild/build/release/firmware.elf`
(the `bash compile` layout for stand-alone ARM boards). On the
`PioCompiler._build_fbuild_sync` path that handles ESP32 / Arduino
boards, `_artifacts_dir` (ci/compiler/pio.py:1386) lays the ELF down
at `<build_dir>/.fbuild/build/<env>/release/firmware.elf` instead.

The previous code derived `env_name` from `list(board_info.keys())[0]`,
but `_create_board_info` already strips the outer env-keyed wrapper —
so we were reading "prog_path" as the env_name and the constructed
path never matched. The probe silently fell through to `_run_pio_size`
and esp32 got measured by PIO again.

Switch to a recursive glob: `<.fbuild>/build/**/firmware.elf` covers
both layouts without needing to know the env_name. Pick newest mtime.

Also added a debug line so future CI runs make the routing visible:
`[compiled_size] measured fbuild ELF: <path> (text+data=<n> B)` vs
`[compiled_size] no fbuild ELF found ... falling through to pio size`.

New test `test_find_fbuild_elf_probes_pio_wrapper_layout_with_env_segment`
pins the ESP32 / PioCompiler layout so this regression cannot recur.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees and others added 2 commits June 19, 2026 01:31
The 330 KB ceiling in e646657 was an intentional regression-signal
that presumed ~300 KB of pending memory work would land alongside it.
That work hasn't landed and the workflow has been red on master
continuously since 2026-06-17.

The proximate measurement bug (PIO re-link reintroducing the
.eh_frame machinery fbuild strips) is fixed in ci/compiled_size.py
earlier on this branch. Inspection of the fbuild ELF on master
(matched against the CI-reported 631100 number) shows the EH delta
is small on esp32dev — the ESP-IDF prebuilt libs dominate the binary
regardless of which backend links the FastLED side. Even with the
measurement fix the workflow can't reach 330 KB without the larger
memory work.

Set the ceiling to 640 KB (~1.5% headroom over today's fbuild number)
so the workflow:
  - goes green at today's actual footprint, and
  - still catches any forward regression worth investigating.

Tighten this back down as memory work lands.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Apa102 measured 687520 B on the prior CI run (last commit, with Blink
passing the new 640 KB ceiling). Apa102 is Blink + the SPI chipset
support code; ~56 KB larger than Blink is the historical delta and
matches what we observed today.

Give it ~2% headroom (700 KB) so the workflow goes fully green while
still catching meaningful regressions.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@zackees
zackees merged commit f7cbb06 into master Jun 19, 2026
10 checks passed
@zackees
zackees deleted the fix/ci-compiled-size-prefer-fbuild branch June 19, 2026 09:12
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant