hatch-cpp


Namehatch-cpp JSON
Version 0.1.9 PyPI version JSON
download
home_pageNone
SummaryHatch plugin for C++ builds
upload_time2025-11-06 03:12:11
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseApache-2.0
keywords build c++ cmake cpp hatch python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # hatch-cpp

Hatch plugin for C++ builds

[![Build Status](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml)
[![codecov](https://codecov.io/gh/python-project-templates/hatch-cpp/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/hatch-cpp)
[![License](https://img.shields.io/github/license/python-project-templates/hatch-cpp)](https://github.com/python-project-templates/hatch-cpp)
[![PyPI](https://img.shields.io/pypi/v/hatch-cpp.svg)](https://pypi.python.org/pypi/hatch-cpp)

## Overview

A simple, extensible C++ build plugin for [hatch](https://hatch.pypa.io/latest/).

```toml
[tool.hatch.build.hooks.hatch-cpp]
libraries = [
    {name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
]
```

For more complete systems, see:

- [scikit-build-core](https://github.com/scikit-build/scikit-build-core)
- [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)

## Configuration

Configuration is driven from the `[tool.hatch.build.hooks.hatch-cpp]` hatch hook configuration field in a `pyproject.toml`.
It is designed to closely match existing Python/C/C++ packaging tools.

```toml
verbose = true
libraries = { Library Args }
cmake = { CMake Args }
platform = { Platform, either "linux", "darwin", or "win32" }
```

See the [test cases](./hatch_cpp/tests/) for more concrete examples.

`hatch-cpp` is driven by [pydantic](https://docs.pydantic.dev/latest/) models for configuration and execution of the build.
These models can themselves be overridden by setting `build-config-class` / `build-plan-class`.

### Library Arguments

```toml
name = "mylib"
sources = [
    "path/to/file.cpp",
]
language = "c++"

binding = "cpython" # or "pybind11", "nanobind", "generic"
std = "" # Passed to -std= or /std:

include_dirs = ["paths/to/add/to/-I"]
library_dirs = ["paths/to/add/to/-L"]
libraries = ["-llibraries_to_link"]

extra_compile_args = ["--extra-compile-args"]
extra_link_args = ["--extra-link-args"]
extra_objects = ["extra_objects"]

define_macros = ["-Ddefines_to_use"]
undef_macros = ["-Uundefines_to_use"]

py_limited_api = "cp39"  # limited API to use
```

### CMake Arguments

`hatch-cpp` has some convenience integration with CMake.
Though this is not designed to be as full-featured as e.g. `scikit-build`, it should be satisfactory for many small projects.

```toml
root = "path/to/cmake/root"
build = "path/to/cmake/build/folder"
install = "path/to/cmake/install/folder"

cmake_arg_prefix = "MYPROJECT_"
cmake_args = {}  # any other cmake args to pass
cmake_env_args = {} # env-specific cmake args to pass

include_flags = {} # include flags to pass -D
```

### Environment Variables

`hatch-cpp` will respect standard environment variables for compiler control.

| Name                       | Default | Description           |
| :------------------------- | :------ | :-------------------- |
| `CC`                       |         | C Compiler override   |
| `CXX`                      |         | C++ Compiler override |
| `LD`                       |         | Linker override       |
| `HATCH_CPP_PLATFORM`       |         | Platform to build     |
| `HATCH_CPP_DISABLE_CCACHE` |         | Disable CCache usage  |

> [!NOTE]
> This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "hatch-cpp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "build, c++, cmake, cpp, hatch, python",
    "author": null,
    "author_email": "the hatch-cpp authors <t.paine154@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/2d/b8/9e8e2a5e28c67b1494cdea874eae984e77b21ee77c691e585bb4cd231d1c/hatch_cpp-0.1.9.tar.gz",
    "platform": null,
    "description": "# hatch-cpp\n\nHatch plugin for C++ builds\n\n[![Build Status](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml)\n[![codecov](https://codecov.io/gh/python-project-templates/hatch-cpp/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/hatch-cpp)\n[![License](https://img.shields.io/github/license/python-project-templates/hatch-cpp)](https://github.com/python-project-templates/hatch-cpp)\n[![PyPI](https://img.shields.io/pypi/v/hatch-cpp.svg)](https://pypi.python.org/pypi/hatch-cpp)\n\n## Overview\n\nA simple, extensible C++ build plugin for [hatch](https://hatch.pypa.io/latest/).\n\n```toml\n[tool.hatch.build.hooks.hatch-cpp]\nlibraries = [\n    {name = \"project/extension\", sources = [\"cpp/project/basic.cpp\"], include-dirs = [\"cpp\"]}\n]\n```\n\nFor more complete systems, see:\n\n- [scikit-build-core](https://github.com/scikit-build/scikit-build-core)\n- [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)\n\n## Configuration\n\nConfiguration is driven from the `[tool.hatch.build.hooks.hatch-cpp]` hatch hook configuration field in a `pyproject.toml`.\nIt is designed to closely match existing Python/C/C++ packaging tools.\n\n```toml\nverbose = true\nlibraries = { Library Args }\ncmake = { CMake Args }\nplatform = { Platform, either \"linux\", \"darwin\", or \"win32\" }\n```\n\nSee the [test cases](./hatch_cpp/tests/) for more concrete examples.\n\n`hatch-cpp` is driven by [pydantic](https://docs.pydantic.dev/latest/) models for configuration and execution of the build.\nThese models can themselves be overridden by setting `build-config-class` / `build-plan-class`.\n\n### Library Arguments\n\n```toml\nname = \"mylib\"\nsources = [\n    \"path/to/file.cpp\",\n]\nlanguage = \"c++\"\n\nbinding = \"cpython\" # or \"pybind11\", \"nanobind\", \"generic\"\nstd = \"\" # Passed to -std= or /std:\n\ninclude_dirs = [\"paths/to/add/to/-I\"]\nlibrary_dirs = [\"paths/to/add/to/-L\"]\nlibraries = [\"-llibraries_to_link\"]\n\nextra_compile_args = [\"--extra-compile-args\"]\nextra_link_args = [\"--extra-link-args\"]\nextra_objects = [\"extra_objects\"]\n\ndefine_macros = [\"-Ddefines_to_use\"]\nundef_macros = [\"-Uundefines_to_use\"]\n\npy_limited_api = \"cp39\"  # limited API to use\n```\n\n### CMake Arguments\n\n`hatch-cpp` has some convenience integration with CMake.\nThough this is not designed to be as full-featured as e.g. `scikit-build`, it should be satisfactory for many small projects.\n\n```toml\nroot = \"path/to/cmake/root\"\nbuild = \"path/to/cmake/build/folder\"\ninstall = \"path/to/cmake/install/folder\"\n\ncmake_arg_prefix = \"MYPROJECT_\"\ncmake_args = {}  # any other cmake args to pass\ncmake_env_args = {} # env-specific cmake args to pass\n\ninclude_flags = {} # include flags to pass -D\n```\n\n### Environment Variables\n\n`hatch-cpp` will respect standard environment variables for compiler control.\n\n| Name                       | Default | Description           |\n| :------------------------- | :------ | :-------------------- |\n| `CC`                       |         | C Compiler override   |\n| `CXX`                      |         | C++ Compiler override |\n| `LD`                       |         | Linker override       |\n| `HATCH_CPP_PLATFORM`       |         | Platform to build     |\n| `HATCH_CPP_DISABLE_CCACHE` |         | Disable CCache usage  |\n\n> [!NOTE]\n> This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Hatch plugin for C++ builds",
    "version": "0.1.9",
    "project_urls": {
        "Homepage": "https://github.com/python-project-templates/hatch-cpp",
        "Repository": "https://github.com/python-project-templates/hatch-cpp"
    },
    "split_keywords": [
        "build",
        " c++",
        " cmake",
        " cpp",
        " hatch",
        " python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3edd7d86ab05867d574edf6a27aad509f9dd2061a37a3618049f81f9ff6de5cb",
                "md5": "e433b83272a103fd2ae8711078766334",
                "sha256": "281c49d9ab81b9bd2855dcc4748c47a3478bb4349c066500447cf99dbb262665"
            },
            "downloads": -1,
            "filename": "hatch_cpp-0.1.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e433b83272a103fd2ae8711078766334",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 37937,
            "upload_time": "2025-11-06T03:12:09",
            "upload_time_iso_8601": "2025-11-06T03:12:09.986667Z",
            "url": "https://files.pythonhosted.org/packages/3e/dd/7d86ab05867d574edf6a27aad509f9dd2061a37a3618049f81f9ff6de5cb/hatch_cpp-0.1.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2db89e8e2a5e28c67b1494cdea874eae984e77b21ee77c691e585bb4cd231d1c",
                "md5": "4e1fbd1eb6dbbb205470d97b048389c4",
                "sha256": "dfe481d8fca7fb8eaf41d35763cced25e7cebd07ed2ec5d18bd12e07dc5d79d8"
            },
            "downloads": -1,
            "filename": "hatch_cpp-0.1.9.tar.gz",
            "has_sig": false,
            "md5_digest": "4e1fbd1eb6dbbb205470d97b048389c4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 19234,
            "upload_time": "2025-11-06T03:12:11",
            "upload_time_iso_8601": "2025-11-06T03:12:11.279942Z",
            "url": "https://files.pythonhosted.org/packages/2d/b8/9e8e2a5e28c67b1494cdea874eae984e77b21ee77c691e585bb4cd231d1c/hatch_cpp-0.1.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-11-06 03:12:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "python-project-templates",
    "github_project": "hatch-cpp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "hatch-cpp"
}
        
Elapsed time: 4.57887s