Metadata-Version: 2.5
Name: pcons
Version: 0.32.0
Summary: A cross-platform software build system, configured in Python, that generates Ninja files
Project-URL: Homepage, https://github.com/DarkStarSystems/pcons
Project-URL: Repository, https://github.com/DarkStarSystems/pcons
Project-URL: Documentation, https://pcons.readthedocs.io/
Project-URL: Issues, https://github.com/DarkStarSystems/pcons/issues
Author-email: Gary Oberbrunner <garyo@oberbrunner.com>
License: MIT
License-File: LICENSE
Keywords: build,build-system,cmake,ninja,scons
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.11
Requires-Dist: click<9,>=8.4
Requires-Dist: tomli-w>=1.0
Requires-Dist: tomli>=2.0; python_version < '3.11'
Requires-Dist: watchfiles>=1.0; sys_platform == 'linux' or sys_platform == 'darwin' or sys_platform == 'win32'
Provides-Extra: dev
Requires-Dist: coverage>=7.10; extra == 'dev'
Requires-Dist: hypothesis>=6.100; extra == 'dev'
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Requires-Dist: ty>=0.0.79; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-macros-plugin>=1.0; extra == 'docs'
Requires-Dist: mkdocs-material>=9.0; extra == 'docs'
Requires-Dist: mkdocs>=1.5; extra == 'docs'
Provides-Extra: watch
Requires-Dist: watchfiles>=1.0; extra == 'watch'
Provides-Extra: xcode
Requires-Dist: pbxproj>=3.0.0; extra == 'xcode'
Description-Content-Type: text/markdown

# Pcons

A modern open-source cross-platform zero-install Python-based build system. Builds anything that requires a repeatable workflow, using a dependency graph. Easy to use, reliable and quick. Uses Ninja (or Make or Xcode) to do the builds. Optimized for C/C++, Fortran, CUDA, wasm etc. but should work for anything that needs building.

[![CI](https://github.com/DarkStarSystems/pcons/actions/workflows/main.yml/badge.svg)](https://github.com/DarkStarSystems/pcons/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/DarkStarSystems/pcons/graph/badge.svg)](https://codecov.io/gh/DarkStarSystems/pcons)
[![PyPI](https://img.shields.io/pypi/v/pcons)](https://pypi.org/project/pcons/)
[![PyPI Downloads](https://static.pepy.tech/badge/pcons)](https://pepy.tech/projects/pcons)
[![Python](https://img.shields.io/pypi/pyversions/pcons)](https://pypi.org/project/pcons/)
[![Doc Status](https://readthedocs.org/projects/pcons/badge/?version=latest)](https://pcons.readthedocs.io/en/latest/?badge=latest)

## Overview

Pcons is inspired by [SCons](https://scons.org) and [CMake](https://cmake.org), taking a few of the best ideas from each:

- **From SCons**: Environments, Tools, dependency tracking, Python as the configuration language
- **From CMake**: Generator architecture (configure once, build fast), usage requirements that propagate through dependencies

**Key design principles:**

- **Configuration, not execution**: Pcons generates Ninja files; Ninja executes the build
- **Python is the language**: No custom DSL—build scripts are real Python with full IDE support
- **Language-agnostic**: Build C++, Rust, LaTeX, protobuf, or anything else
- **Explicit over implicit**: Dependencies are discoverable and traceable
- **Extensible**: Add-on modules for domain-specific tasks (plugin bundles, SDK configuration, etc.)

## Language and OS Support

Pcons currently supports C and C++, ObjC and C++, Swift, Fortran, CUDA, assembly, WASM (Emscripten/WASI), LaTeX, Python native extensions, and Rust (via integration). The list is always growing, and it's easy to create your own tools. All built-in tools work on Mac, Windows and Linux. It has cross-compile presets for Android NDK and iOS.

Pcons can build not just executables, but also tar/zip archives, python packages, Windows installers, and MacOS installer packages.

## What's in the box

- **[Fortran](https://pcons.readthedocs.io/en/latest/fortran/)**: gfortran and flang on Linux, macOS and Windows, and Intel's ifx on Linux and Windows; modules and submodules ordered automatically, and Fortran mixed with C and C++ in one program
- **[Qt 6](https://pcons.readthedocs.io/en/latest/qt/)**: `find_qt()`, automoc/autouic/autorcc, QML modules, translations, and `ninja deploy`
- **C++20 modules**: named modules, partitions, and `import std` on GCC, Clang and MSVC, with automatic dependency scanning
- **[Tests and fuzzing](https://pcons.readthedocs.io/en/latest/testing/)**: `project.Test()`, `pcons test`, gtest/doctest/Catch2 case discovery, JUnit XML, libFuzzer/AFL++
- **Compiler caching**: `env.use_compiler_cache()`, or run any command behind a launcher
- **`pcons --watch`**: rebuilds on every save, including edits to the build script itself
- **Configure checks**: `check_header()`, `check_flag()`, `try_compile()`, `configure_file()`, all cached
- **Generated sources**: code generators and multi-phase builds; if a generated file didn't change, its consumers don't rebuild
- **Installers**: signed and notarized `.pkg` and `.dmg`, MSIX packages, WinSxS assemblies
- **Cross-compilation**: presets for Android NDK, iOS, and WebAssembly (WASI and Emscripten)
- **`compile_commands.json`**: for clangd and friends; it always reports the real compiler
- **`env.explain()`**: where did this flag come from? Every flag, traced back to the preset that set it

## Why another software build tool?

I was one of the original developers of SCons, and helped maintain it for many years. I love that python is the config language; that makes build descriptions incredibly flexible and powerful. Recently I've been using CMake for more projects, and despite the deeply painful configuration language, I've come to appreciate its power: conan integration, the separation between *describing* the build andrunning it, and dependency propagation, among other things. I feel that SCons hasn't kept up with modern python; like any very widely used mature project, it has a lot of accumulated wisdom but also a bit ossified ways of doing things.

I've been thinking for years now about rearchitecting SCons onto a modern python stack with Path and decorators and all the other wonderful stuff python has been doing, and fixing some of the pain points at the same time (substitution/quoting, extensibility, tracing, separation between description and building, and more), but I've never had the time to dig into it. But recently as I've been using a lot more of Claude Code as a programming assistant, and it has gotten significantly better, it seemed like the right time to try this as a collaborative project. So, meet pcons!

Here's a [comparison](COMPARISONS.md) between pcons and other common modern build tools. I think pcons fills a real need, for a general-purpose broadly applicable extensible software build tool using a modern well-known language to describe builds and tools.

## Status

✅ **Ready for small-scale production use** - and still under active development, so feedback is very welcome. It's working in several medium-sized projects.

Core functionality is working and well tested across Linux, macOS and Windows, on every commit: C/C++/ObjC/Fortran/Swift/CUDA compilation, C++20 modules, Qt 6, static and shared libraries, install targets, installers, cross-compilation, and mixed-language builds. There are nearly 100 self-contained [examples](examples/), and every one is built and verified in CI. See [ARCHITECTURE.md](ARCHITECTURE.md) for design details.

### Rust / Go interop

pcons links Rust crates into C/C++ projects: `project.CargoBuild()` drives `cargo build` and links the resulting library, with optional [cbindgen](https://github.com/mozilla/cbindgen) header generation. See `examples/43_rust_cxx_hybrid` (hand-written FFI header) and `examples/44_rust_cxx_cbindgen` (cbindgen-generated header). Go support is straightforward to add on the same pattern — [open an issue](https://github.com/DarkStarSystems/pcons/issues) if you'd like it.

## Quick Start

Already have C or C++ sources? `pcons init` reads them and writes the build script for you:

```bash
cd myproject
uvx pcons init    # writes pcons-build.py from the sources it finds
uvx pcons         # generate build.ninja and build
```

## Quick Example

Or write it yourself; it's ordinary Python:

```python
# pcons-build.py
from pcons import Project

project = Project("myapp")
env = project.Environment(toolchain="c")
env.cc.flags.extend(["-Wall"])

# Build a static library
lib = project.StaticLibrary("core", env, sources=["src/core.c"])
lib.public.include_dirs.append("include")

# Build a program that links the library
app = project.Program("myapp", env, sources=["src/main.c"])
app.private.link_libs.append(lib)
```

```bash
uvx pcons # generate build.ninja and run it, producing build/myapp (or build/myapp.exe)
```

## Installation

No installation needed, if you have `uv`; just use `uvx pcons` to configure and build. `uvx pcons --help` for more info.
If you want to install it, though:

```bash
# Install as a CLI tool (recommended)
uv tool install pcons
pcons ...

# Or add to a project's dependencies
uv add pcons

# Or with pip
pip install pcons
```

Once installed, `pcons completion install` sets up tab completion for bash, zsh
or fish. See the [command-line
reference](https://pcons.readthedocs.io/en/latest/cli/#pcons-completion).

### Using the development version

To try the latest development version straight from GitHub:

```bash
# Run without installing
uvx --from git+https://github.com/DarkStarSystems/pcons pcons

# Install as a CLI tool
uv tool install git+https://github.com/DarkStarSystems/pcons

# Or with pip
pip install git+https://github.com/DarkStarSystems/pcons
```

## Verifying Release Signatures

Release artifacts on the [GitHub Releases page](https://github.com/DarkStarSystems/pcons/releases) are signed with [Sigstore](https://www.sigstore.dev/) using short-lived certificates issued via GitHub Actions OIDC; transparency-log records are stored at [rekor.sigstore.dev](https://rekor.sigstore.dev). Each `.tar.gz` and `.whl` has a matching `.sigstore.json` bundle. To verify with [`cosign`](https://docs.sigstore.dev/cosign/system_config/installation/):

```bash
cosign verify-blob \
  pcons-x.y.z.tar.gz \
  --bundle pcons-x.y.z.tar.gz.sigstore.json \
  --new-bundle-format \
  --certificate-identity-regexp='https://github.com/DarkStarSystems/pcons/.*' \
  --certificate-oidc-issuer='https://token.actions.githubusercontent.com'
```

## Documentation

- User Guide is at [ReadTheDocs](https://pcons.readthedocs.io)
- [Porting from CMake](docs/porting-from-cmake.md) - Side-by-side guide for migrating CMake projects to pcons
- [ARCHITECTURE.md](ARCHITECTURE.md) - Design document and implementation status
- [CONTRIBUTING.md](CONTRIBUTING.md) - How to contribute

## Development

```bash
# Run tests
uv run pytest

# Run linter
make lint

# Format code
make fmt

# Or use uv directly
uv run ruff check pcons/
uvx ty check pcons/ examples/

# Use your local checkout to build a project (uv run inside the repo,
# or point uvx/uv tool at the checkout from anywhere)
uv run pcons                                # inside this repo
uvx --from ~/src/pcons pcons                # one-off, from any project dir
uvx --refresh --from ~/src/pcons pcons      # ...rebuilding uv's cached wheel
uv tool install -e ~/src/pcons             # install the checkout, editable
```

## This Project is AI-Assisted

Pcons is my long-term vision for a modern build tool. I've used Claude Code extensively to assist in creating this project, mostly with Claude Opus models (Opus 5.5 as of Sept 2026). It has been a huge help in realizing the vision I've had for a long time. If you reflexively or morally reject all AI-generated or AI-assisted code, pcons is not for you. That said, this code reflects my vision, my architecture, my goals and my priorities. I take full responsibility for it, and as a professional software engineer with 40+ years of C/C++/python experience I stand behind it. I also intend to support it long-term.

### How is this different from "vibe coding?"

The short answer is you have to treat it like a real project with a project team, except most of the team is AI. Here's how I work as a solo AI-assisted developer working on an open source project:

- **Know what you're building.** Deep domain knowledge is vital. I know what I want pcons to be. I have 30+ years experience building software with all kinds of tools, and being a toolsmith myself. I can feel when it's right and when it's having trouble.
- **Understand software engineering.** Pcons has over 6,000 unit tests, full system tests, and nearly 100 examples, each built and checked on every commit. [CI](https://github.com/DarkStarSystems/pcons/actions/workflows/main.yml) runs on Linux, macOS and Windows across every supported Python version. Every commit is gated on lint, formatting, type checks and passing tests. I also have a suite of over a dozen medium-size open source projects in various languages which I ported to pcons; I use those as a test suite before every release. I co-design each new feature with the AI assistant and I don't let it start until I like the proposed design, and then we iterate until it's clean and I like it.
- **Have a long-term vision.** I started pcons seriously in January of 2026, and I've been working on it continuously since then (around 1000 commits total), moving toward the system I've always wanted it to be. Good design takes iteration, learning from users, judgment, and persistence. It's not one-shot prompt-to-app slop.
- **Own the product.** Working with AI assistance, you become partly (or even mostly) a product manager. Does it do what it says? Does it do what users want? Is it fast enough, and secure? Is the design clean and maintainable?
- **Review what matters.** I review changes closely, especially anything significant or gnarly. That's where you catch an agent spinning, or hacking around a problem instead of taking the principled approach. Everyday code from current models (Opus 5.5) is mostly trustworthy, tests catch most of what isn't, and I review all the interesting parts carefully.
- **Get a second opinion.** On a regular basis, a separate agent does a full code review in a fresh session, with no context from the work it's reviewing.

One of my sub-goals has been to make sure the documentation and source organization is clear; not just for humans but for browsing by AI agents. I want to make it easy for a human or an AI agent to create a best-practices `pcons-build.py` for *your* project quickly and easily. Using AI to auto-generate doc and making sure APIs are clean and consistent helps with that goal.

## License

MIT License - see [LICENSE](LICENSE)

