Repository navigation
Description
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 viapath_norm_I_srcinci/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:
- 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. - Include the
-ffile-prefix-map/-fmacro-prefix-mapnormalization to strip the mixed-separator prefix consistently. - On Windows, always resolve the include-root path via
fs.as_posix()equivalent and pass e.g.-fcanonical-system-headers=falseplus a flag that forces forward slashes across search paths.
Workarounds in the meantime
- Run single tests (
bash test --cpp fl/channels/driver) rather thanbash test --cppfor 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