Skip to content

Test build: #pragma once fails for fl/cled_controller.h / fl/gfx/colorutils.h under PCH on Windows (clang) #2376

Closed

Description

@zackees

Environment

  • Host: Windows 10 + clang 21.1.5 via meson/ninja
  • Build: bash test --cpp (full suite, quick mode with PCH enabled)
  • Compiler args observed for PCH: -I<...>/src, -I<...>/src/platforms/stub (forward-slash normalized via path_norm_I_src in ci/meson/shared/meson.build)
  • Branch: tip of master (e713d6f9f3)

Symptoms

Full test-suite compile fails in tests/fastled_core.cpp with #pragma once guards silently not taking effect for headers that are pulled in by the shared fastled_pch and then re-included directly by the translation unit:

FAILED: tests/fastled_core.dll.p/fastled_core.cpp.obj
C:/Users/niteris/dev/fastled10/./src\fl/cled_controller.h:32:7: error: redefinition of 'CLEDController'
  32 | class CLEDController {
     |       ^
note: 'C:/Users/niteris/dev/fastled10/./src\fl/cled_controller.h' included multiple times, additional include site here
  src/fl/fastled.h:73: #include \"cled_controller.h\"
  tests/fastled_core.cpp:56: #include \"fl/cled_controller.h\"

The same class of failure also reproduces against src/fl/gfx/colorutils.h (redefinition of inline fadeLightBy, fade_video, nscale8_video, fadeToBlackBy). Standalone single-test compiles (e.g. bash test --cpp fl/channels/driver) succeed because the PCH/TU path lineage is consistent there.

Root cause

The path in the error has mixed separators: C:/Users/.../src\fl/cled_controller.h — forward slashes from the -I arg, back slash glued in from the Windows native #include resolution. clang hashes headers by path string for #pragma once, so the PCH sees it under one spelling and the TU adds it again under the (still-identical-looking) other spelling, defeating the guard.

The project already intends to normalize include roots — see ci/meson/shared/meson.build (path_norm_I_src) and the comment block in ci/meson/native/meson.build around fastled_pch_abs_include_args ("must match between PCH and consumer compilation so that #pragma once recognises headers from both contexts as the same file"). The include-root side is consistent; what's inconsistent is clang's gluing of the relative #include suffix with a native \ onto a /-terminated search-path root.

Proposed fixes

One of:

  1. Add -fno-pch-canonical-path / equivalent, or pass the PCH and consumer compiles the same canonical-prefix flags so the full file path is spelled identically.
  2. Include the -ffile-prefix-map / -fmacro-prefix-map normalization to strip the mixed-separator prefix consistently.
  3. On Windows, always resolve the include-root path via fs.as_posix() equivalent and pass e.g. -fcanonical-system-headers=false plus a flag that forces forward slashes across search paths.

Workarounds in the meantime

  • Run single tests (bash test --cpp fl/channels/driver) rather than bash test --cpp for quick iteration.
  • On systems with no PCH, or with --no-pch, the build succeeds.

Related

Surfaced while investigating #2371 (direct per-controller showLeds() flush) — the fix for that ships on branch fix-2371-direct-controller-show.

Activity

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions