Skip to content

fix(stm32-mbed): emit depfiles so included sketches/headers invalidate objects - #1950

Merged
zackees merged 1 commit into
mainfrom
agent/stm32-mbed-depfiles
Nov 7, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/stm32-mbed-depfiles

Conversation

@zackees

@zackees zackees commented Nov 7, 2026

Copy link
Copy Markdown
Member

Summary

ArduinoCore-mbed's variants/<name>/{c,cxx,ld}flags.txt are only the body of
Arduino's compile recipe. The -MMD that makes gcc write a per-TU .d lives in
platform.txt's recipe, which the mbed build path never replays. Every other MCU
config (stm32f1/f4/h7/u5, sam*, teensy*, esp32*, …) carries -MMD in its
JSON, so the Arduino-mbed path was the only one producing zero depfiles.

CompilerBase::needs_rebuild then degrades to a source-mtime comparison — and for
the generated main.cpp that source's mtime never moves when the sketch tab or a
header it includes is edited. A build could therefore report compilation succeeded while reusing an object built from a sketch that no longer compiles.

Reported in #1948 (bash compile stm32h747xi --examples Blink).

Real repro (installed fbuild 2.5.50, before this change)

Minimal giga_r1_m7 project, src/main.cpp includes src/widget.h:

  1. build 1 → 23.0 s; find .fbuild -name '*.d' | wc -l → 0
  2. append #error PROBE_REACHED to src/widget.h, build 2 → build succeeded in 3.3s,
    object mtime unchanged (09:09:49.101), PROBE_REACHED absent from the output
  3. delete main_34d2.cpp.o + .cmdhash, build 3 → src/widget.h:3:2: error: #error PROBE_REACHED — the header really was broken; only the dependency check missed it

Change

  • arduino_mbed_mcu_config_from_variant_text (a pure split of
    build_arduino_mbed_mcu_config, so the flag policy is testable without an
    installed framework) appends -MMD to the shared compile flags, matching every
    JSON MCU config.
  • gcc's naming convention was verified against the real toolchain:
    arm-none-eabi-g++ -c -MMD TU.cpp -o TU.cpp.o writes TU.cpp.d, which is exactly
    the object.with_extension("d") path needs_rebuild reads and matches the
    workspace-relative prerequisites compile_cwd_from_output resolves against.

Tests

  • mbed_flags_request_a_depfile_so_included_files_invalidate — exactly one -MMD;
    -c and -std= never leak into the shared block; the flag survives into both
    c_flags and cpp_flags.
  • every_mcu_config_json_requests_a_depfile — walks all 24 checked-in MCU JSON
    configs and fails if any declares no -MMD, so a new platform cannot ship
    without dependency tracking.
  • Mutation-tested in both directions: removing the flag push → test 1 RED; deleting
    -MMD from stm32u5.json → test 2 RED.
  • soldr cargo test -p fbuild-build-arm --lib → 254 passed, 0 failed, 2 ignored
    (includes both new tests); ci/enforce_platform_boundary.py --print-totals →
    rows=44; dylint_rows=43 rc 0; ci/check_test_layout.py → ok;
    soldr lint rust --cross-dylint → rc 0.

Notes

  • Adding a flag changes the rebuild signature, so the first build after upgrading
    recompiles the mbed boards' core once. Steady state is unchanged.
  • Not verified end-to-end with the patched binary: fbuild always runs builds in
    the daemon provisioned by the installed tool, so worktree code cannot be
    exercised daemon-side. The flag contract is unit-tested and the depfile naming
    is asserted against the real gcc.

…e objects

ArduinoCore-mbed's variants/<name>/{c,cxx,ld}flags.txt are only the body of
Arduino's compile recipe: the -MMD that makes gcc write a per-TU .d lives in
platform.txt's recipe, which this build path never replays. Every other MCU
config carries -MMD in its JSON, so the mbed path was the only one producing
zero depfiles and CompilerBase::needs_rebuild degraded to a source-mtime
comparison of the GENERATED main.cpp -- which never moves when an included
sketch tab or header is edited, so a stale object kept reporting success
(#1948).

Split the mcu-config builder into a pure flag-text function so the policy is
testable without an installed framework, append -MMD, and guard the whole
checked-in config set with a test that fails if any config declares no -MMD.
@coderabbitai

coderabbitai Bot commented Nov 7, 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

@zackees
zackees added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit e48d9bd Nov 7, 2026
39 checks passed
@zackees
zackees deleted the agent/stm32-mbed-depfiles branch November 7, 2026 19:50
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 8, 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