Skip to content

fix(audio): add #ifndef guards to vibe.h for PCH-safe inclusion - #2325

Merged
zackees merged 1 commit into
masterfrom
ci/vibe-pch-header-guards
Apr 18, 2026
Merged

zackees merged 1 commit into
masterfrom
ci/vibe-pch-header-guards

Conversation

@zackees

@zackees zackees commented Apr 18, 2026 •

Copy link
Copy Markdown
Member

Classic #ifndef guards alongside existing #pragma once. Works around a Clang-on-Windows PCH dedup quirk that caused VibeLevels/Vibe redefinition errors when vibe.h was pulled in via the test PCH (FastLED.h → audio_processor.h → vibe.h) and also directly by the standalone tests/fl/audio/detector/vibe.cpp. Confirmed fix with clean rebuild: all audio tests pass.

Summary by CodeRabbit

  • Chores
    • Internal code maintenance improvements.

On Windows builds, the include path for vibe.h is sometimes presented with
mixed slashes (e.g. "fastled6/./src\fl/audio/detector/vibe.h"), which can
defeat `#pragma once`'s file-identity check. When vibe.h is included both
via audio_processor.h and via tests/fl/audio/detector/vibe.hpp, the
resulting translation unit sees VibeLevels and Vibe defined twice and
fails with a redefinition error.

Fix: add a classic `#ifndef FL_AUDIO_DETECTOR_VIBE_H` guard alongside the
existing `#pragma once`. This matches the belt-and-suspenders pattern
already used in audio_processor.h and is content-based (path-agnostic),
so it deduplicates regardless of how the include path is spelled.

Verified with `bash test --cpp`: 299/299 tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 598d298 into master Apr 18, 2026
6 of 171 checks passed
@coderabbitai

coderabbitai Bot commented Apr 18, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2e069c09-4603-4380-b4f9-e1e33446215a

📥 Commits

Reviewing files that changed from the base of the PR and between 9528888 and eca191e.

📒 Files selected for processing (1)
  • src/fl/audio/detector/vibe.h

📝 Walkthrough

Walkthrough

An include guard (#ifndef/#define/#endif) has been added to the vibe.h header file to prevent multiple inclusion during compilation. This is a defensive coding practice that avoids potential redefinition errors.

Changes

Cohort / File(s) Summary
Include Guard Protection
src/fl/audio/detector/vibe.h
Added #ifndef/#define include guard at the top and #endif at the end to prevent multiple inclusion of the header file.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A guard now stands at vibe.h's door,
Preventing includes forevermore,
No duplicate definitions to fear,
Just clean compilation, crystal clear! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/vibe-pch-header-guards

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

zackees added a commit that referenced this pull request Apr 18, 2026
…ibling -I spellings

The test include args were chaining `meson.project_source_root() / '.' / 'src'`
which produces `C:/.../fastled6/./src` with a `/./` in the middle of the path.
Every other meson file uses `meson.project_source_root() / 'src'` directly,
producing `C:/.../fastled6/src` — a cleaner spelling.

When the test DLL links against fastled_lib / crash_handler_lib, Meson
ends up putting both spellings of the same directory on the compile line
as distinct -I flags. Clang keys #pragma once on the resolved path string,
so two spellings of the same directory can defeat the deduplication even
though they refer to the same file.

This change aligns the test -I spelling with the rest of the codebase
(ci/meson/native/meson.build lines 438, 469, 524 and examples/meson.build
line 172 all already use the clean spelling).

Note: this is a cleanup, not a #pragma once fix. The redefinition error
seen when vibe.h is included via both audio_processor.h and
tests/fl/audio/detector/vibe.hpp is a deeper PCH+clang issue on Windows
toolchains; the defensive ifndef guard added in #2325 is the working
fix. This PR just removes an unnecessary path inconsistency so the
overall -I surface area is smaller and any future investigation is
working from clean paths.

Verified: bash test --cpp all 299/299 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Apr 18, 2026
On Windows, Meson's `include_directories()` propagates `-I` flags using
native backslash + relative-path spellings (e.g. `-I..\..\src\platforms\stub`).
Clang keys `#pragma once` deduplication on the raw resolved path string —
if the same directory reaches a translation unit via two different
spellings (forward slash vs backslash, absolute vs relative), the header
appears to be two different files and `#pragma once` is silently defeated,
producing double-definition errors (#2324, #2325).

This change ensures every `-I` flag we generate is absolute +
forward-slash + spelled identically everywhere:

* Add canonical `path_norm_*` -I args in ci/meson/shared/meson.build
  (path_norm_I_root, path_norm_I_src, path_norm_I_tests, path_norm_I_stub).
  Every consumer meson.build references these instead of redeclaring.
* Replace every project-wide `include_directories(...)` consumer
  (`include_directories: [src_dir, stub_dir, ...]`) with explicit absolute
  cpp_args. This stops Meson from injecting relative backslash `-I` flags
  into the propagated compile lines.
* For per-example discovered include dirs, build absolute forward-slash
  `-I` args from the discovered relative path via the `/` operator and
  the canonical `path_norm_root` prefix, replacing the previous
  `include_directories(inc_dir_fixed)` call.
* Remove the `#ifndef FL_AUDIO_DETECTOR_VIBE_H` belt-and-suspenders guard
  added in #2325. With all `-I` flags normalized, `#pragma once` alone
  is sufficient. Verified with `bash test --cpp`: 300/300 tests pass.
* Add ci/tests/test_meson_include_paths.py — a CI check that parses
  `.build/meson*/compile_commands.json` after setup and fails if any
  non-Meson-auto `-I` flag contains a backslash or is not absolute.

Fixes #2328.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Apr 18, 2026
On Windows, Meson's `include_directories()` propagates `-I` flags using
native backslash + relative-path spellings (e.g. `-I..\..\src\platforms\stub`).
Clang keys `#pragma once` deduplication on the raw resolved path string —
if the same directory reaches a translation unit via two different
spellings (forward slash vs backslash, absolute vs relative), the header
appears to be two different files and `#pragma once` is silently defeated,
producing double-definition errors (#2324, #2325).

This change ensures every `-I` flag we generate is absolute +
forward-slash + spelled identically everywhere:

* Add canonical `path_norm_*` -I args in ci/meson/shared/meson.build
  (path_norm_I_root, path_norm_I_src, path_norm_I_tests, path_norm_I_stub).
  Every consumer meson.build references these instead of redeclaring.
* Replace every project-wide `include_directories(...)` consumer
  (`include_directories: [src_dir, stub_dir, ...]`) with explicit absolute
  cpp_args. This stops Meson from injecting relative backslash `-I` flags
  into the propagated compile lines.
* For per-example discovered include dirs, build absolute forward-slash
  `-I` args from the discovered relative path via the `/` operator and
  the canonical `path_norm_root` prefix, replacing the previous
  `include_directories(inc_dir_fixed)` call.
* Remove the `#ifndef FL_AUDIO_DETECTOR_VIBE_H` belt-and-suspenders guard
  added in #2325. With all `-I` flags normalized, `#pragma once` alone
  is sufficient. Verified with `bash test --cpp`: 300/300 tests pass.
* Add ci/tests/test_meson_include_paths.py — a CI check that parses
  `.build/meson*/compile_commands.json` after setup and fails if any
  non-Meson-auto `-I` flag contains a backslash or is not absolute.

Fixes #2328.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Apr 18, 2026
… (#2332)

On Windows, Meson's `include_directories()` propagates `-I` flags using
native backslash + relative-path spellings (e.g. `-I..\..\src\platforms\stub`).
Clang keys `#pragma once` deduplication on the raw resolved path string —
if the same directory reaches a translation unit via two different
spellings (forward slash vs backslash, absolute vs relative), the header
appears to be two different files and `#pragma once` is silently defeated,
producing double-definition errors (#2324, #2325).

This change ensures every `-I` flag we generate is absolute +
forward-slash + spelled identically everywhere:

* Add canonical `path_norm_*` -I args in ci/meson/shared/meson.build
  (path_norm_I_root, path_norm_I_src, path_norm_I_tests, path_norm_I_stub).
  Every consumer meson.build references these instead of redeclaring.
* Replace every project-wide `include_directories(...)` consumer
  (`include_directories: [src_dir, stub_dir, ...]`) with explicit absolute
  cpp_args. This stops Meson from injecting relative backslash `-I` flags
  into the propagated compile lines.
* For per-example discovered include dirs, build absolute forward-slash
  `-I` args from the discovered relative path via the `/` operator and
  the canonical `path_norm_root` prefix, replacing the previous
  `include_directories(inc_dir_fixed)` call.
* Remove the `#ifndef FL_AUDIO_DETECTOR_VIBE_H` belt-and-suspenders guard
  added in #2325. With all `-I` flags normalized, `#pragma once` alone
  is sufficient. Verified with `bash test --cpp`: 300/300 tests pass.
* Add ci/tests/test_meson_include_paths.py — a CI check that parses
  `.build/meson*/compile_commands.json` after setup and fails if any
  non-Meson-auto `-I` flag contains a backslash or is not absolute.

Fixes #2328.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the ci/vibe-pch-header-guards branch August 30, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant