Skip to content

Incremental build reuses main.cpp object when only the included sketch .ino changes #1948

Closed

Description

@zackees

Seen from FastLED on 2026-11-07, board stm32h747xi (giga_r1_m7, ststm32/arduino), via bash compile stm32h747xi --examples Blink.

The generated src/main.cpp is #include "sketch/Blink.ino". When only Blink.ino changes, fbuild reuses .fbuild/build/release/src/main_<hash>.cpp.o and reports success.

Repro:

  1. Build once.
  2. Append #error PROBE_REACHED to examples/Blink/Blink.ino and build again. Result: Compilation succeeded in about 2 s, and the object's mtime is unchanged.
  3. Remove main_<hash>.cpp.o and .cmdhash, then build again. Result: src/sketch/Blink.ino:92:2: error: #error PROBE_REACHED.

So the dependency check for main.cpp does not include the headers or sketch files it includes, at least on this target; the .cmdhash covers only the command line. A build can therefore pass without compiling the current sketch, so 'compiles for board X' results can be stale.

Activity

  1. added
    bug
    on Nov 7, 2026
  2. zackees commented on Nov 7, 2026

    @zackees
    MemberAuthor

    Fixed by #1950 (squashed as e48d9bd9).

    Root cause — not the .cmdhash: the Arduino-mbed STM32 path emitted no
    depfile at all
    . build_arduino_mbed_mcu_config built its flags from
    ArduinoCore-mbed/variants/<name>/cflags.txt, which is only the body of
    Arduino's compile recipe — the -MMD lives in platform.txt's recipe, which
    fbuild never replays. Every other MCU config carries -MMD in its JSON
    (stm32f1/f4/h7/u5, sam*, teensy*, esp32*, rp2040, …), so this path was
    the only one producing zero .d files, and CompilerBase::needs_rebuild fell
    through to src_time > obj_time — where src is the generated main.cpp,
    whose mtime never moves when only an included tab/header is edited.

    Reproduced before the fix with a minimal giga_r1_m7 project (no FastLED
    needed — the mechanism is generic to this path):

    build 1: 23.0 s; find .fbuild -name '*.d' | wc -l -> 0
    append "#error PROBE_REACHED" to src/widget.h
    build 2: "build succeeded in 3.3s", object mtime unchanged (09:09:49.101)
    rm the .o + .cmdhash; build 3: src/widget.h:3:2: error: #error PROBE_REACHED
    

    Fix — append -MMD to the mbed shared compile flags (deduped), matching
    every JSON config. gcc's naming was verified against the real toolchain:
    arm-none-eabi-g++ -c -MMD TU.cpp -o TU.cpp.o writes TU.cpp.d, i.e. exactly
    object.with_extension("d"), with workspace-relative prerequisites that
    compile_cwd_from_output already resolves.

    Tests — mbed_flags_request_a_depfile_so_included_files_invalidate (exactly
    one -MMD; -c/-std= never leak into the shared block; the flag reaches both
    c_flags and cpp_flags) and every_mcu_config_json_requests_a_depfile
    (walks all 24 checked-in MCU configs, so a new platform cannot ship without
    dependency tracking). Both mutation-checked RED. fbuild-build-arm --lib: 254
    passed. CI green including the board matrix — the Arduino GIGA R1 M7 / build
    job on this PR and Build STM32H747XI on the merge commit both pass with the new
    flags.

    Two caveats worth knowing:

    • Adding a flag changes the rebuild signature, so the first mbed build after
      upgrading recompiles that board's core once.
    • Re-running your exact stale-object repro needs a release that carries this
      commit: fbuild always builds in the daemon provisioned by the installed
      tool, so a fix cannot be exercised in-place from a checkout. Re-open if the
      probe still reports "succeeded" on a build whose .fbuild contains no
      *.d files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions