Add initial support for Rust static analysis via Clippy#4862
Open
peterkmg wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for Rust static analysis using Clippy. It introduces a new Clippy analyzer, integrates it into the analyzer selection and execution flow.
Integration surface
Existing implementation and integration points for analyzers highly favours C/C++ tools which have specific per-file invocation patterns. Clippy, and Rust tooling in general, is designed to run at the Cargo project level, consuming a Cargo manifest.
Least problematic approach to integration that I've found that preserves existing analyzer flow is to extend the
analyzecli command, so it can also accept a directCargo.toml(Cargo manifest) input.General usage example:
The input must be the manifest file itself, not the project directory. If
analyzepoints to a Cargo manifest and no analyzer is specified,clippyis selected automatically, since it is currently the only analyzer supported for this input type. If another analyzer is explicitly requested with Cargo manifest input, analysis fails with an error.Since most of
analyzecommand parameters are flat and not dependant on the analyzer selected, some options are not meaningful for Cargo manifest input, but it is still possible to pass extra arguments to Cargo and Clippy through--analyzer-configparameter.For example, if
cargo-args.txtcontains:and
clippy-args.txtcontains:CodeChecker runs the equivalent of:
Arguments from
cargo-args-fileare passed to cargo clippy before--. Arguments fromcc-verbatim-args-fileare passed after--, whereclippy/rustclint flags are expected.After analysis, you can use
parseorstorecommands as usual to process the results.Diagnostic categories
Clippy run preserves
rustcdiagnostics as well. Even if project fails to compile due to code issues, output will containrustc-E*diagnostics, which are emitted withCRITICALseverity. This allows the Clippy analyzer to provide compiler diagnostics and Clippy lints in one run.Generally all diagnostics is split into three major categories:
rustc-E*- emitted by rustc, withCRITICALseverity. It is emitted when compilation fails, and contains diagnostics related to compilation errors.rustc-*- emitted by rustc, withLOWseverity and contains diagnostics related to warnings and other non-error messages.clippy-*- emitted by Clippy, withLOWseverity and contains diagnostics related to Clippy lints.Finer control
Currently, Clippy lint rule names are not exposed as first-class CodeChecker checkers. Clippy’s lint rule set depends on the installed Rust toolchain, target, project configuration, and enabled lint groups, so maintaining a static list of all supported checkers is not a trivial task.
Instead, this integration exposes stable checker groups:
These groups can be enabled or disabled through the existing checker configuration flow, while individual emitted diagnostics still preserve their concrete checker names, such as
clippy-unnecessary-map-ororrustc-E0308.This could be improved in the future by adding support for dynamic checkers emitted by analyzers at runtime.
Report conversion
Even though libraries such as sarif-rs exist, which can convert Clippy output (among other tools) to SARIF format which is already supported by CodeChecker, in reality for Clippy specifically it is a thin wrapper around the JSON output emitted by Cargo. Therefore instead of adding an extra dependency and conversion step, the Clippy analyzer directly parses Cargo JSON output, extracts relevant information, and emits CodeChecker plist format.
Testing
Changes are covered by analyzer and report-converter tests for the new Clippy flow, including command construction, configuration handling, diagnostic conversion, and edge cases around Cargo JSON output.
Manual end-to-end validation was also done using the built CodeChecker binary to analyze a real Rust project, parse the generated reports, and store them into a running CodeChecker server.

Documentation
Documentation changes are not included in this PR. If the implementation approach is accepted, I can attempt to prepare a follow-up PR with the necessary documentation updates.