A hermetic clang-tidy (e.g. from toolchains_llvm) resolves its own
libc++ and Clang builtins via binary-relative search, but cannot find
macOS Xcode SDK platform headers (wchar.h, stdlib.h, stdint.h) that
libc++ depends on via #include_next.
Pass -isysroot pointing to the macOS SDK root so the Clang frontend
locates platform headers without injecting individual include dirs
that risk mixing incompatible header versions.
The sysroot is obtained from cc_toolchain.sysroot when available, or
derived from built_in_include_directories by searching for MacOSX.sdk
paths. A platform constraint check (@platforms//os:macos) ensures
the fallback search only runs when targeting macOS.
Also fix the pre-existing //test:clang_tidy test which expected exit
code 1 but got 0: the readability-inconsistent-declaration-parameter-name
check requires a forward declaration with a different parameter name
to fire, but hello.cpp had only definitions. Add the missing forward
declaration.
References:
- llvm/llvm-project#63890
- aspect-build#566
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
-isysrootto clang-tidy so it can find macOS Xcode SDK platform headers(wchar.h, stdlib.h, stdint.h) that libc++ depends on via
#include_nextctx.target_platform_has_constraint(@platforms//os:macos)to guard themacOS-specific sysroot fallback
//test:clang_tidyfailure (forward declaration needed forreadability-inconsistent-declaration-parameter-nameto fire)clang_tidy_stdlib) exercising stdlib includes with-stdlib=libc++Description
A hermetic clang-tidy (e.g. from toolchains_llvm) resolves its own libc++ and Clang builtins via binary-relative search, but cannot find macOS Xcode SDK platform headers (wchar.h, stdlib.h, stdint.h) that libc++ depends on via #include_next.
Pass -isysroot pointing to the macOS SDK root so the Clang frontend locates platform headers without injecting individual include dirs that risk mixing incompatible header versions.
The sysroot is obtained from cc_toolchain.sysroot when available, or derived from built_in_include_directories by searching for MacOSX.sdk paths. A platform constraint check (@platforms//os:macos) ensures the fallback search only runs when targeting macOS.
Also fix the pre-existing //test:clang_tidy test which expected exit code 1 but got 0: the readability-inconsistent-declaration-parameter-name check requires a forward declaration with a different parameter name to fire, but hello.cpp had only definitions. Add the missing forward declaration.
References:
Test plan
clang_tidy,clang_tidy_stdlib,cppcheck)clang_tidyandclang_tidy_stdlibpassclang_tidyandclang_tidy_stdlibpassPlease note that I verified MacOS builds in my fork CI, but not including it into the PR. Let me know if you would like to reenable MacOS CI and I can push it as a separate PR or update this one.