clang-tidy: parse against libc++ everywhere, and document the real hook setup - #279
Merged
Conversation
The extracted commands come from the default build configuration, not `--config=clang`, so they carry no `-stdlib`. The hermetic clang then falls back to each platform's default: libc++ on macOS, libstdc++ on Linux. Same clang-tidy, different standard library, so the same check could report differently per platform - a finding fixed on a Mac could be absent on the Linux CI runner, and the reverse. Pass `--bcce-copt=-stdlib=libc++`, which the hermetic toolchain ships on both platforms. A no-op on macOS; the actual switch on Linux. Verified locally: all 3002 compile DB entries carry the flag and clang-tidy still parses cleanly (no hard errors). The Linux half is what this change is for and is verified by the CI clang-tidy job. Note this treats the symptom. The root cause is that the compile DB is extracted in the default configuration and only has its compiler substituted afterwards; extracting with `--config=clang` would make every flag - stdlib, include paths, feature macros, sysroot - match what bazel actually builds. That is tracked separately. Signed-off-by: helly25 <6420169+helly25@users.noreply.github.com>
helly25
enabled auto-merge (squash)
August 9, 2026 08:26
The dev-setup paragraph claimed the repo "enables `trunk-fmt-pre-commit` and `trunk-check-pre-push` so the hooks run automatically once installed". That has been false for some time: both actions are disabled in .trunk/trunk.yaml, and main.yml's "Trunk must not own git hooks" step fails the build if either is re-enabled. A dev following the README would never run `pre-commit install` and would end up with no git hooks at all. Describe what is actually there: pre-commit owns the git hook and delegates `trunk fmt` to trunk, trunk's own hook actions stay disabled so the two cannot fight over .git/hooks, and CI runs pre-commit, trunk check and clang-tidy as separate jobs. clang-tidy is one of the pre-commit hooks too - it moved there from trunk, which pinned a version too old to parse this code - opt-in for now and automatic once the finding sweep lands. STYLE_CPP.md has the details. The paragraph is taken from #183, which proposed it before the CI guard and the clang-tidy job existed; the rest of that PR is superseded. Signed-off-by: helly25 <6420169+helly25@users.noreply.github.com>
2 tasks
Fab-Cat
approved these changes
Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two parts of the same story: making clang-tidy behave identically on macOS and Linux, and describing the setup honestly in the README.
1. Parse against libc++ on every platform
compile_commands-update.shextracts the compile DB from the default build configuration —--config=clangnever reaches the extractor'saquery; we only substitute the compiler binary afterwards via--bcce-compiler. So the recorded commands carry no-stdlib, and the hermetic clang falls back to each platform's default:Same clang-tidy, different standard library, therefore different template instantiations and different findings. A finding fixed on a Mac could simply be absent on the Linux CI runner, and the reverse — which makes the finding sweep platform-dependent and would make enforcement flap between local and CI.
Fix: pass
--bcce-copt=-stdlib=libc++. The hermetic toolchain ships libc++ on both platforms, so this is a no-op on macOS and the actual switch on Linux.Test: all 3002 compile DB entries carry the flag; clang-tidy still parses cleanly on macOS with no hard errors. The Linux half is exactly what this changes, and the CI
clang-tidyjob verifies it.This treats the symptom
The root cause is that the DB is extracted in the default configuration with only its compiler replaced. Extracting with
--config=clang(arefresh_compile_commandstarget withtargets = {"@//...": "--config=clang"}) would make every flag — stdlib, include paths, feature macros, sysroot — match what bazel actually builds, and would let both--bcce-compilerand this flag go away. Worth doing; tracked separately.2. README: document the dev hook setup that actually exists
The dev-setup paragraph claimed the repo "enables
trunk-fmt-pre-commitandtrunk-check-pre-pushso the hooks run automatically once installed". That has been false for some time: both actions are disabled in.trunk/trunk.yaml, and main.yml's "Trunk must not own git hooks" step fails the build if either is re-enabled. A dev following the README would never runpre-commit installand would end up with no git hooks at all.It now says what is there: pre-commit owns the git hook and delegates
trunk fmtto trunk, trunk's own hook actions stay disabled so the two cannot fight over.git/hooks, and CI runspre-commit,trunk checkandclang-tidyas separate jobs. clang-tidy is one of the pre-commit hooks too — it moved there from trunk, which pinned a version too old to parse this code — opt-in for now and automatic once the finding sweep lands.This paragraph originates in #183, which proposed it before the CI guard and the clang-tidy job existed. The rest of that PR is superseded and it is being closed.