Skip to content

fix(shrink): apply --shrink=printf only on Xtensa ESP32 (it grows RISC-V images) - #1840

Merged
zackees merged 3 commits into
mainfrom
agent/shrink-printf-fmt
Nov 1, 2026
Merged

zackees merged 3 commits into
mainfrom
agent/shrink-printf-fmt

Conversation

@zackees

@zackees zackees commented Nov 1, 2026

Copy link
Copy Markdown
Member

What and why

--shrink=printf (newlib-nano) was wired for every espressif32 target
(#1826). Measured on real hardware/builds, that is only correct on Xtensa:

board arch / toolchain --no-shrink flash --shrink=printf flash delta
esp32dev Xtensa LX6, xtensa-esp32-elf 8.4.0 277,185 B 254,036 B −23,149 B (−8.4 %)
esp32s3 Xtensa LX7, xtensa-esp32s3-elf 8.4.0 328,162 B 305,134 B −23,028 B (−7.0 %)
esp32c6 RISC-V, riscv32-esp-elf 14.2.0 280,848 B 290,374 B +9,526 B

On RISC-V the full formatter is only ~15 KB (_vfprintf_r 9,658 B +
_vfiprintf_r 5,740 B), and nano's replacement pulls _dtoa_r (3,642 B) and
_printf_float (1,346 B) back in with an offsetting +8.3 KB of other libc code
(.flash.text 153,118 → 161,424 B). Net: the "shrink" grows the image.

A reducer that grows firmware must never be applied, so:

  • shrink_link::resolve_shrink now takes is_xtensa (from
    McuConfig::is_xtensa() at the call site) and, on RISC-V, builds unshrunk and
    emits one always-visible line:
    WARNING: shrink: --shrink=printf is Xtensa-only; <toolchain> is RISC-V, where newlib-nano grows the image - building unshrunk (FastLED/fbuild#1459)
    build_info_<env>.json records resolved: off, applied: [] — terminal and
    JSON agree.
  • The CLI no longer previews "links newlib-nano": it cannot resolve
    board → mcu → arch from platformio.ini, and claiming it on a C6 produced a
    false line next to the new warning. The applied line is now printed by the one
    place that knows both the arch and the probe result
    (resolve_shrink), so there is exactly one authoritative line.

Tests

New crates/fbuild-build/tests/it/esp32_shrink_printf.rs (registered in
tests/it/main.rs), three #[ignore] real-toolchain tests against a
self-checking printf battery (integers incl. %lld/%zu, width/precision/flags,
floats incl. inf, %s %c %%, through snprintf/sprintf/vsnprintf):

  • build_esp32dev_shrink_printf_replaces_newlib_formatter — builds the same
    source --no-shrink and --shrink=printf; asserts flash decreases,
    -specs=nano.specs + -Wl,-u,_printf_float reach the link only when shrunk,
    and the record is mode/resolved=printf, applied=["newlib-nano"],
    strategy=spec-file.
  • build_esp32dev_auto_shrink_stays_off — Auto stays Off and never links nano.
  • build_esp32c6_shrink_printf_is_refused — the RISC-V gate end to end: build
    succeeds unshrunk, record resolved=off, no nano flag.

Unit: shrink_link_tests add riscv_targets_refuse_printf_and_say_why and
riscv_auto_stays_silent (5 pass in -p fbuild-build-esp --lib shrink),
-p fbuild-cli --bin fbuild shrink 16 pass.

Hardware check

BATTERY total=36 failed=0 over serial on an attached ESP32-C6 (ttyACM0) with
the current tree — the battery itself and the full-newlib control are correct.
No Xtensa ESP32 board is attached here, so the nano variant's on-silicon
formatting run is still unproven; that is exactly why Auto stays Off and the
README records the per-arch measurement.

Gates

  • soldr cargo fmt --all -- --check rc 0
  • soldr lint rust (workspace clippy + dylint, RUST-033) rc 0
  • bash test — see log pasted in the PR conversation/report
  • boundary 44/43, new test file ~350 LOC

Docs: crates/fbuild-build-engine/src/shrink/README.md gains a measured
"Xtensa-only, because that is where it shrinks" section.

The newlib-nano reducer was wired for every espressif32 target (#1826).
Measured against the same printf battery source, that is only a win on
Xtensa: esp32dev 277,185 -> 254,036 B (-23,149) and esp32s3 328,162 ->
305,134 B (-23,028), while esp32c6 (RISC-V, riscv32-esp-elf 14.2.0) goes
280,848 -> 290,374 B (+9,526): the full formatter there is only ~15 KB and
nano pulls _dtoa_r + _printf_float back in with an offsetting +8.3 KB of
libc code.

A size reducer that grows the image must never be applied, so
resolve_shrink now takes is_xtensa (McuConfig::is_xtensa() at the call
site), builds unshrunk on RISC-V and prints one always-visible
"WARNING: shrink: --shrink=printf is Xtensa-only ..." line; build_info
records resolved=off / applied=[] so terminal and JSON agree.

The CLI no longer previews "links newlib-nano": it cannot resolve
board -> mcu -> arch from platformio.ini and produced a false line next
to the new warning. The applied line is now emitted by resolve_shrink,
the only place that knows both the architecture and the probe result.

Tests: new ignored integration module esp32_shrink_printf builds a
self-checking printf battery both ways (flash down, nano flags only when
shrunk, record mode/resolved=printf + newlib-nano + spec-file), guards
that Auto stays off, and proves the RISC-V refusal end to end. Unit
tests cover the RISC-V warning and that auto stays silent. Shrink README
gains the measured per-arch table.
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Adding the arch argument pushed the ESP32 orchestrator to 1001 LOC, which
the LOC gate rejects for any file that was <=1000 on the base SHA. The
shrink comment block it duplicated already lives in
shrink_link::resolve_shrink (module docs plus the inline gate), so it is
replaced by a two-line pointer: build.rs is 996 LOC.
The new test module tripped `ban_std_pathbuf` on its `params()` signature
and on the two `PathBuf` return types. New files may not join the legacy
allowlist, so the module now carries `fbuild_core::path::NormalizedPath`
and converts with `as_path().to_path_buf()` only at the `BuildParams`
boundary.

Local gates: `soldr dylint --all -- --package fbuild-build --all-targets`
rc 0; the three ignored real-toolchain tests still pass
(control 277,149 B -> 254,000 B); fmt rc 0.
@zackees
zackees added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 71a5031 Nov 1, 2026
36 checks passed
@zackees
zackees deleted the agent/shrink-printf-fmt branch November 1, 2026 11:08
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant