Compilation databases and agent workflows
CLAP can emit a Clang compilation database (compile_commands.json) for direct builds. CMake builds already export the same database into the CMake build directory because CLAP configures them with CMAKE_EXPORT_COMPILE_COMMANDS=ON.
Generate it explicitly for a direct build:
clap build main.c util.c --compile-commands
# or choose the destination
clap build main.c util.c --compile-commands-output .clangd/compile_commands.jsonThe generated file is ordinary JSON in the format consumed by clangd-style tools. Each entry contains:
| Field | Meaning |
|---|---|
directory | working directory used for the compilation command |
file | absolute source file path |
output | object-file path used by CLAP/Ninja |
arguments | exact compiler argument vector, including language standard, target, includes, defines, and flags |
CLAP writes arguments rather than a shell-quoted command string. That avoids quoting ambiguity on Windows paths containing spaces or Unicode characters.
Editor and analyzer consumers
clangd
Point clangd at the project root or copy/symlink the database there:
clap build main.c util.c --compile-commands-output compile_commands.jsonFor direct multi-file projects this is usually the simplest setup: restart clangd after regenerating the file. For CMake projects, point clangd at build/compile_commands.json or symlink it into the project root.
Microsoft C/C++ extension
clap vscode writes .vscode/c_cpp_properties.json with compileCommands set to ${workspaceFolder}/compile_commands.json, plus a CLAP: Build task that regenerates that file. Existing unrelated VS Code configuration is preserved.
clang-tidy and other Clang tools
Most Clang-based tools accept -p:
clang-tidy main.c -p compile_commands.jsonThe exact flag spelling depends on the tool version; consult that tool's documentation. CLAP only guarantees that the database itself follows the standard JSON shape.
Agent workflow
For an AI agent or automation, prefer JSON CLI output and stable files over terminal scraping:
- Run
clap inspectto determine project sources, dependency metadata, cache state, and platform overrides. - Run
clap build ... --compile-commands --jsonorclap test ... --json. - Read
compile_commands.jsonwhen exact per-source compiler arguments are needed. - Read
clap.spdx.jsonwhen dependency/provenance metadata is needed. - Treat diagnostics in the JSON
diagnosticsarray as structured data; use stdout/stderr only as fallback context.
A compact agent loop is:
clap inspect > inspect.json
clap build --compile-commands --json > build.json
clap test --junit-xml test-results.xml --json > test.jsonThe build may use direct source discovery, clap.toml, or a CMake project; the agent does not need to know which one before inspect runs.
Regeneration and staleness
Compilation databases are build metadata, not dependency locks. Regenerate them after changing:
- source file lists;
- include paths, defines, libraries, or language standards;
- compiler selection or target triple;
- platform-specific project overrides;
- generated sources or generated headers.
compile_commands.json does not itself cause rebuilds. Ninja incremental state remains in .clap-ninja/ for direct builds or in the CMake build directory for CMake builds.