From e1d754cc82edeecb4e86b81d588cda42ad4b1d41 Mon Sep 17 00:00:00 2001 From: Tim Paine <3105306+timkpaine@users.noreply.github.com> Date: Sat, 2 Aug 2025 10:12:34 -0400 Subject: [PATCH 1/2] Update readme docs --- README.md | 77 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a468e43..30459a6 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,74 @@ 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) -## Environment Variables - -| Name | Default | Description | -| :------------------------- | :------ | :---------- | -| `CC` | | | -| `CXX` | | | -| `LD` | | | -| `HATCH_CPP_PLATFORM` | | | -| `HATCH_CPP_DISABLE_CCACHE` | | | +## 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. + +### 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). From 2d3ea7c7cda7a088c51db4dd52c87a1055a198ab Mon Sep 17 00:00:00 2001 From: Tim Paine <3105306+timkpaine@users.noreply.github.com> Date: Sat, 2 Aug 2025 10:17:39 -0400 Subject: [PATCH 2/2] Add more configuration information to readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 30459a6..31715dd 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,9 @@ 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