Skip to content

Mandatory C++ linter migration: Rust-only via build-on-change cache, retire Python checkers #3288

Closed

Description

@zackees

Goal

Make the Rust C++ linter (ci/lint_cpp_rs/, binary fastled-lint) the mandatory default everywhere — on-save hook, Stop hook, bash lint, and CI. Retire the Python checkers in ci/lint_cpp/*.py once the Rust port is at parity. The Rust binary should be compiled on first use and after any source change, and otherwise invoked directly with no soldr/build cost.

Current state (audit, 2026-06-19)

  • Python linter: 85 .py checker files in ci/lint_cpp/, dispatched by ci/lint_cpp/run_all_checkers.py. This is the default path everywhere.
  • Rust linter: single crate ci/lint_cpp_rs/ (package fastled-lint), covers 60 checkers declared in RUST_SUPPORTED_CHECKERS (frozenset in ci/lint_cpp/rust_bridge.py:16-79).
  • Activation: Rust path is opt-in behind a --rust flag (ci/lint/args_parser.py:115-119, default False). Nothing passes it today:
    • ci/hooks/lint-on-save.py:121 — no --rust
    • ci/hooks/check-on-stop.py:377-381 — no --rust
    • .github/workflows/template_unit_test.yml:57 — runs one standalone Python checker, never invokes bash lint
  • soldr is NOT in pyproject.toml (pins fbuild==2.2.28 and zccache>=1.12.7; soldr is absent). The ci/hooks/rust_tool_guard.py:9-11 comment assumes soldr is on PATH; if it isn't, subprocess.run([\"soldr\", ...]) in rust_bridge.py:96 will FileNotFoundError.
  • Fingerprint infrastructure already exists: ci/fingerprint/core.py:391-583 ships TwoLayerFingerprintCache and HashFingerprintCache, both backed by the zccache-fingerprint CLI which is guaranteed by zccache>=1.12.7 in pyproject.toml. Used today by ci/python_lint_cache.py, ci/cpp_lint_cache.py, ci/js_lint_cache.py.

Verdict on build strategy

Full JIT (rebuild-check on every invocation) is not required. The simpler and more robust contract is:

The fastled-lint binary is rebuilt only when (a) it doesn't exist yet, or (b) the Rust crate's sources changed. Otherwise the cached binary is invoked directly — zero build-tool overhead per lint call.

This sidesteps the per-invocation fingerprint-scan tax (~300–800ms on Windows) and removes the hard dependency on soldr being installed at every lint call — soldr is only needed during the rare rebuild path.

Design

1. Make Rust toolchain available

  • Add soldr to pyproject.toml as a guaranteed dependency (or document the bootstrap step in install so every developer + CI runner has it before we flip the default).
  • Continue using soldr to drive the actual rebuild path (it warms zccache and the shared target tree, per ci/hooks/rust_tool_guard.py:9-11).
  • If soldr no-op overhead still exceeds ~500ms after install, file a separate soldr upstream bug — but this issue does not depend on that, because we skip the build-tool invocation entirely on the cache-hit path.

2. Build-on-change wrapper

New helper (e.g. ci/lint_cpp/rust_binary_cache.py) that:

  1. Resolves the expected binary path: ci/lint_cpp_rs/target/release/fastled-lint{,.exe}.
  2. Computes a HashFingerprintCache over:
    • ci/lint_cpp_rs/src/**/*.rs
    • ci/lint_cpp_rs/Cargo.toml
    • ci/lint_cpp_rs/Cargo.lock
    • (optionally) rust-toolchain.toml if present
  3. Decision:
    • Binary missing → run soldr build, then update fingerprint.
    • Fingerprint changed → same rebuild, then update fingerprint.
    • Fingerprint unchanged AND binary exists → no soldr call. Caller invokes the binary directly.
  4. Caller (rust_bridge.py) switches from the current soldr ... run --release --bin fastled-lint -- ... to <cached_binary_path> .... This removes per-invocation build-tool overhead.

The fingerprint key uses the same zccache-fingerprint CLI everything else in ci/ uses — no new infra.

3. Wire Rust as the default

Once the wrapper lands and parity is verified (the existing A/B mode FL_LINT_AB=1 in run_all_checkers.py:904 + rust_bridge.py:159 run_rust_ab_check already supports this):

  • Flip --rust default to True in ci/lint/args_parser.py.
  • Update ci/hooks/lint-on-save.py:121 and ci/hooks/check-on-stop.py:377-381 to use the default (no change needed once default flips).
  • Add a CI step that runs bash lint --cpp (which will now use Rust by default) in at least one workflow — .github/workflows/template_unit_test.yml is the obvious target.
  • Keep --no-rust as an escape hatch during the deprecation window.

4. Port the Python-only checkers

RUST_SUPPORTED_CHECKERS covers 60 checkers. Approximately 12 Python checkers remain:

  • BareLibmChecker, BareNoInlineChecker, BareSnprintfChecker
  • LegacyLogMacroChecker
  • PublicSettingsPatternChecker
  • pch_file_checker.check, test_unity_build.check, test_aggregation_checker.check
  • SubdirNamespaceChecker(\"net\"/\"video\"/\"task\") instances at run_all_checkers.py:273-281
  • Other special-case BannedHeadersChecker instances

Plus two AST-based checks that use clang-query:

  • run_noexcept_ast_check in run_all_checkers.py:565-608 → ci.tools.check_noexcept.find_missing_noexcept
  • run_array_param_ast_check in run_all_checkers.py:611-652 → ci.tools.check_array_params.find_decayed_array_params

These call out to the existing clang-query ratchet tools; the Rust path can keep shelling out to those Python tools, or we port them to a libclang Rust binding. Either way, this issue does not require porting them — the Rust binary can fall back to the Python AST tools as subprocesses while we get parity on the regex/text checkers.

5. Retire the Python checkers

Once all 60+ checkers have Rust equivalents and FL_LINT_AB=1 shows zero divergence for one release window:

  • Delete the .py checker files in ci/lint_cpp/*_checker.py.
  • Delete ci/lint_cpp/rust_bridge.py's Python-dispatch fallback.
  • Delete the orphan cpp_lint.py at the repo root (already dead — no caller).
  • Keep run_all_checkers.py only as the thin orchestrator that invokes the Rust binary + the AST ratchet subprocesses.

Acceptance criteria

  • soldr is pinned in pyproject.toml (or bootstrapped by install) so it is guaranteed present.
  • New ci/lint_cpp/rust_binary_cache.py builds fastled-lint on first use and on source change; otherwise no-op.
  • rust_bridge.py invokes the cached binary directly (no build-tool call per lint invocation).
  • --rust is the default in ci/lint/args_parser.py; --no-rust is the escape hatch.
  • At least one GitHub Actions workflow runs bash lint --cpp (Rust path) on every PR.
  • FL_LINT_AB=1 parity test passes for all 60 checkers in RUST_SUPPORTED_CHECKERS.
  • Python .py checker files in ci/lint_cpp/ whose Rust port has parity are deleted.
  • On-save hook latency for the no-op case (no source change, no Rust rebuild) is measured and reported in this issue.

Out of scope

  • Porting the clang-query AST ratchet tools (noexcept + decayed-array-param) to native Rust. Keep them as Python subprocesses for now.
  • Sub-500ms soldr no-op performance work. Tracked separately if needed — this design avoids invoking soldr at all on the hot path.

Related files

  • ci/lint_cpp/rust_bridge.py:16-79, 94-120, 159
  • ci/lint_cpp/run_all_checkers.py:170-342, 565-652, 904-960
  • ci/lint/args_parser.py:115-119
  • ci/lint/stage_impls.py:226-227
  • ci/lint_cpp_rs/Cargo.toml, ci/lint_cpp_rs/src/lib.rs
  • ci/fingerprint/core.py:391-583
  • ci/hooks/lint-on-save.py:121
  • ci/hooks/check-on-stop.py:377-381
  • ci/hooks/rust_tool_guard.py:9-11
  • .github/workflows/template_unit_test.yml:57
  • pyproject.toml (add soldr)
  • cpp_lint.py (delete — orphan)

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions