Skip to main content

Hatch plugin for C++ builds

Project description

hatch-cpp

Hatch plugin for C++ builds

Build Status codecov License PyPI

Overview

A simple, extensible C++ build plugin for hatch.

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

For more complete systems, see:

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.

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

See the test cases for more concrete examples.

hatch-cpp is driven by pydantic models for configuration and execution of the build. These models can themselves be overridden by setting build-config-class / build-plan-class.

Library Arguments

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.

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

CLI

hatch-cpp is integrated with hatch-build to allow easy configuration of options via command line:

hatch-build \
    -- \
    --verbose \
    --platform linux \
    --vcpkg.vcpkg a/path/to/vcpkg.json \
    --libraries.0.binding pybind11 \
    --libraries.0.include-dirs cpp,another-dir

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 from the Base Python Project Template repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hatch_cpp-0.2.1.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hatch_cpp-0.2.1-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

Details for the file hatch_cpp-0.2.1.tar.gz.

File metadata

  • Download URL: hatch_cpp-0.2.1.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hatch_cpp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9d40f8dc8520d29c260eba5617857bf76de1d832bd7137a0cc53c058f8d0f0da
MD5 5891a0e104c38bd93f580e160c5d3a19
BLAKE2b-256 59d935c61f1febfdc46255abb428a223b597145b010e19182bdfffb7bb34a676

See more details on using hashes here.

File details

Details for the file hatch_cpp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: hatch_cpp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 40.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hatch_cpp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee4c676e47f5e2d9b6f0c3847fea03d9585b818e04c992b55751b29bf7009867
MD5 068a9c4c697bdf8a911a125c8edaa635
BLAKE2b-256 e1f02d7bb7cbdd27d5ca0edfb2a812d9b153d9c72c3ae8f8a6c88386329517ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page