Skip to content

Fix: strip target triples from replayed compile commands - #1652

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix/strip-target-triples-from-compile-commands
Aug 3, 2026
Merged

Fix: strip target triples from replayed compile commands#1652
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix/strip-target-triples-from-compile-commands

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

tests/lint/clang_tidy.py replays each changed file's compile command through
clang-tidy. clang-tidy does not run the compiler — it drives its own clang
frontend, and clang's driver reads the program name in argv[0] as a target
triple
when that name carries one (ToolChain::getTargetAndModeFromProgramName,
the mechanism behind aarch64-linux-gnu-gcc).

conda-forge and crosstool GCC install <triple>-g++ and make g++ a symlink to
it; CMake records the resolved name. So a database entry reads
.../bin/aarch64-conda-linux-gnu-g++ …, clang-tidy takes
aarch64-conda-linux-gnu as its target, matches no installed GCC (the box has
/usr/lib/gcc/aarch64-linux-gnu/10.3.1 — different vendor segment), and is left
with no C++ standard library include dirs at all. Every #include <cerrno> /
<cstdint> fails, and because Sema drops statements that fail to build, a
constructor with a real body is additionally reported as
modernize-use-equals-default. One toolchain mismatch, presented as lint errors
naming real files and real checks.

Every target in a sim compile database is host-compiled, so the triple prefix
names nothing clang-tidy needs. This drops it while rewriting each command —
next to the GCC-only flags already stripped there — and writes the database back
whenever a rewrite changed something, rather than only when a -fno-gnu-unique
was present. Directory and all other arguments are untouched.

ci-self-cpu.yml's pre-commit job additionally prefers a clang-tidy-18 when
an agent provides one, so the emergency lane lints with the same clang-tidy
major as ci.yml (ubuntu ships 18; HCE 2.0 packages only LLVM 12).

Where it fires

The self-hosted cpu lane. Its agents resolve g++ to a conda GCC 15 prefix,
and their clang-tidy is the distro LLVM 12 — which, unlike 18, does not fall
back to a compatible triple. It stayed latent because every earlier lane run
reported clang-tidy … (no files to check) Skipped; #1587 was the first
C++-touching PR through the lane, and its lane pre-commit failed on those
phantom diagnostics while the GitHub-hosted pre-commit for the same commit
passed.

Testing

Run on a cpu agent, against the changed-file set of #1587, restoring the
triple-prefixed database before each case:

clang-tidy hook result
12 (distro) before exit 1 — 'cstdint' file not found + phantom modernize-use-equals-default
12 (distro) after exit 0
18 before exit 0 (18 tolerates the prefix)
18 after exit 0
  • ruff check / ruff format / pyright clean on the hook
  • Rewrite verified idempotent, and a no-op for untouched spellings
    (/usr/bin/g++, g++-15, /opt/llvm/bin/clang++)
  • Simulation tests pass — not run; no product code changes
  • Hardware tests pass — not applicable

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7bb1e939-8777-468c-be88-47ae476e0d4a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR updates compile database normalization for target-triple-prefixed compilers and GCC-only flags. It also updates CPU runner provisioning and documentation to use clang-tidy 18 with builtin headers.

Changes

Clang-tidy CPU alignment

Layer / File(s) Summary
Compile command rewriting
tests/lint/clang_tidy.py
The linter detects target-triple-prefixed compiler names and removes GCC-only flags from both command formats.
Compile database loading and indexing
tests/lint/clang_tidy.py
Database loading handles missing or invalid files. Indexing rewrites entries and saves the database only when changes occur.
CPU runner clang-tidy setup
.github/workflows/ci-self-cpu.yml, docs/ci.md
The CPU runner conditionally selects clang-tidy-18. The CI contract documents GCC 15 resolution, compiler-name normalization, and required builtin headers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

A rabbit checks each compiler name,
Then trims the flags that cause linting pain.
Clang-tidy eighteen joins the run,
With builtin headers under the sun.
The CPU trail is neat and bright—
Hop, hop, to cleaner checks tonight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: removing target triples from replayed compile commands.
Description check ✅ Passed The description directly explains the target-triple rewrite, clang-tidy behavior, CI change, and testing results.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/ci-self-cpu.yml (1)

191-191: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Do not assume that the version appears on output line 2.

Line 191 assumes a fixed clang-tidy --version layout. If the installed package uses another layout, the log can omit the selected version or show unrelated metadata. Clang-tidy documents --version for version display, but the workflow should not depend on a fixed line number. (clang.llvm.org)

Print the complete output, or parse and validate the expected major version.

Proposed fix
-          PATH="$RUNNER_TEMP/bin:$PATH" clang-tidy --version | sed -n 2p
+          PATH="$RUNNER_TEMP/bin:$PATH" command -v clang-tidy
+          PATH="$RUNNER_TEMP/bin:$PATH" clang-tidy --version
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci-self-cpu.yml at line 191, Update the clang-tidy version
logging command in the workflow so it does not pipe output through sed -n 2p or
depend on a fixed output line; print the complete output from clang-tidy
--version, while preserving the PATH override that selects the installed
executable.

Source: MCP tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/lint/clang_tidy.py`:
- Around line 238-245: Update _parse_compile_database to validate every entry is
an object containing a valid "file" field before returning the entries, raising
ValueError for malformed entries. Keep _rewrite_entry and the later
entry["file"] access unchanged so _load_compile_database can handle invalid
databases through its existing recovery or skip behavior.

---

Nitpick comments:
In @.github/workflows/ci-self-cpu.yml:
- Line 191: Update the clang-tidy version logging command in the workflow so it
does not pipe output through sed -n 2p or depend on a fixed output line; print
the complete output from clang-tidy --version, while preserving the PATH
override that selects the installed executable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 211b281c-5724-4f19-b178-e50a7e4922e7

📥 Commits

Reviewing files that changed from the base of the PR and between c975b61 and c18abc0.

📒 Files selected for processing (3)
  • .github/workflows/ci-self-cpu.yml
  • docs/ci.md
  • tests/lint/clang_tidy.py

Comment thread tests/lint/clang_tidy.py
@ChaoWao

ChaoWao commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

/run-cpu

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

/run-cpu lane passedhttps://github.com/hw-native-sys/simpler/actions/runs/30799621412

  • ✅ detect-changes
  • ✅ pre-commit
  • ✅ ut
  • ✅ st-onboard-a5
  • ✅ ut-a2a3
  • ✅ st-sim-a2a3
  • ✅ packaging
  • ✅ st-onboard-a2a3
  • ✅ profiling-flags-smoke
  • ✅ st-sim-a5
  • ✅ ut-a5

@ChaoWao
ChaoWao force-pushed the fix/strip-target-triples-from-compile-commands branch from c18abc0 to f6f8b58 Compare August 3, 2026 09:50
A compiler whose program name carries a target-triple prefix — conda and
crosstool GCC ship `<triple>-g++` with `g++` as a symlink to it, and CMake
records the resolved name — makes clang-tidy adopt that triple as its
target. It then matches no installed GCC, so it receives no C++ standard
library include dirs and fails on the first `#include <cstdint>`. Sema
drops the statements that fail to build, which additionally reports
constructors with a real body as modernize-use-equals-default: one
toolchain mismatch surfaces as lint errors that name real files and real
checks.

Every target in a sim compile database is host-compiled, so the prefix
names nothing clang-tidy needs. Drop it while rewriting each command,
next to the GCC-only flags already stripped there, and write the database
back whenever a rewrite changed it rather than only on a flag match. A
database whose entries are not objects naming a file is now rejected at
parse time, so it takes the existing reconfigure-or-skip recovery instead
of raising out of the rewrite.

The self-hosted cpu lane is where this fires: its agents resolve `g++` to
a conda GCC 15 prefix, and its clang-tidy is the distro LLVM 12, which
unlike 18 does not fall back to a compatible triple. Verified on an agent
against the changed files of the PR that first exercised the hook there —
LLVM 12 fails before the rewrite and passes after it; LLVM 18 passes
either way. The lane's pre-commit job now also prefers a `clang-tidy-18`
when an agent provides one, so it lints with the major ci.yml uses.
@ChaoWao

ChaoWao commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai Addressed the review-body nitpick as well:

  • .github/workflows/ci-self-cpu.yml:191 — dropped | sed -n 2p. The step now prints command -v clang-tidy and the full --version output under the same PATH override, so the log records which binary was selected and its complete version banner without depending on LLVM keeping the version on line 2. Left it a diagnostic rather than a version assertion — turning it into a gate would add a failure mode for a line whose only job is to make the lane log self-explanatory.

The inline finding on tests/lint/clang_tidy.py is fixed and resolved in its own thread.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@ChaoWao Confirmed. The diagnostic now records the selected binary and its complete version output without relying on a fixed output line. This addresses the review-body nitpick.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@ChaoWao
ChaoWao merged commit bb9f6cf into hw-native-sys:main Aug 3, 2026
32 of 33 checks passed
@ChaoWao
ChaoWao deleted the fix/strip-target-triples-from-compile-commands branch August 3, 2026 11:26
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