Skip to content

Conversation

@Synss
Copy link
Contributor

@Synss Synss commented Aug 13, 2025

The changes are more detailed in the commit messages.

In short, this adds two optional arguments to the linter:

  • gcc-install-dir arg to prevent clang-tidy to use a gcc intallation from the host.
  • deps lets users actually provide the headers and files from an hermetic toolchain registered elsewhere using the rules_cc API.

both options were lifted from https://github.com/erenon/bazel_clang_tidy

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: no

Test plan

Would require registering an hermetic gcc toolchain, which is not trivial.

But manually:

directory(
    name = "x86_64-buildroot-linux-gnu",
    srcs = ["lib/gcc/x86_64-buildroot-linux-gnu/13.3.0"],
)
  • make sure that clang-tidy now uses the hermetic headers.

@aspect-workflows
Copy link

aspect-workflows bot commented Aug 13, 2025

Test

⚠️ Buildkite build #477 failed.

//lint:clang_tidy.doc_extract failed to build

in deps attribute of starlark_doc_extract rule //lint:clang_tidy.doc_extract: missing bzl_library targets for
Starlark module(s) @bazel_skylib//rules/directory:providers.bzl. Since this rule was created by the macro
'bzl_library', the error might have been caused by the macro implementation

💡 To reproduce the build failures, run

bazel build //lint:clang_tidy.doc_extract

Test

example

8 test targets passed

Targets
//tools/format:format_test_HTML_Jinja_with_djlint [k8-fastbuild]3s
//tools/format:format_test_JavaScript_with_prettier [k8-fastbuild]11s
//tools/format:format_test_Markdown_with_prettier [k8-fastbuild]2s
//tools/format:format_test_Protocol_Buffer_with_buf [k8-fastbuild]497ms
//tools/format:format_test_Python_with_ruff [k8-fastbuild]356ms
//tools/format:format_test_SQL_with_prettier [k8-fastbuild]2s
//tools/format:format_test_Scala_with_scalafmt [k8-fastbuild]6s
//tools/format:format_test_Starlark_with_buildifier [k8-fastbuild]444ms

Total test execution time was 24s. 33 tests (80.5%) were fully cached saving 14s.


Test (WORKSPACE) (Test)

example

⚠️ Buildkite build #477 failed.

//src:tsconfig failed to build

error loading package 'src': at
/mnt/ephemeral/workdir/aspect-build/rules_lint/example/tools/lint/linters.bzl:5:6: at
/mnt/ephemeral/output/rules_lint/example/external/aspect_rules_lint/lint/clang_tidy.bzl:40:6: Label
'@@bazel_skylib//rules/directory:providers.bzl' is invalid because 'rules/directory' is not a package;
perhaps you meant to put the colon here: '@@bazel_skylib//rules:directory/providers.bzl'?

💡 To reproduce the build failures, run

bazel build //src:tsconfig

Lint [.]      Lint [example]

@Synss Synss marked this pull request as draft August 13, 2025 16:49
@Synss Synss force-pushed the clang-tidy-hermetic branch from d21c7c8 to 82a1043 Compare September 15, 2025 10:24
@Synss Synss changed the title Improve support of hemertic toolchains with the clang tidy linter feat: Improve support of hemertic toolchains with the clang tidy linter Sep 15, 2025
@Synss Synss force-pushed the clang-tidy-hermetic branch 2 times, most recently from 346ac2f to 54271cb Compare September 23, 2025 09:46
for `rules/directory`
Without the argument, clang (clang-tidy) discovers a gcc installation
automatically on the system, for example,
```
% clang -v
Ubuntu clang version 18.1.8 (++20240731024944+3b5b5c1ec4a3-1~exp1~20240731145000.144)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
```

However, users may want to switch off the discovery and specify a
version, exactly.

```
% clang -v --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/12
Ubuntu clang version 18.1.8 (++20240731024944+3b5b5c1ec4a3-1~exp1~20240731145000.144)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
```

This is especially relevant for, but not limited to, hermetic
toolchains.

See also

  This patch ports erenon/bazel_clang_tidy#88
  to rules_lint.
This partially ports erenon/bazel_clang_tidy@b8c0567
to extend the support of hermetic toolchains.

The `deps` argument lets users control the visibility of the hermetic
gcc install during the clang-tidy run.
@Synss Synss force-pushed the clang-tidy-hermetic branch from 54271cb to 58899cc Compare November 10, 2025 14:27
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