Skip to content

feat(ldf): evaluate active preprocessor branches during library selection #1098

Closed

Description

@zackees

Problem

After #1097 changes framework library selection to seed only from sketch translation units, FastLED Teensy Blink no longer selects Audio, SD, SdFat, or SerialFlash. However fbuild lib-select --explain still selects DmxSimple, OctoWS2811, and SoftwareSerial because fbuild-header-scan deliberately traverses both sides of every conditional.

Examples in reachable FastLED headers:

  • #ifdef USE_OCTOWS2811 ? <OctoWS2811.h>
  • #ifdef DmxSimple_h ? <DmxSimple.h>
  • #if defined(ARDUINO) && defined(SoftwareSerial_h) ? <SoftwareSerial.h>

Those macros are not enabled by Blink, so the headers are not in the compiler's active include graph.

Required behavior

Library selection must follow the active include graph for the target build:

  1. Start from sketch translation units.
  2. Seed preprocessor state from the target's compile defines and sketch-local defines.
  3. Evaluate #if, #ifdef, #ifndef, #elif, #else, and #endif sufficiently to skip inactive #includes.
  4. Preserve selection when a sketch explicitly defines the relevant feature macro or includes the feature header directly.
  5. Incorporate the define set / conditional mode into the library-selection cache key.

Acceptance

  • FastLED Teensy 4.1 Blink selects only framework libraries in its active graph.
  • Blink does not select DmxSimple, OctoWS2811, SoftwareSerial, Audio, SD, SdFat, or SerialFlash unless the sketch enables/includes that feature.
  • Existing direct and transitive library-selection tests remain valid.
  • Add unit coverage for #if 0, inactive #ifdef, enabled sketch macro, and target compile defines.

Parent: #1094. Consumer: FastLED/FastLED#3696.

Activity

  1. zackees commented on Jul 16, 2026

    @zackees
    MemberAuthor

    Implementation is in #1099 (stacked on #1097). It evaluates active include branches with target compiler defines and sketch-local active defines; the cache key includes the compiler define set.\n\nValidated locally with focused scanner/resolver/cache tests, strict clippy, and the live FastLED Teensy selector. The live selector now reaches 369 headers and selects zero framework libraries; Audio, SD, SdFat, and SerialFlash are absent.

  2. zackees commented on Jul 21, 2026

    @zackees
    MemberAuthor

    Resolved on main by PR #1097 (its squash merge explicitly includes the active-preprocessor implementation from stacked PR #1099).\n\nValidation on current main:\n- bash ./test -p fbuild-header-scan (53 passed)\n- bash ./test -p fbuild-library-select (19 unit + 2 integration passed)\n- soldr cargo check -p fbuild-header-scan -p fbuild-library-select\n- soldr cargo run -p fbuild-cli -- lib-select C:\Users\niteris\dev\fastled -e teensy41 --explain: selected libraries (0), unresolved includes (0). This confirms Blink/FastLED's inactive optional branches no longer pull DmxSimple, OctoWS2811, SoftwareSerial, Audio, SD, SdFat, or SerialFlash.

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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions