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.

Synss added 3 commits August 12, 2025 15:57
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.
Copy link

aspect-workflows bot commented Aug 13, 2025

Test

All tests were cache hits

3 tests (100.0%) were fully cached saving 421ms.


Test

docs

⚠️ Buildkite build #219 failed.

//:clang-tidy.extract failed to build

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

💡 To reproduce the build failures, run

bazel build //:clang-tidy.extract

Test

example

7 test targets passed

Targets
//tools/format:format_test_JavaScript_with_prettier [k8-fastbuild]9s
//tools/format:format_test_Markdown_with_prettier [k8-fastbuild]4s
//tools/format:format_test_Protocol_Buffer_with_buf [k8-fastbuild]505ms
//tools/format:format_test_Python_with_ruff [k8-fastbuild]194ms
//tools/format:format_test_SQL_with_prettier [k8-fastbuild]3s
//tools/format:format_test_Scala_with_scalafmt [k8-fastbuild]3s
//tools/format:format_test_Starlark_with_buildifier [k8-fastbuild]397ms

Total test execution time was 20s. 27 tests (79.4%) were fully cached saving 7s.


Test (WORKSPACE) (Test)

example

⚠️ Buildkite build #219 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 [docs]      Lint [example]

@Synss Synss marked this pull request as draft August 13, 2025 16:49
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