Repository navigation
Description
fbuild 2.5.4. Reproduced deterministically; this currently breaks FastLED's teensy41 CI on master (FastLED/FastLED#3775).
Summary
fbuild's library dependency finder appears to consider only includes reachable from the sketch. Includes that live inside a library's own sources or headers do not pull that library into the link, so the build compiles cleanly and then fails at link with undefined references.
Critically, there is no supported way for the library to declare the dependency instead — I tried every mechanism I could find and none is honored (table below).
Reproduction
In a FastLED checkout at master:
bash compile teensy41 --examples Blink # succeeds
bash compile teensy41 --examples Apa102 # fails at link, ~30sBlink succeeds because it is clockless-only and the SPI drivers get dead-stripped. Apa102 retains them:
Linking firmware.elf
build error: build failed: arm-none-eabi-gcc link failed:
ld: .lto-tmp/ccG97iow.ltrans1.ltrans.o: in function `fl::SpiHw4MXRT1062::begin(fl::SpiHw4::Config const&)':
<artificial>:(.text+0x2672): undefined reference to `SPIClass::setSCK(unsigned char)'
<artificial>:(.text+0x2682): undefined reference to `SPIClass::setMOSI(unsigned char)'
<artificial>:(.text+0x2692): undefined reference to `SPIClass::setMISO(unsigned char)'
<artificial>:(.text+0x2698): undefined reference to `SPIClass::begin()'
<artificial>:(.text+0x26b0): undefined reference to `SPI'
<artificial>:(.text+0x26b4): undefined reference to `SPI1'
<artificial>:(.text+0x26b8): undefined reference to `SPI2'
collect2: error: ld returned 1 exit status
SPIClass, SPI, SPI1, SPI2 are defined in the Teensy core's libraries/SPI/SPI.cpp. The header is always on the include path (fbuild passes -I.../libraries/SPI unconditionally), which is why compilation succeeds — only the archive is missing from the link.
The include chain exists and is reachable from the sketch
Apa102.ino
└─ #include <FastLED.h>
└─ src/fastspi.h:42 #include "platforms/spi_device_proxy.h"
└─ src/platforms/arm/mxrt1062/spi_device_proxy.h:33 #include <SPI.h>
Every edge is a plain unconditional #include in a header. PlatformIO's chain LDF follows exactly this shape. fbuild does not appear to.
Contrast within a single run
In the same failing CI run, Ports/PJRCSpectrumAnalyzer — whose .ino includes SPI.h directly — compiled 147/147 files including libraries/SPI/SPI.cpp and linked successfully. The only difference from Apa102 is whether the #include <SPI.h> is in the sketch or in a library header.
Declaration mechanisms tried — none honored
| # | attempt | result |
|---|---|---|
| 1 | lib_ldf_mode = deep in the generated platformio.ini |
no effect (verified present in the ini fbuild consumes) |
| 2 | lib_deps = SPI in the generated platformio.ini |
no effect (verified present in the ini) |
| 3 | "dependencies": [{"name": "SPI", "platforms": "teensy"}] in the library's library.json (copied to lib/FastLED/library.json) |
no effect |
| 4 | #include <SPI.h> added to the sketch |
links — Flash 129.00 KB |
fbuild build --help exposes no library/dependency flag either, so from the consuming project there is no lever at all.
Why it surfaced now (may help reproduce)
FastLED's teensy41 build had been carrying a warm cached link set that happened to contain SPI.cpp; runs logged Compiled 1/1 files. A commit touching src/ busted that cache, the first cold resolution logged Compiled 84/84 files and omitted the SPI library, and every firmware in that run shrank by a uniform ~27 KB with byte-identical compiler flags. So the defect is latent and only visible on a cold dependency resolution — worth knowing when trying to reproduce, since a warm cache can hide it.
Ask
Any one of these would resolve it:
- Have the LDF scan library sources/headers (PlatformIO
deep-equivalent), or follow nested includes through library headers aschaindoes. - Honor
lib_depsfromplatformio.ini. - Honor
dependenciesin a library'slibrary.json.
Option 2 or 3 would let a library declare a dependency the finder cannot infer, which seems worth having regardless of what the LDF does.
Per FastLED's CLAUDE.md I am not adding a workaround on the FastLED side (sprinkling #include <SPI.h> into the affected examples would turn CI green while leaving the defect in place for every other fbuild consumer).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Jul 31, 2026
Fastled was supposed to pull in teensy header dependencies, use singleton to allow stripping, then LDF can be used as normal. Fastled will always include its own headers so now we have a solution by putting the solution inside the fastled lib
zackees commentedon Jul 31, 2026
Withdrawing ask #1. My framing was wrong — a maintainer pointed out that shallow, sketch-only LDF is the intended default (PlatformIO parity), and the code agrees with them, not with me.
crates/fbuild-build-engine/src/framework_libs.rshas an explicit regression test namedinactive_local_library_header_cannot_select_framework_library(#1094). So "a local library's header must not select a framework library" is a deliberate, tested invariant. Asking for it to be reversed was asking to undo #1094, which I did not realize when I filed this.Please disregard ask #1 (make the LDF scan library sources/headers). Deepening the LDF would also re-introduce the problem the consuming project spent real effort escaping: libraries pulled in by default drag their global objects' constructors into the image, which is what makes them unstrippable.
New data that may still be useful
I tested how far the hint mechanism gets under fbuild. FastLED has a purpose-built
src/platforms/*/ldf_headers.hchain, reachable from the sketch via#include <FastLED.h>→src/FastLED.h:216, whose entire job is to expose framework-library dependencies to a dependency finder:platforms/arm/teensy/ldf_headers.h#if 0+#include <SPI.h>+#endif(the form written for PlatformIO's non-evaluating LDF)#include <SPI.h>#include <SPI.h>in the sketchThe second row is the interesting one: an unconditional include in a library header reachable from the sketch still does not select the library. So under fbuild that mechanism is completely inert, and a consuming library has no way to express a dependency the finder cannot infer —
lib_deps,lib_ldf_mode,library.jsondependenciesand header hints all no-op on the Teensy/STM32 path.What I think is still worth doing here (asks #2/#3 only)
lib_depsis already parsed (crates/fbuild-config/src/ini_parser/mod.rs:249get_lib_deps()) but only consumed by the ESP32 orchestrator; the Teensy and STM32 orchestrators never call it. Honoring it there is not a deeper LDF —lib_depsis an explicit user declaration, which is exactly PlatformIO's semantics, and it leaves the shallow default intact. Same argument forlibrary.jsondependencies, whichcrates/fbuild-library/src/library/library_manager.rs:177already parses but hard-filters toespressif32.Separately,
lib_ldf_modeis never parsed anywhere incrates/(only two doc-comment mentions insource_scanner.rs), so a project setting it gets silent no-op rather than an unsupported-option error — worth at least a warning.Feel free to retitle/rescope or close this if only the
lib_depspart is wanted. The actual fix for the FastLED breakage belongs on the FastLED side and I've filed it there — the Teensy 4.x driver should not depend on the Arduino SPI library in the first place.fix(ldf): honor lib_deps on Teensy/STM32 and warn on inert lib_ldf_mo…
fix(adafruit): unbreak all teensy builds + make README badges honest (#…
fix(ldf): seed from every compiled TU, and treat __has_include as und…