Skip to content

CLAP command reference ​

The complete reference for every command, flag, and feature. For a quick introduction see the README; for runnable projects see examples/.

Quick start in detail ​

bash
clap init hello
cd hello
clap run

# other starting points:
# clap init app --template cpp
# clap init app --template mixed
# clap init app --template library
# clap init app --template cmake
# clap init app --template cmake-library
# clap init app --template greatest  # C unit-testing project with real assertions
# clap init app --ci   # also generate a GitHub Actions CI workflow
# clap init --adopt .  # existing code? write only clap.toml adopting your sources

Or compile a file directly:

bash
clap run main.c
clap run main.cpp
clap build main.c -o hello
clap build main.c util.c -j 8  # compile objects in parallel
clap build src/                  # directories expand recursively; globs work everywhere, even PowerShell
clap run main.c --sanitize undefined  # catch undefined behaviour at runtime
clap run main.c --system --sanitize address  # AddressSanitizer via system GCC/Clang
clap build main.c --coverage       # write compiler coverage instrumentation
clap run main.c --coverage-report  # write .gcov files plus text/JSON summaries
clap build main.c --timing         # print phase and executed-edge timings
clap build main.c --check  # syntax-check without linking
clap build main.c --warnings --warnings-as-errors  # strict warning hygiene
clap build main.c --verbose  # show exact compiler and linker commands
clap build main.c --dry-run  # inspect the build plan without artifacts
clap run main.c -- arguments for the program

When no files are passed and no clap.toml exists, CLAP conservatively autodiscovers a simple layout: a unique main.c/main.cpp-style entrypoint plus its sibling source files in the project root or src/, or exactly one source file in either location. Ambiguous or recursive multi-directory projects still need explicit files or clap.toml; autodiscovery is a zero-config convenience, not a replacement for project configuration.

Useful commands:

bash
clap doctor       # show compiler, build tools, pkg-config, and cache state
clap doctor --probe  # compile tiny C and C++ health checks
clap bootstrap    # download and verify the private toolchain now
clap bootstrap --warmup  # also precompile the C/C++ runtime cache
clap toolchain list    # show cached toolchains and sizes
clap toolchain info    # show pinned/active toolchain details
clap toolchain verify  # verify cached toolchain markers/executables
clap toolchain prune   # remove stale or incomplete cached toolchains
clap toolchain delete --yes  # remove the current cached toolchain
clap inspect .      # stable JSON project/toolchain/cache metadata for editors and agents
clap vscode         # write VS Code tasks and IntelliSense configuration
clap lock           # record pkg-config dependency versions and flags
clap deps           # check dependency lock, paths, and vcpkg status
clap build        # build without running
clap cmake .      # configure and build a CMake project
clap cmake . -j 8  # parallel CMake build
clap cmake . --release  # CMake Release configuration
clap cmake . --install --prefix out  # build and install into ./out
clap clean --cache  # remove build outputs and cached toolchains
clap completion bash  # print shell completion for the current CLI

Shell completion ​

CLAP generates completion scripts from the same argparse surface as the running CLI, so new commands and flags do not drift from a hand-written completion file:

bash
eval "$(clap completion bash)"   # current Bash shell
eval "$(clap completion zsh)"    # current Zsh shell
clap completion fish > ~/.config/fish/completions/clap.fish

For persistent Bash installation, write the output as ~/.local/share/bash-completion/completions/clap. For persistent Zsh installation, write it as _clap in a directory listed in fpath. Bash completion behavior is regression-tested directly; all three shells are generated from the same parser metadata.

Examples ​

Small runnable examples live in examples/:

bash
clap run examples/hello/main.c
clap run examples/mixed/answer.c examples/mixed/main.cpp
clap cmake examples/cmake
clap test examples/tests/test_arithmetic.c examples/tests/test_boolean.c

(cd examples/zero-config && clap run)       # autodiscover main.c + util.c
(cd examples/library && clap build)          # build libanswer.a / answer.lib
(cd examples/pkg-config-zlib && clap run) # with zlib pkg-config installed

The mixed example is the important one: answer.c is compiled as C, main.cpp as C++, and the final link uses the C++ driver.

Compiler flags go in --flag; linker-only flags go in --link-flag (use --link-flag=-lm for values starting with a dash). Portable -I/--include, -D/--define, --library, --library-path, and pkg-config --package options are translated into GCC/Clang or MSVC syntax. In Ninja and mixed-language builds linker-only flags are kept out of per-object compile commands and are added only when linking.

Build profiles ​

--profile selects a small built-in preset without replacing normal project configuration:

bash
clap build main.c --profile debug
clap build main.c --profile release
clap build main.c --profile windows-x86_64
clap build main.c --profile windows-arm64
clap build main.c --profile linux-x86_64
clap build main.c --profile linux-arm64
clap build main.c --profile macos-x86_64
clap build main.c --profile macos-arm64

debug and release map to the same portable optimization/debug flags as --debug and --release. Cross profiles select Zig/Clang target triples (windows-x86_64 uses x86_64-windows-gnu, linux-x86_64 uses x86_64-linux-gnu, windows-arm64 uses aarch64-windows-gnu, linux-arm64 uses aarch64-linux-gnu, and the macOS profiles use the matching macOS triple). The linux-x86_64-musl/linux-arm64-musl profiles produce fully static Linux binaries with zero runtime dependencies. clap targets lists every profile from the CLI. Explicit --target, --release, --debug, or --output still wins. Profile builds use separate default output names such as main-windows-x86_64.exe so a cross build does not overwrite the host binary.

Repeat --profile to matrix-build several targets in a single invocation — each target produces its own profile-suffixed binary:

bash
clap build main.c --profile windows-x86_64 --profile macos-arm64 --profile linux-arm64

clap dist — release packaging ​

clap dist is the release-engineering command: it cross-compiles the project for a matrix of targets and packs each binary into a distributable archive, in one invocation:

bash
clap dist

Produces in dist/:

hello-0.1.0-linux-x86_64-musl.tar.gz    # static musl binary + LICENSE/README when present
hello-0.1.0-linux-arm64-musl.tar.gz
hello-0.1.0-windows-x86_64.zip          # hello.exe inside
checksums.txt                           # sha256 of every archive
  • The default matrix is linux-x86_64-musl, linux-arm64-musl, windows-x86_64 — all static or self-contained. Override with repeated --profile flags (clap dist --profile release --profile macos-arm64).
  • Archive names use the project name and the [project] version key from clap.toml (default 0.1.0).
  • Windows payloads always carry the .exe suffix.
  • A target that fails to build does not block the rest — failures are listed at the end and the exit code is nonzero, but every successful target is still packed.
  • Works for direct source files too: clap dist main.c (version falls back to 0.1.0).
  • --outdir relocates the output directory; --json prints machine-readable artifact metadata.

clap update — refresh stale curated pins ​

bash
clap update          # report which curated pins drifted behind the registry
clap update --apply  # re-pin and re-vendor them

Beyond curated names and full URLs, clap add owner/repo resolves a GitHub repository shorthand: CLAP reads the repository's HEAD commit through git ls-remote (no API rate limits) and pins the tarball of exactly that commit. Version pinning works the same way: clap add owner/repo@v1.2 resolves the tag or branch — annotated tags are peeled to the tagged commit, because the tag object itself has no tarball — and clap update then tracks that ref rather than HEAD, so version-pinned dependencies stay put exactly as intended while the upstream repository moves on — the pin stays reproducible because the commit hash is baked into the URL and the SHA-256 is verified on every sync. When the vendored tree ships compilable .c files the pin does not cover, CLAP says so and prints the sources = [...] line to add to the dependency block. If the repository cannot be resolved (or git is missing), the error says to pass a full tarball URL instead.

Curated registry entries occasionally move to newer upstream versions as CLAP itself is released. clap update compares every [dependencies] pin in clap.toml against the registry of your installed clap: matches are reported up to date, mismatches get re-pinned and re-vendored with --apply (verify-before-write, like clap add --force). GitHub commit-archive pins — everything clap add owner/repo produces — are tracked too: clap update re-resolves the upstream HEAD through git ls-remote, reports repositories that moved ahead, and --apply re-pins to the latest commit. Other URL pins are reported as untracked — CLAP cannot know their upstream. Nothing mutates without --apply.

clap install — put the binary on your machine ​

bash
clap install

Builds the project in release mode and copies the binary into ~/.local/bin (override with --prefix /some/prefix — the binary lands in <prefix>/bin). Prints a hint when that directory is not on your PATH. --profile selects a cross target instead of the host release build; --json reports the destination machine-readably. This is the single-platform companion of clap dist: dist packages archives for distribution, install puts the binary on this machine.

Release automation in generated CI ​

clap init --ci (executable templates) writes a workflow whose release job runs exactly this pipeline: a v* tag push builds the matrix with clap dist and attaches the archives to the GitHub release. To cut a release of your project: git tag v1.0.0 && git push --tags — nothing else to configure.

Matrix builds apply to clap build only; run/test and explicit --target combinations fail fast because executing several cross binaries in one command would be meaningless.

On Linux hosts with qemu-user installed, foreign-architecture Linux binaries are not just built but executed — clap run --profile linux-arm64-musl prints real output from an ARM64 binary on an x86_64 machine, transparently through binfmt_misc or the qemu binary. Static musl builds are the reliable shape for this; see the cross-compilation guide.

Watch mode ​

--watch (-w) rebuilds and restarts automatically when source files change:

bash
clap run main.c --watch
clap test --watch

The watcher observes every C/C++ source, header, CMake file, and clap.toml under the input directories (build output trees excluded) and polls for mtime/size changes — no extra dependencies. While a program is still running, a detected change terminates the whole process tree before the rebuild, matching Ctrl+C interruption semantics. Output files, object caches, and generated Ninja files never trigger restarts. Stop with Ctrl+C.

Objects and libraries ​

Executables are the default, but direct builds can also emit the artifacts a compiler frontend is expected to produce:

bash
clap build util.c --artifact object   # util.o / util.obj
clap build util.c --artifact static   # libutil.a / util.lib
clap build util.c --artifact shared   # libutil.so / util.dll / libutil.dylib
clap build util.c --artifact asm      # util.s assembly (Zig/GCC/Clang backends)
clap build util.c --artifact preprocess  # util.i preprocessed source

With several sources, --artifact object treats -o as a directory and writes one object per source. Static archives use zig ar, MSVC lib.exe, or the system ar depending on the active compiler. These modes compose with --ninja, so repeated builds stay incremental. Assembly artifacts are portable too. MSVC emits documented assembler listings with /FA and /Fa; because MSVC cannot suppress the companion object file, CLAP writes that implementation detail to a hidden .clap-assembly-objects directory. Preprocessing uses /P and /Fi on MSVC and -E on Zig/GCC/Clang.

Windows, minus the setup ritual ​

On a Windows machine with only Python installed:

powershell
python -m pip install clap-compiler
clap bootstrap
clap run main.c

CLAP downloads a pinned Zig archive, checks its SHA-256 digest and exact size, extracts it into the user cache, and invokes it without touching global system state. Concurrent first-run bootstraps share a cache lock instead of downloading or replacing the same toolchain twice. clap bootstrap --warmup additionally compiles minimal C and C++ programs so the first real build does not pay the one-time compiler runtime cache cost.

A Windows executable can also be produced from Linux or macOS:

bash
clap build main.c --target x86_64-windows-gnu
clap cmake . --target x86_64-windows-gnu  # CMake projects can cross too

Windows outputs automatically receive .exe when the target is Windows. CMake cross-builds use the pinned Zig/Clang-style target triple, set the matching CMake system name and processor, and avoid running try-compile executables on the host.

For project paths longer than the classic Windows MAX_PATH, enable Win32 long-path support and invoke CLAP from a shorter working directory with explicit deep input/output paths, for example clap build C:\deep\project\main.c -o C:\deep\project\main.exe. CLAP keeps Ninja compiler child processes in a valid short working directory and can execute deep output binaries. Windows itself does not allow a new process to inherit a current directory longer than MAX_PATH, so cd C:\deep\project followed by clap ... remains an operating-system limitation rather than something a compiler frontend can bypass.

Testing ​

For a CMake project, clap test builds the project and runs CTest. For a direct source file — or a clap.toml executable project without a tests/ directory — it builds the executable and runs it, using the program exit code as the test result. When a conventional tests/ directory holds test files, bare clap test discovers them and runs each as an independent executable — zero arguments needed. Inside a project, each test additionally links the project's own sources (everything except the translation units carrying main()), so tests can exercise real project code instead of being forced self-contained. Library projects (artifact = "static"/"shared") are fully supported: tests are the way you verify a library, since the artifact itself cannot run — clap init --template library scaffolds exactly this layout, and bare clap test works out of the box. Running or testing explicit files always produces an executable regardless of the project's artifact type; only clap build honors artifact. This applies both to source-less test projects (exactly what clap init --template test scaffolds) and to regular projects: running the tests is what clap test means, while running the main binary remains clap run's job. Arguments after -- go to the test executable:

bash
clap test . -- --verbose
clap test tests/                 # direct .c/.cpp files in a tests directory
clap test "tests/*.c"              # explicit cross-platform glob expansion
clap test test_math.c test_string.c  # independent test executables
clap test test_math.c test_string.c -j 2  # build/run independent tests in parallel
clap test tests/ --fail-fast            # stop sequential tests at first failure
clap test . --junit-xml build/test-results.xml

Explicit glob patterns such as "tests/*.c" are expanded deterministically by CLAP, which also makes the same command usable on Windows without shell globbing. When a directory named test or tests without its own clap.toml/CMakeLists.txt is passed, CLAP conservatively expands direct child .c/.cpp files as independent test sources; project directories are unchanged. When multiple source files are passed to clap test, CLAP builds each file as its own executable in .clap-tests/, runs them sequentially by default or in parallel with -j/--jobs, and aggregates pass/fail results. For direct tests, --fail-fast stops sequential execution after the first failure and is intentionally rejected for parallel mode because already-running test processes cannot be un-started honestly. For CMake projects it maps to CTest --stop-on-failure. This is intended for independent test binaries; shared production code should be linked through a project configuration or represented in CMake.

--object-cache (or object_cache = true) enables an opt-in content-addressed object cache for direct and CMake GCC/Clang/Zig Ninja builds. Cache entries are keyed by compiler identity/version, language mode, normalized compile flags, source content, and the content of compiler-reported dependencies; changing a header or system header prevents stale reuse. Direct builds use generated Ninja rules; CMake builds use C/C++ compiler launchers while keeping CMake in control of configure/link/test logic. GCC/Clang .gcno coverage notes are cached as object sidecars when coverage instrumentation is enabled. Relative project dependencies can hit across moved clean checkouts. The cache is capped at 512 MiB by default (CLAP_OBJECT_CACHE_MAX_BYTES overrides that), corrupted entries are ignored, and clap clean --cache removes it together with private toolchains. MSVC, dry-run/check, assembly, and preprocessing are outside scope. CMake object caching requires CLAP's default Ninja generator and refuses user compiler or compiler-launcher overrides rather than silently replacing them.

Local maintainer measurements for cold, no-op, incremental, coverage-report, raw-compiler/CMake comparison, and object-cache builds live in PERFORMANCE.md and can be refreshed with python scripts/benchmark.py --format markdown --output docs/PERFORMANCE.md; individual measurements can be iterated with repeatable --scenario NAME selection, including parallel-j1/parallel-j4 Ninja scaling measurements.

--junit-xml writes a JUnit XML report for CI systems. Direct tests include the executable runtime; CMake tests use CTest’s native per-test JUnit output when available, with a simple fallback report if CTest cannot write the file. --coverage enables compiler coverage instrumentation for GCC/Clang direct and CMake builds. --coverage-report [DIR] implies it, runs gcov (or llvm-cov gcov for Clang), and writes .gcov files, line/branch summary.txt, a self-contained index.html, coverage-summary.json, and Cobertura-style coverage.xml with branch condition coverage when the compiler reports branches; for CMake projects CLAP recursively uses test/run coverage data from the CMake build tree and excludes compiler-probe files. Multiple independent direct test binaries get isolated object directories plus per-test reports and an explicit aggregate summary; shared headers can be counted once per test binary because the aggregate sums instrumented line instances. --coverage-fail-under and --coverage-branch-fail-under enforce line/branch thresholds from the generated summary and fail CI when coverage regresses; they require --coverage-report. --timing prints toolchain, compile, run (when applicable), and total phase timings; JSON output exposes the same values under timing. For direct Ninja builds it also emits conservative timing_steps entries for compile/link/archive edges that actually ran in that invocation, with per-edge millisecond durations and source mapping when the object name can be mapped back to an input. No-op rebuilds therefore report an empty step list rather than pretending cached edges ran again.

Testing with doctest ​

Any translation unit that includes <doctest/doctest.h> just works — CLAP bootstraps the pinned, SHA-256-verified doctest single header into the user cache on first use and adds the include path automatically. No submodule, no system package, no manual download:

cpp
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>

TEST_CASE("addition") {
    CHECK(2 + 2 == 4);
}
bash
clap run test_math.cpp   # real assertions out of the box

The pinned version is documented in src/clap_compiler/doctest_dev.py; in offline mode a missing cache entry fails closed with a clear error instead of a compiler diagnostic.

CI in one step — the setup-clap action ​

clap init --ci generates a three-OS GitHub Actions workflow that uses the composite action shipped in this repository. Use it in your own workflows the same way:

yaml
- uses: BRATAN-CORP/clap/.github/actions/setup-clap@v0.71.0
  with:
    version: '0.58.0'   # pin both together; empty means latest
- run: clap run test_math.cpp

The action installs clap-compiler from PyPI and caches the private zig toolchain between runs — cold CI bootstrap drops to seconds after the first run. The action tag and the release it ships with are the same object: pin them together, bump them together.

Declared dependencies — clap add and clap sync ​

The reproducible way to consume libraries: clap add pins a dependency into clap.toml and vendors it in one command — clap add --dev pins into [dev-dependencies] instead, visible to test builds only and never compiled into production artifacts (where test harnesses like doctest belong) — it computes the SHA-256 itself, so there is no hash copying. Curated hash-verified pins ship in the CLI for the common cases — bare clap add lists the whole registry grouped by category — clap search <term> filters it by name, description, or category (clap search json answers "which JSON library" without opening a browser) — no URL hunting at all. After a successful add, CLAP prints the exact #include line matching the vendored layout (and exposes it as include_hint in --json); curated pins that upstream expects namespaced — nlohmann/json.hpp, argparse/argparse.hpp — vendor into that layout through the pin's file_path, so the idiomatic include compiles. Compiled libraries work too: a sources key in the dependency table builds sqlite3.c or cJSON.c directly into your project, zero configuration — it takes a single path or a list — glob patterns like library/*.c are allowed and must match at least one file inside the vendored tree, never escaping it (this is how the mbedtls pin compiles all 109 of its sources in one entry) — and an optional defines key carries compile-time configuration macros the library needs (the zlib pin uses defines = ["Z_HAVE_UNISTD_H"] so gz io compiles; defines apply to the whole build, configuration macros by nature). Libraries that need system libraries to link carry a links key — entries are plain library names applied everywhere, or platform-prefixed windows:name / linux:name / macos:name applied only when the target matches (cross-builds included). The mongoose pin uses links = ["windows:ws2_32"]: Windows builds link the socket library automatically and Linux builds link nothing, zero flags either way):

bash
clap add https://raw.githubusercontent.com/doctest/doctest/v2.4.11/doctest/doctest.h
# pinned doctest in clap.toml + vendored — done

Dependency defines accept the same platform prefixes — linux:ZIP_HAVE_SYMLINK=1 applies only when targeting Linux. The zip pin uses this because strict POSIX toolchains need the macro for its unistd include while Windows must never see it: symlink does not exist there. When a library only supports some platforms, a platforms key declares it — platforms = ["linux", "macos"] makes the build fail honestly before compiling when the target does not match, instead of dying inside system headers. The linenoise pin uses this: POSIX terminals only.

toml
[dependencies.doctest]
url = "https://raw.githubusercontent.com/doctest/doctest/v2.4.11/doctest/doctest.h"
sha256 = "44faa038e9c3f9728efbda143748d01124ea0a27f4bf78f35a15d8fab2e039fb"

The whole dependency lifecycle: bare clap add lists the registry, cjson builds zero-flag, remove cleans up

clap sync downloads, hash-verifies, and extracts every declared dependency into vendor/<name>/ — on a fresh clone, one command reproduces the exact dependency tree. Builds then add the include roots automatically, so #include <doctest.h> compiles with no -I at all; a missing or drifted dependency fails the build with the exact remedy instead of a misleading missing-header error. clap deps reports the sync status of everything declared, clap doctor surfaces drift in the environment check, and clap remove <name> unpins and deletes the vendored tree in one step.

Vendoring single-header libraries ​

For other header-only dependencies, clap vendor downloads a pinned, hash-verified copy into the project — no submodule, no package manager:

bash
clap vendor https://github.com/nlohmann/json/releases/download/v3.11.3/json.hpp \
  --sha256 9bea4c8066ef4a1c206b2be5a36302f8926f7fdc6087af5d20b417d0cf103ea6
clap run main.cpp -I vendor

Verified end-to-end recipes for nlohmann/json, stb_image, cJSON, argparse, doctest and SQLite live in docs/LIBRARY_RECIPES.md — each one was downloaded, hash-verified, compiled and run before being documented.

The SHA-256 is mandatory: a hash mismatch refuses to write anything, re-running with the correct hash is idempotent, and an existing differently-hashed file is never overwritten silently. Commit vendor/ like any other source.

Archives work too — .zip, .tar.gz, .tgz, .tar.xz, and .tar.bz2 downloads are hash-verified as blobs and then extracted into vendor/<name>/ with path-traversal protection (absolute paths, .. members, and links are refused rather than written). A .clap-vendor.json marker inside the directory makes re-runs idempotent and protects against silent replacement.

bash
clap vendor https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz \
  --sha256 <release-archive-hash>
clap run main.cpp -I vendor/json/include

CMake projects ​

If a directory has CMakeLists.txt, CLAP can treat it as a project:

bash
clap build .
clap build . --release
clap cmake . --cmake-target all --cmake-arg -DENABLE_TESTS=OFF
clap test . --debug
clap run .        # build and run a single executable target
clap test .       # build, then run CTest
clap test . -j 8 --ctest-arg=-R --ctest-arg=mytest
clap clean        # remove CLAP build directories

The CMake path uses the same compiler selection logic as direct compilation. If a build directory was configured with another compiler or generator, CLAP resets CMake’s cache instead of silently reusing the wrong toolchain. --release and --debug map to the normal CMake Release and Debug build types; an exact --cmake-arg -DCMAKE_BUILD_TYPE=... can still override them when a project needs another configuration. cmake and ninja come from pinned Python package dependencies, so CLAP does not download a random “latest” archive in the background.

Project configuration ​

clap.toml keeps small projects small. Projects created by clap init start with a Taplo-compatible #:schema comment pointing at the published project schema. Source entries can be exact files or deterministic glob patterns such as src/**/*.c. The supported configuration surface is described by the versioned JSON Schema in [schema/project-v1.json(https://github.com/BRATAN-CORP/clap/blob/main/schema/project-v1.json), which editors and schema-aware TOML tooling can use for completion/validation. Unknown [project] keys, wrong types, unsupported platform tables, and empty string list values are invalid rather than silently ignored. entry remains a compatibility alias used only when sources is absent; prefer sources in new projects.

toml
[project]
name = "hello"
sources = ["src/**/*.c", "src/util.c"]  # glob patterns are allowed
# exclude_sources = ["src/generated/**", "tests/fixtures/**"]
output = "hello"
flags = ["-Wall"]
includes = ["include"]
defines = ["CONFIG_RELEASE=1"]
libraries = ["m"]
library_paths = ["lib"]
packages = ["zlib"]  # resolved through pkg-config
# vcpkg_root = "vendor/vcpkg"
# vcpkg_triplet = "x64-linux"
link_flags = []
std = "c11"
# artifact = "static"  # exe, object, static, shared, asm, preprocess
# sanitizers = ["address"]
# warnings = true
# warnings_as_errors = false
# compiler = "gcc"   # CLI --compiler overrides this
# ninja = false      # disable automatic incremental Ninja builds
# object_cache = true # reuse compatible direct-build objects across clean builds
# jobs = 4           # parallel compile jobs
# compile_commands = true  # always write editor metadata
# sbom = false             # write SPDX SBOMs for direct builds
# release = true           # optimized project builds by default
# debug = false            # debug info project builds by default
# or separate mixed C/C++ projects:
# c_std = "c11"
# cpp_std = "c++20"

# Platform-specific additions are applied for the host platform,
# or for the selected target when cross-compiling:
# [project.platform.linux]
# includes = ["platform/linux/include"]
# libraries = ["m"]
# packages = ["libudev"]
#
# [project.platform.windows]
# includes = ["platform/windows/include"]
# libraries = ["user32"]

Then:

bash
clap build
clap run

Explicit files on the command line still win over config defaults. That is intentional: automation should be able to override a project without editing it.

[project.platform.windows], [project.platform.linux], and [project.platform.macos] can add flags, link_flags, includes, defines, libraries, library_paths, and packages for one operating system. Host builds use the host platform; cross-builds use the selected target triple. Values are additive after the base project values, so shared configuration stays in [project] and only platform-specific pieces move into these tables. Unknown platform names or keys are rejected instead of silently ignored.

vcpkg can be enabled with vcpkg_root/vcpkg_triplet in clap.toml, --vcpkg-root/--vcpkg-triplet, or VCPKG_ROOT. For direct builds CLAP adds installed/<triplet>/include to include paths and installed/<triplet>/lib (or debug/lib for debug builds) to library paths; libraries themselves are still explicit through libraries/--library. For CMake projects CLAP passes the standard scripts/buildsystems/vcpkg.cmake toolchain file and triplet, so find_package and vcpkg manifest mode work normally; see examples/vcpkg-manifest-fmt/.

clap lock records resolved pkg-config versions, compile flags, and linker flags in clap.lock.json. clap deps reports the declared packages, lock status/version drift, concrete remediation actions, manual include/library paths, and vcpkg triplet state in human output or schema-versioned JSON (schema/deps-v1.json). The lock format itself is described by versioned JSON Schema [schema/lock-v1.json(https://github.com/BRATAN-CORP/clap/blob/main/schema/lock-v1.json). When that file exists, direct builds use the locked flags by default and verify that the installed pkg-config --modversion still matches; a mismatch stops the build until clap lock refreshes the file. --no-lock (also accepted as --ignore-lock) temporarily bypasses the lock. The lock does not make system libraries portable across machines — it makes their resolution explicit and verifiable.

Machine-readable output ​

bash
clap build main.c --json
clap run main.c --json

The JSON report includes the primary compiler command, the full commands list for multi-step builds, output path, toolchain name/version/source, parsed diagnostics, warnings, stdout/stderr, and the child process result for run. It is meant to be useful to editor integrations and coding agents, not just decorative JSON. clap inspect follows the versioned schema in schema/inspect-v1.json; schema version 1 is additive-stable, so integrations can rely on the documented fields while ignoring future additions. The report also exposes the configured object-cache setting, cache locations, entry count, byte usage, and cache size limit.

clap vscode writes mergeable .vscode/tasks.json, launch.json, c_cpp_properties.json, extensions.json, and settings.json files. The launch configuration enables F5 debugging of the default main binary: gdb or lldb through cppdbg where one is installed (no entry is written when no debugger exists), cppvsdbg on Windows, with a CLAP: Build pre-launch task. Besides the Microsoft C/C++ extension, it recommends Even Better TOML and associates clap.toml with the published project schema for completion/validation. The default CLAP: Build task generates ${workspaceFolder}/compile_commands.json, which the recommended Microsoft C/C++ extension uses for IntelliSense. Additional generated tasks cover test execution, JUnit reports, project inspection, dependency status, toolchain information, and cleanup. Existing unrelated VS Code tasks and settings are preserved; CLAP refuses to overwrite malformed existing JSON instead of destroying it.

The VS Code extension in editors/vscode is published on the Visual Studio Marketplace as CLAP Compiler. It activates for CLAP, CMake, and ordinary C/C++ workspaces; adds Command Palette commands, editor-title Build/Run actions, and native tasks for bootstrap/build/run/test/coverage/dependency/toolchain operations; parses GCC/Clang-style and MSVC-style compiler output into native diagnostics; and provides a Getting Started walkthrough, configure/build/run/test follow-through, cancellable process-tree-aware execution, overlap protection, settings recovery for a missing executable, file-watch status refresh, and a compact project status item that becomes a cancellation action while work is running. The extension is compiled, tested in a real VS Code extension host with fake and real CLAP executables, and packaged as a .vsix in CI/publication workflows.

CLAP uses Ninja automatically for CMake projects and direct builds whenever the bundled Ninja dependency is available. --ninja remains accepted as an explicit opt-in, while --no-ninja keeps the legacy immediate compile/link behavior:

bash
clap build main.c                     # incremental by default
clap build main.c --ninja             # explicit Ninja opt-in
clap build main.c --no-ninja          # legacy direct commands

This writes .clap-ninja/build.ninja, compiles each source once, tracks header dependencies, and reuses unchanged object files on later builds. Add --compile-commands to write a compile_commands.json database beside the output for clangd and other editor tooling, or --compile-commands-output path/to/db.json to choose the exact destination. CMake builds export the same database into the CMake build directory automatically. Consumer setup and agent workflows are documented in docs/COMPILE_COMMANDS.md.

SPDX SBOMs ​

CLAP can write an SPDX 2.3 software bill of materials after a successful build:

bash
clap build main.c --sbom
clap cmake . --sbom
clap cmake . --sbom --sbom-output sbom.spdx.json

Direct builds record source files, output checksums, compiler identity, linker libraries, and non-standard includes. CMake builds use the CMake File API, so target names, artifacts, sources, target dependencies, and link-line libraries come from CMake's own model instead of a text scan.

One honest boundary: CLAP can report that a target links openssl or z, but it cannot magically know which upstream package supplied that library if the project does not say so. Conan/vcpkg/system package provenance still has to come from the project or package manager.

How the toolchain works ​

CLAP pins Zig 0.17.1 per platform and verifies every downloaded archive before extraction. Archive entries are checked for path traversal and links are rejected. The toolchain lives in the user cache:

PlatformCache location
Windows%LOCALAPPDATA%\CLAP
macOS~/Library/Caches/CLAP
Linux${XDG_CACHE_HOME:-~/.cache}/clap

Set CLAP_CACHE to use a different location. Use --system to prefer an installed compiler, or --offline to forbid downloads.

This design is deliberately unglamorous. A compiler is not the sort of thing that should depend on whatever happened to be in PATH today.

Platform support ​

PlatformNative buildWindows cross-buildCMake
Windowsyesnative .exeyes
Linuxyesyesyes
macOSyesyesyes

Automatic GitHub CI runs Linux unit, packaging, and Linux-to-Windows smoke checks. Native Windows smoke remains available as a manual workflow, while maintainers use scripts/ci-local.sh plus real Windows/macOS validation for platform-sensitive changes. After installing checkout dependencies with python -m pip install -e ., python scripts/validate_platform.py --output report.json runs a reproducible end-to-end platform smoke covering direct/CMake builds, Unicode paths, process-tree termination, toolchain verification, coverage when GCC/Clang tools exist, and optionally --deep-path; --cold-cache uses an isolated empty CLAP cache to measure first-run bootstrap behavior. Recorded baseline results and exact semantics live in docs/PLATFORM_VALIDATION.md.

Why CLAP instead of CMake, Meson, or XMake? ​

CLAP is not trying to replace large build systems inside mature projects. Its narrow job is the first ten minutes: install one Python package, get a verified compiler toolchain, compile or run ordinary C/C++, and optionally drive an existing CMake project with pinned CMake/Ninja. Use CMake/Meson/XMake when you need their full project model; use CLAP when compiler setup itself is the barrier, especially on Windows or in agent/CI environments.

Honest limitations ​

CLAP is not a full replacement for Visual Studio or the Windows SDK. Projects that require MSVC-specific extensions, MFC/ATL, proprietary SDK pieces, or exotic linker setups still need those Microsoft components installed. When they are installed, clap --system can discover MSVC through vswhere and use the correct vcvars environment even outside a Developer PowerShell; --compiler cl asks for that toolchain explicitly.

CLAP is also not a new programming language. The “Python” part is about the installation experience, not syntax.

Development ​

bash
python -m pip install -e '.[dev]'
python -m ruff check src tests
python -m pytest -q

The active engineering plan lives in ROADMAP.md; local performance measurements live in PERFORMANCE.md; reproduced platform failure modes and fixes live in TROUBLESHOOTING.md; coverage CI consumption is documented in COVERAGE.md. Please keep changes small enough to explain in one commit message. CLAP itself should stay small too. Release notes live in the changelog and on the releases page.

License ​

MIT. Use it, teach with it, automate with it, improve it.