@@ -24,6 +24,7 @@ def _run_tidy(
2424 additional_deps ,
2525 config ,
2626 flags ,
27+ cc_toolchain ,
2728 compilation_context ,
2829 infile ,
2930 discriminator ):
@@ -34,7 +35,7 @@ def _run_tidy(
3435 direct_deps .append (additional_deps .files )
3536 inputs = depset (
3637 direct = direct_deps ,
37- transitive = [compilation_context .headers ],
38+ transitive = [compilation_context .headers , cc_toolchain . all_files ],
3839 )
3940
4041 args = ctx .actions .args ()
@@ -69,6 +70,10 @@ def _run_tidy(
6970 args .add_all (compilation_context .quote_includes , before_each = "-iquote" )
7071 args .add_all (compilation_context .system_includes , before_each = "-isystem" )
7172
73+ # Add the toolchain's builtin include directories (e.g. libc++ headers,
74+ # clang builtins) which are implicit for the compiler but not for clang-tidy.
75+ args .add_all (cc_toolchain .built_in_include_directories , before_each = "-isystem" )
76+
7277 ctx .actions .run (
7378 inputs = inputs ,
7479 outputs = [outfile ],
@@ -126,6 +131,7 @@ def _clang_tidy_aspect_impl(target, ctx):
126131 config = ctx .attr ._clang_tidy_config .files .to_list ()[0 ]
127132 compilation_context = target [CcInfo ].compilation_context
128133
134+ cc_toolchain = find_cpp_toolchain (ctx )
129135 rule_flags = ctx .rule .attr .copts if hasattr (ctx .rule .attr , "copts" ) else []
130136 safe_flags = {
131137 ACTION_NAMES .cpp_compile : _safe_flags (_toolchain_flags (ctx , ACTION_NAMES .cpp_compile ) + rule_flags ),
@@ -139,6 +145,7 @@ def _clang_tidy_aspect_impl(target, ctx):
139145 additional_deps ,
140146 config ,
141147 safe_flags [ACTION_NAMES .c_compile if src .extension == "c" else ACTION_NAMES .cpp_compile ],
148+ cc_toolchain ,
142149 compilation_context ,
143150 src ,
144151 target .label .name ,
0 commit comments