Skip to main content

👏 CLAP

C Like A Python — simple as clap.

English | Русский

CI License: MIT Python Platforms PyPI

CLAP is a zero-setup C/C++ compiler frontend for people who just want the thing to build.

No afternoon lost to MinGW mirrors. No “please install Visual Studio Build Tools and restart your machine”. No lecture about PATH. Install the Python package, run clap build, and get a binary.

CLAP does not try to turn C into Python. It only makes compiling C feel almost as uneventful as running Python. The mascot logic is equally simple: 👏 for clap, 🐍 for the Python-like lack of ceremony. Under the hood it uses a pinned, checksum-verified Zig/Clang toolchain; Python is the installer, dispatcher, and boring glue.

CLAP terminal demo

What it does

  • compiles C as C and C++ as C++ — a small detail that many “simple” tools still manage to break;
  • handles mixed C/C++ projects by compiling each file in the right mode and linking with the C++ driver;
  • bootstraps a private toolchain on Windows, Linux, and macOS;
  • can cross-compile Windows executables from Linux or macOS;
  • builds ordinary CMake projects with pinned cmake and ninja Python packages;
  • prints human output by default and structured JSON for editors, scripts, and agents;
  • falls back to a system compiler only when you ask for it or when the private toolchain is unavailable.

Install

Today: install from GitHub

With pipx — recommended for a CLI tool:

pipx install git+https://github.com/BRATAN-CORP/clap.git

Or with plain pip:

python -m pip install git+https://github.com/BRATAN-CORP/clap.git
# `python -m clap_compiler` also works after installation

Python 3.9+ is required. The first private toolchain bootstrap needs internet access; after that --offline builds work.

Planned package homes

These links are placeholders until the first release is published. They are listed here so the packaging shape is explicit instead of tribal knowledge.

Package manager Planned package Status
PyPI clap-compiler planned for the first release
npm clap-compiler wrapper placeholder
Debian/Ubuntu clap-compiler .deb placeholder
Snap Store clap-compiler placeholder
AUR clap-compiler placeholder
Nix/NixOS clap-compiler placeholder
GitHub Releases releases release artifacts land here

Quick start

clap init hello
cd hello
clap run

# other starting points:
# clap init app --template cpp
# clap init app --template mixed
# clap init app --template cmake

Or compile a file directly:

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 run main.c --sanitize address  # debug memory errors
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

Useful commands:

clap doctor       # show the active toolchain and cache
clap doctor --probe  # compile tiny C and C++ health checks
clap bootstrap    # download and verify the private toolchain now
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

Examples

Small runnable examples live in examples/:

clap run examples/hello/main.c
clap run examples/mixed/answer.c examples/mixed/main.cpp
clap cmake examples/cmake

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, and --library-path options are translated into GCC/Clang/Zig 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.

Objects and libraries

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

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:

python -m pip install git+https://github.com/BRATAN-CORP/clap.git
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.

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

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.

Testing

For a CMake project, clap test builds the project and runs CTest. For a direct source file or a clap.toml executable project, it builds the executable and runs it, using the program exit code as the test result. Arguments after -- go to the test executable:

clap test . -- --verbose

CMake projects

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

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. Source entries can be exact files or deterministic glob patterns such as src/**/*.c:

[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"]
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 = true       # use incremental Ninja builds by default
# 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"

Then:

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.

Machine-readable output

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 uses Ninja automatically for CMake projects. You can also opt into it for direct builds:

clap build main.c answer.cpp --ninja

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.

SPDX SBOMs

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

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:

Platform Cache 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

Platform Native build Windows cross-build CMake
Windows yes native .exe yes
Linux yes yes yes
macOS yes yes yes

The GitHub Actions matrix runs unit tests on Windows, Linux, and macOS, plus separate native Windows and Linux-to-Windows smoke builds.

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

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

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.

Metadata

Release files for clap-compiler 0.35.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clap-compiler 0.35.1
File Size Uploaded Provenance Actions
clap_compiler-0.35.1.tar.gz 70.5 kB Without provenance Details for clap_compiler-0.35.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clap-compiler 0.35.1
File Interpreter ABI Platform Actions
clap_compiler-0.35.1-py3-none-any.whl Python 3 none any Details for clap_compiler-0.35.1-py3-none-any.whl

Total release size: 112.3 kB

Release files / clap_compiler-0.35.1.tar.gz

Download URL clap_compiler-0.35.1.tar.gz
Size 70.5 kB
Tags Source
SHA-256 checksum
How to use checksums
02a3aa449eb90aa2ef69184fffdd1a4a73f6ec1ae22b8de90514c3be1dfa5b4e
BLAKE2b-256 checksum
How to use checksums
14bbe0f6fad297f97c7fe560d46ced26d9bf15e729a1ee4dd35dbf82479df64b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / clap_compiler-0.35.1-py3-none-any.whl

Download URL clap_compiler-0.35.1-py3-none-any.whl
Size 41.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33bbbe61491f6bb77546a392308ba49ce1c4036e8517f857fc49447154cccff0
BLAKE2b-256 checksum
How to use checksums
b8dcf405337d9b696cf8f5748aacdf7106593c037cbf8cd95826613875569536
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for clap-compiler 0.35.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.35.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page