Skip to content

Conversation

@bobtista
Copy link

@bobtista bobtista commented Nov 5, 2025

This PR builds on @JohnsterID's work in PR #1580, fixing issues identified in that PR to enable clang-tidy static analysis for the project.

Clang-tidy doesnot work with our Pre-Compiled Headers, so we can just run cmake to disable them, then it works. Added a python script for convenience and for processing files in batches to avoid Windows command line character limits.

Usage:

# One-time setup (creates build/clang-tidy/ - just CMake config, no compilation)
cmake -B build/clang-tidy -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON -G Ninja

# Run clang-tidy (auto-uses build/clang-tidy)
python scripts/run-clang-tidy.py --include Core/Libraries/

# Or run clang-tidy directly
clang-tidy -p build/clang-tidy --checks="-*,modernize-use-nullptr" "file.cpp"

@OmniBlade
Copy link

Out of interest, why does this close the clang-format stuff? Clang-tidy and clang-format perform different functions as I understand it.

@Skyaero42
Copy link

Out of interest, why does this close the clang-format stuff? Clang-tidy and clang-format perform different functions as I understand it.

I was in the understanding the three closed PR's were replacable by this work - additionally they were also not worked on, I'm doing a clean up of older PR's.

But if I was mistaken, please open the other PR again (and remove it from the first-post here).

@bobtista bobtista force-pushed the bobtista/build/clang-tidy-fixes branch 3 times, most recently from 0ad4d79 to 2caeed2 Compare November 17, 2025 18:17
@bobtista
Copy link
Author

bobtista commented Nov 29, 2025

This works for me on mac and windows: EDIT while it runs on mac, it lacks a lot of Windows specific stuff and will skip a ton of files. I've removed mac support from the script and docs. Use Windows

@bobtista bobtista marked this pull request as ready for review November 29, 2025 02:41
@bobtista bobtista marked this pull request as draft December 4, 2025 16:11
@bobtista bobtista marked this pull request as ready for review December 4, 2025 17:21
@bobtista bobtista force-pushed the bobtista/build/clang-tidy-fixes branch 5 times, most recently from 07d1ba4 to fe57955 Compare December 6, 2025 17:20
@bobtista bobtista force-pushed the bobtista/build/clang-tidy-fixes branch from fe57955 to 951288d Compare December 6, 2025 17:24
@xezon xezon requested a review from OmniBlade December 7, 2025 16:11
Copy link

@OmniBlade OmniBlade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing it seems that a required cmake argument is missing from the command suggested by the help text.

@OmniBlade
Copy link

A general comment I have is while this does work, it does the file checking serially and could work much faster on multi core machines if it generated multiple clang-tidy processes. I've not worked with clang-tidy that much previously so I'm not sure how easy that is to accomplish.

@bobtista
Copy link
Author

bobtista commented Dec 9, 2025

A general comment I have is while this does work, it does the file checking serially and could work much faster on multi core machines if it generated multiple clang-tidy processes. I've not worked with clang-tidy that much previously so I'm not sure how easy that is to accomplish.

Yeah I noticed this too - The script already supports parallelization via --jobs. It defaults to --jobs 1 (serial). Updating it to default to the number of CPU cores:

Copy link

@OmniBlade OmniBlade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that has addressed any issues I had. Only issue with running the script is that currently running it on anything more than a handful of files generates a lot of output to pour over.

@xezon xezon added the Build Anything related to building, compiling label Dec 10, 2025
@xezon xezon added this to the Code foundation build up milestone Dec 10, 2025
@xezon xezon changed the title build: clang-tidy build: Add clang-tidy checks and script Dec 10, 2025
@xezon xezon merged commit 9573250 into TheSuperHackers:main Dec 10, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build Anything related to building, compiling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants