Skip to content

ESP8266: replace code-enabling defines with template selection + linker elimination #4940

Closed

Description

@zackees

Guiding principle (do it this way, not with a #define)

Do not gate a driver behind a #define that turns its code on. Select drivers
by template and let the linker drop the ones nothing references. A driver's
translation unit stays alive only when something names it — this repo already has
the mechanism: BusTraits<Bus::X>::instance() / BusSupports<Bus::X, Chipset>
(see src/fl/channels/bus_traits.h, "Naming BusTraits<Bus::X>::instance()
anywhere in the program is what causes the linker to keep the driver's
translation unit. If no template instantiation references it, the driver TU is
dead-stripped. See #2428.").

So on a given target the unused drivers are eliminated automatically — which is
most of them — without a compile-time enable flag, and the whole program is still
type-checked. Opt-in defines (FASTLED_ESP8266_UART, FL_ESP8266_EMBEDDED_FS,
FASTLED_ALL_PINS_HARDWARE_SPI, ...) move this decision to the build system and
prevent the driver from being link-eliminated or compile-verified.

Scope on ESP8266

Audit every define that gates driver code on FL_IS_ESP8266 and convert it to a
template-selected driver whose TU link-eliminates when unreferenced. Known today:

Define Gates Where
FASTLED_ESP8266_UART UART1 WS2812 driver src/platforms/esp/8266/fastled_esp8266.h
FL_ESP8266_EMBEDDED_FS LittleFS embedded FS src/platforms/embedded_fs.h:28
FASTLED_ALL_PINS_HARDWARE_SPI legacy Arduino-SPI shim src/platforms/esp/8266/spi_output_template.h:33

(Pin-order selects — FASTLED_ESP8266_RAW/D1/NODEMCU_PIN_ORDER — are board
wiring configuration, not driver enables; leave those.)

Deliverable

  1. Convert each row above to a template/BusTraits-selected driver.
  2. Document the rule in agents/docs/cpp-standards.md ("Driver selection is by
    template, never a code-enabling define").
  3. Add a lint check that flags a new driver-enabling #define under
    src/platforms/**.
  4. Prove elimination: a build with no reference to a given engine must not link
    its symbols (flash/RAM size diff, per bash bloat).

Activity

  1. added
    type: feature
    priority: medium
    platform: esp8266
    area: core
    on Oct 27, 2026
  2. added a commit that references this issue on Oct 28, 2026
  3. moved this from Triage to Done in FastLED Trackeron Oct 28, 2026
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

    area: coreplatform: esp8266priority: mediumtype: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions