Skip to content

feat: support c, c++ and assembly as one cmake language - #323

Merged
possiblyneal merged 3 commits into
mainfrom
possiblyneal/add-c-cpp-asm
Nov 18, 2026
Merged

possiblyneal merged 3 commits into
mainfrom
possiblyneal/add-c-cpp-asm

Conversation

@possiblyneal

@possiblyneal possiblyneal commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Intent

Operator request in session: add C, C++ and assembly as template languages, built by CMake, with firmware ship targets deferred until a firmware unit exists.

Before this change, a repository holding C, C++ or assembly got no lint, format, build, test or CodeQL coverage, and the gate reported nothing for it. After it, a root CMakeLists.txt makes cpp present:

  • clang-tidy and clang-format run over the repository's own C/C++ files.
  • CMake builds into the root build/ and ctest runs the tests.
  • CodeQL scans c-cpp with build-mode: none.

All of this lands in both the root and the payload.

Read first

  • scripts/libs/detect.sh:250 — cpp_sources, cmake_configure, _cmake_translation_units (logical-or-physical path match) and the cpp adapters, through the _capability_test_cpp enable_testing guard; _cmake_owned_elsewhere at :380 narrows the orphan search
  • docs/adrs/0011-support-c-cpp-and-assembly-as-one-cmake-language.md — the decision and the three probed behaviours that shaped the adapters
  • scripts/tests/capabilities-test — the probe table's new cpp column, plus eight new fixtures: detection, the orphan CMakeLists.txt, a CMakeLists.txt owned by another build, the lint unit set, lint through a symlinked checkout, the enable_testing refusal (indented add_test() and discovered-test include()), and a dependency's own tests
  • Mechanical: every apps/github-repository-template/src/base-repo/scripts/ and .github/ file is a byte copy of its root counterpart (scripts/payload-parity passes); docs/adrs/index.md is generated

Decisions

  • One cpp language over three separate languages, because one build file compiles all three and CodeQL already treats C and C++ as one language.
  • CMake over GNU Make, because only CMake reports a compilation database, a test registry and a target list. Make would need each repository to keep those lists by hand.
  • The clang tools get the compile DB intersected with cpp_sources, not the whole DB, because clang-tidy fails on .S and the DB also lists vendored and build/ sources.
  • lint-fix runs clang-tidy --fix without --warnings-as-errors, because with that flag it exits 1 even after it has applied the fixes.
  • A project with no tests passes the test check, matching pytest's treatment, but a nested CTestTestfile.cmake declaring a test (an add_test(), indented under a multi-config generator, or the include() gtest and Catch2 discovery writes) with no top-level one is refused, because ctest would skip those tests silently. Files under build/_deps/ and vendor/ are a dependency's and do not count.
  • A nested CMakeLists.txt below a src/ or beside another language's manifest is not an orphan: it is that language's native build (Android NDK, scikit-build, cmake-js), and flagging it would fail existing Kotlin, Python and Node repositories.
  • gcc-only flags reaching clang-tidy are left as a documented consequence in ADR 0011, not worked around, because choosing the lint compiler is each repository's call.
  • run and package are left absent, not stubbed, so scripts/run and scripts/package report unavailable for a C/C++ unit (the same gap Swift has for run).
  • CMakeLists.txt gets no Dependabot mapping, because Dependabot has no CMake ecosystem.
  • ADR 0001's "Go and Rust are the only languages that build an executable" is left unedited. ADRs are not rewritten, and it is still true, since cpp has no package adapter.
  • apps/repo-builder/src/scripts/retrofit.py's MANIFESTS does not gain CMakeLists.txt, because C/C++ tools are found on PATH and never declared in a manifest.

Out of scope

  • Firmware ship targets, and a run/package adapter for cpp: deferred until a firmware unit exists (ADR 0011).
  • A C/C++ dependency audit and vcpkg or Conan Dependabot entries: added when a repository adopts one.

Verified

  • scripts/check → EXIT=0, every row pass or not-applicable
  • scripts/check at 9ab1e47 → EXIT=0
  • scripts/tests/capabilities-test → 79 passed, 0 failed. Each new fixture fails under a mutation of its fix: dropping the logical-path strip, the _deps/vendor prune, the declared-test grep, its include alternative, its leading-space allowance, or the _cmake_owned_elsewhere call each gives one failure. The enable_testing fixture fails when the guard's return 1 is replaced with true, and the lint fixture fails when the duplicate-unit unset is removed
  • scripts/tests/clean-test → 3 passed; scripts/tests/structure-test → 84 passed
  • scripts/payload-parity → the root and payload .github/ and scripts/ trees agree
  • Against a real CMake project mixing C and assembly, run with language_capabilities run <check> on host CMake 3.31.6 and clang-format/clang-tidy 19.1.7: toolchain, lint, format-check, build, test, lint-fix and format-write pass; typecheck, audit and integration not-applicable; run and package unavailable; codeql-matrix emits {"language":"c-cpp","build-mode":"none","runner":"ubuntu-latest"}

Not verified

  • No CI run yet. The setup action's "Report C and C++ toolchain" step only runs when cpp is detected, and this repository has no CMakeLists.txt, so CI here never runs it.
  • Tested only against the host's clang 19. The Ubuntu 24.04 runner image ships clang 16–18.
  • The symlink, _deps and orphan-ownership fixes are covered by stubbed fixtures only, not a real symlinked checkout, FetchContent build, or NDK project.
  • C++ sources, FetchContent, and the CodeQL analysis job itself were not run.
  • Not tested in a generated repository.

Merge danger

Door: two-way: a revert restores everything; no data, schema or published interface changes.

Blast radius:

  • Every repository generated after this merge, which gets the new detect.sh. Its searches now prune the root build/ for every language, so nothing under it is linted, formatted or collected. scripts/clean already removed that build/ through its name search, and now removes it by path.
  • scripts/structure's root allowlist gains three files.
  • language_capabilities probe output gains seven cpp rows, and the detect GitHub output gains cpp=.
  • The /repo-builder lifecycle.md Dependabot and first-manifest guidance.

neal added 3 commits November 18, 2026 13:17
Microcontroller firmware mixes a startup file in assembly, a HAL in C
and application code in C or C++ inside one build target, so the three
are one detected language, cpp, present when the root holds a
CMakeLists.txt. Three detectors over one build file would give three
adapter columns that could never differ, and CodeQL already counts C
and C++ as the single language c-cpp.

CMake over GNU Make because the checks need what only CMake reports: a
compilation database for clang-tidy, a test registry for ctest, and,
for the run and package adapters still to come, the File API's list of
executables. Make would push all three onto a list each repository
keeps by hand.

clang-tidy and clang-format read the compilation database intersected
with the repository's own C and C++ files. That drops assembly, which
neither tool can parse, along with vendored trees and sources fetched
or generated into build/. The root build/ is pruned from every search,
since FetchContent clones dependency trees into it, and scripts/clean
removes it by path.

ctest reads only the top-level CTestTestfile.cmake, which CMake writes
only when the root calls enable_testing(). A unit's own call leaves
every add_test() below it skipped behind a passing "No tests were
found", so the test adapter refuses a nested test file that has no
top-level one.

run and package stay absent, so scripts/run and scripts/package report
unavailable for a C or C++ unit. A firmware unit's ship targets wait
until one exists. ADR 0011 records the decision.

Generated-By: claude-opus-5-5
Correctness review of #323 found three ways the cpp adapters misreport:

- clang-tidy matched compile_commands.json entries against `pwd -P`, but
  CMake writes the logical path it ran from, so a checkout reached through
  a symlink linted no units and passed. Entries are now compared relative
  to either path.
- the enable_testing guard fired on any nested CTestTestfile.cmake,
  including a dependency's under build/_deps that calls include(CTest),
  failing a project with no tests. It now refuses only a nested file that
  declares add_test(), outside _deps/ and vendor/.
- the orphan search reported every nested CMakeLists.txt in a repository
  with no root one, including an Android NDK library under src/ or a
  scikit-build or cmake-js build beside its own manifest, so existing
  Kotlin, Python and Node repositories would fail detection. Those are now
  left to the language that owns them.

The fourth finding, gcc-only flags reaching clang-tidy as unknown
arguments, is recorded as a consequence in ADR 0011 rather than worked
around, since choosing the lint compiler is the repository's call.

Also applies the standards review's wording fixes: the language counts in
scripts/package, dependabot-entries-test and the structure doc, and the
Dependabot exception in the adding-a-language rule.

Generated-By: claude-opus-5-5
The narrowed enable_testing guard matched only a line starting add_test(,
but gtest_discover_tests and catch_discover_tests write an include() of
the discovered list in its place, and multi-config generators indent
add_test() under if(CTEST_CONFIGURATION_TYPE ...). Either let a unit's
tests be skipped with "No tests were found" again. The guard now matches
an optionally indented add_test( or include(; a subdirs()-only file still
declares nothing.

Generated-By: claude-opus-5-5
@possiblyneal possiblyneal added the code-reviewed Multi-axis code review passed label Nov 18, 2026
@possiblyneal

Copy link
Copy Markdown
Owner Author

Code review: standard scan, clean.

Axes: Standards+Spec, Correctness/Logic

Reviewed-Head: 9ab1e47

@possiblyneal
possiblyneal merged commit 9373411 into main Nov 18, 2026
7 checks passed
@possiblyneal
possiblyneal deleted the possiblyneal/add-c-cpp-asm branch November 18, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-reviewed Multi-axis code review passed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant