Repository navigation
fix(shrink): apply --shrink=printf only on Xtensa ESP32 (it grows RISC-V images) - #1840
Merged
Merged
Conversation
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.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
--shrink=printf(newlib-nano) was wired for everyespressif32target(#1826). Measured on real hardware/builds, that is only correct on Xtensa:
--no-shrinkflash--shrink=printfflashesp32devesp32s3esp32c6On RISC-V the full formatter is only ~15 KB (
_vfprintf_r9,658 B +_vfiprintf_r5,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.text153,118 → 161,424 B). Net: the "shrink" grows the image.A reducer that grows firmware must never be applied, so:
shrink_link::resolve_shrinknow takesis_xtensa(fromMcuConfig::is_xtensa()at the call site) and, on RISC-V, builds unshrunk andemits 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>.jsonrecordsresolved: off,applied: []— terminal andJSON agree.
board → mcu → arch from
platformio.ini, and claiming it on a C6 produced afalse 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 intests/it/main.rs), three#[ignore]real-toolchain tests against aself-checking printf battery (integers incl.
%lld/%zu, width/precision/flags,floats incl.
inf,%s %c %%, throughsnprintf/sprintf/vsnprintf):build_esp32dev_shrink_printf_replaces_newlib_formatter— builds the samesource
--no-shrinkand--shrink=printf; asserts flash decreases,-specs=nano.specs+-Wl,-u,_printf_floatreach the link only when shrunk,and the record is
mode/resolved=printf,applied=["newlib-nano"],strategy=spec-file.build_esp32dev_auto_shrink_stays_off—AutostaysOffand never links nano.build_esp32c6_shrink_printf_is_refused— the RISC-V gate end to end: buildsucceeds unshrunk, record
resolved=off, no nano flag.Unit:
shrink_link_testsaddriscv_targets_refuse_printf_and_say_whyandriscv_auto_stays_silent(5 pass in-p fbuild-build-esp --lib shrink),-p fbuild-cli --bin fbuild shrink16 pass.Hardware check
BATTERY total=36 failed=0over serial on an attached ESP32-C6 (ttyACM0) withthe 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
AutostaysOffand theREADME records the per-arch measurement.
Gates
soldr cargo fmt --all -- --checkrc 0soldr lint rust(workspace clippy + dylint, RUST-033) rc 0bash test— see log pasted in the PR conversation/report44/43, new test file ~350 LOCDocs:
crates/fbuild-build-engine/src/shrink/README.mdgains a measured"Xtensa-only, because that is where it shrinks" section.