hatch-cpp 0.1.6__tar.gz → 0.1.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hatch_cpp-0.1.8/.gitignore +159 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/LICENSE +4 -0
- hatch_cpp-0.1.8/PKG-INFO +144 -0
- hatch_cpp-0.1.8/README.md +99 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/__init__.py +1 -1
- hatch_cpp-0.1.8/hatch_cpp/plugin.py +113 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/structs.py +122 -26
- hatch_cpp-0.1.8/hatch_cpp/tests/test_project_cmake/CMakeLists.txt +92 -0
- hatch_cpp-0.1.8/hatch_cpp/tests/test_project_cmake/Makefile +140 -0
- hatch_cpp-0.1.8/hatch_cpp/tests/test_project_cmake/pyproject.toml +39 -0
- hatch_cpp-0.1.8/hatch_cpp/tests/test_project_limited_api/cpp/project/basic.hpp +17 -0
- hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.cpp +5 -0
- hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.hpp +17 -0
- hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.cpp +5 -0
- hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.hpp +17 -0
- hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_toolchain/pyproject.toml +38 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_projects.py +12 -3
- hatch_cpp-0.1.8/hatch_cpp/tests/test_structs.py +56 -0
- hatch_cpp-0.1.8/hatch_cpp/toolchains/__init__.py +0 -0
- hatch_cpp-0.1.8/hatch_cpp/toolchains/cmake.py +0 -0
- hatch_cpp-0.1.8/hatch_cpp/utils.py +12 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/pyproject.toml +19 -9
- hatch_cpp-0.1.6/.gitignore +0 -169
- hatch_cpp-0.1.6/PKG-INFO +0 -71
- hatch_cpp-0.1.6/README.md +0 -35
- hatch_cpp-0.1.6/hatch_cpp/plugin.py +0 -91
- hatch_cpp-0.1.6/hatch_cpp/tests/test_structs.py +0 -26
- hatch_cpp-0.1.6/hatch_cpp/utils.py +0 -132
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/hooks.py +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_basic/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_basic/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_basic/project/__init__.py +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_basic/pyproject.toml +0 -0
- {hatch_cpp-0.1.6/hatch_cpp/tests/test_project_limited_api → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_cmake}/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.1.6/hatch_cpp/tests/test_project_limited_api → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_cmake}/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.1.6/hatch_cpp/tests/test_project_limited_api → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_cmake}/project/__init__.py +0 -0
- {hatch_cpp-0.1.6/hatch_cpp/tests/test_project_override_classes/cpp → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_cmake/project/include}/project/basic.hpp +0 -0
- {hatch_cpp-0.1.6/hatch_cpp/tests/test_project_override_classes → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_limited_api}/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.1.6/hatch_cpp/tests/test_project_nanobind → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_limited_api}/project/__init__.py +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_limited_api/pyproject.toml +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.1.6/hatch_cpp/tests/test_project_override_classes → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_nanobind}/project/__init__.py +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_nanobind/pyproject.toml +0 -0
- {hatch_cpp-0.1.6/hatch_cpp/tests/test_project_pybind → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_classes}/project/__init__.py +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_override_classes/pyproject.toml +0 -0
- {hatch_cpp-0.1.6/hatch_cpp/toolchains → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_toolchain/project}/__init__.py +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.hpp +0 -0
- /hatch_cpp-0.1.6/hatch_cpp/toolchains/cmake.py → /hatch_cpp-0.1.8/hatch_cpp/tests/test_project_pybind/project/__init__.py +0 -0
- {hatch_cpp-0.1.6 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_pybind/pyproject.toml +0 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.a
|
|
8
|
+
*.so
|
|
9
|
+
*.obj
|
|
10
|
+
*.dll
|
|
11
|
+
*.exp
|
|
12
|
+
*.lib
|
|
13
|
+
|
|
14
|
+
# Distribution / packaging
|
|
15
|
+
.Python
|
|
16
|
+
build/
|
|
17
|
+
develop-eggs/
|
|
18
|
+
dist/
|
|
19
|
+
downloads/
|
|
20
|
+
eggs/
|
|
21
|
+
.eggs/
|
|
22
|
+
lib/
|
|
23
|
+
lib64/
|
|
24
|
+
parts/
|
|
25
|
+
sdist/
|
|
26
|
+
var/
|
|
27
|
+
wheels/
|
|
28
|
+
pip-wheel-metadata/
|
|
29
|
+
share/python-wheels/
|
|
30
|
+
*.egg-info/
|
|
31
|
+
.installed.cfg
|
|
32
|
+
*.egg
|
|
33
|
+
MANIFEST
|
|
34
|
+
|
|
35
|
+
# PyInstaller
|
|
36
|
+
*.manifest
|
|
37
|
+
*.spec
|
|
38
|
+
|
|
39
|
+
# Installer logs
|
|
40
|
+
pip-log.txt
|
|
41
|
+
pip-delete-this-directory.txt
|
|
42
|
+
|
|
43
|
+
# Unit test / coverage reports
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
.coverage
|
|
48
|
+
.coverage.*
|
|
49
|
+
.cache
|
|
50
|
+
nosetests.xml
|
|
51
|
+
coverage.xml
|
|
52
|
+
junit.xml
|
|
53
|
+
*.cover
|
|
54
|
+
*.py,cover
|
|
55
|
+
.hypothesis/
|
|
56
|
+
.pytest_cache/
|
|
57
|
+
|
|
58
|
+
# Translations
|
|
59
|
+
*.mo
|
|
60
|
+
*.pot
|
|
61
|
+
|
|
62
|
+
# Django stuff:
|
|
63
|
+
*.log
|
|
64
|
+
local_settings.py
|
|
65
|
+
db.sqlite3
|
|
66
|
+
db.sqlite3-journal
|
|
67
|
+
|
|
68
|
+
# Flask stuff:
|
|
69
|
+
instance/
|
|
70
|
+
.webassets-cache
|
|
71
|
+
|
|
72
|
+
# Scrapy stuff:
|
|
73
|
+
.scrapy
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# IPython
|
|
79
|
+
profile_default/
|
|
80
|
+
ipython_config.py
|
|
81
|
+
|
|
82
|
+
# pyenv
|
|
83
|
+
.python-version
|
|
84
|
+
|
|
85
|
+
# pipenv
|
|
86
|
+
Pipfile.lock
|
|
87
|
+
|
|
88
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
89
|
+
__pypackages__/
|
|
90
|
+
|
|
91
|
+
# Celery stuff
|
|
92
|
+
celerybeat-schedule
|
|
93
|
+
celerybeat.pid
|
|
94
|
+
|
|
95
|
+
# SageMath parsed files
|
|
96
|
+
*.sage.py
|
|
97
|
+
|
|
98
|
+
# Environments
|
|
99
|
+
.env
|
|
100
|
+
.venv
|
|
101
|
+
env/
|
|
102
|
+
venv/
|
|
103
|
+
ENV/
|
|
104
|
+
env.bak/
|
|
105
|
+
venv.bak/
|
|
106
|
+
|
|
107
|
+
# Spyder project settings
|
|
108
|
+
.spyderproject
|
|
109
|
+
.spyproject
|
|
110
|
+
|
|
111
|
+
# Rope project settings
|
|
112
|
+
.ropeproject
|
|
113
|
+
|
|
114
|
+
# mkdocs documentation
|
|
115
|
+
/site
|
|
116
|
+
|
|
117
|
+
# mypy
|
|
118
|
+
.mypy_cache/
|
|
119
|
+
.dmypy.json
|
|
120
|
+
dmypy.json
|
|
121
|
+
|
|
122
|
+
# Pyre type checker
|
|
123
|
+
.pyre/
|
|
124
|
+
|
|
125
|
+
# Documentation
|
|
126
|
+
/site
|
|
127
|
+
index.md
|
|
128
|
+
docs/_build/
|
|
129
|
+
docs/src/_build/
|
|
130
|
+
docs/api
|
|
131
|
+
docs/index.md
|
|
132
|
+
docs/html
|
|
133
|
+
docs/jupyter_execute
|
|
134
|
+
index.md
|
|
135
|
+
|
|
136
|
+
# JS
|
|
137
|
+
js/coverage
|
|
138
|
+
js/dist
|
|
139
|
+
js/lib
|
|
140
|
+
js/node_modules
|
|
141
|
+
js/test-results
|
|
142
|
+
js/playwright-report
|
|
143
|
+
js/*.tgz
|
|
144
|
+
hatch_cpp/extension
|
|
145
|
+
|
|
146
|
+
# Jupyter
|
|
147
|
+
.ipynb_checkpoints
|
|
148
|
+
.autoversion
|
|
149
|
+
Untitled*.ipynb
|
|
150
|
+
!hatch_cpp/extension/hatch_cpp.json
|
|
151
|
+
!hatch_cpp/extension/install.json
|
|
152
|
+
hatch_cpp/nbextension
|
|
153
|
+
hatch_cpp/labextension
|
|
154
|
+
|
|
155
|
+
# Mac
|
|
156
|
+
.DS_Store
|
|
157
|
+
|
|
158
|
+
# Rust
|
|
159
|
+
target
|
|
@@ -186,7 +186,11 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
+
<<<<<<< before updating
|
|
189
190
|
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
=======
|
|
192
|
+
Copyright 2025 the hatch-cpp authors
|
|
193
|
+
>>>>>>> after updating
|
|
190
194
|
|
|
191
195
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
196
|
you may not use this file except in compliance with the License.
|
hatch_cpp-0.1.8/PKG-INFO
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hatch-cpp
|
|
3
|
+
Version: 0.1.8
|
|
4
|
+
Summary: Hatch plugin for C++ builds
|
|
5
|
+
Project-URL: Repository, https://github.com/python-project-templates/hatch-cpp
|
|
6
|
+
Project-URL: Homepage, https://github.com/python-project-templates/hatch-cpp
|
|
7
|
+
Author-email: the hatch-cpp authors <t.paine154@gmail.com>
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: build,c++,cmake,cpp,hatch,python
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Requires-Dist: hatchling>=1.20
|
|
25
|
+
Requires-Dist: pydantic
|
|
26
|
+
Provides-Extra: develop
|
|
27
|
+
Requires-Dist: build; extra == 'develop'
|
|
28
|
+
Requires-Dist: bump-my-version; extra == 'develop'
|
|
29
|
+
Requires-Dist: check-manifest; extra == 'develop'
|
|
30
|
+
Requires-Dist: codespell<2.5,>=2.4; extra == 'develop'
|
|
31
|
+
Requires-Dist: hatch-build; extra == 'develop'
|
|
32
|
+
Requires-Dist: hatchling; extra == 'develop'
|
|
33
|
+
Requires-Dist: mdformat-tables>=1; extra == 'develop'
|
|
34
|
+
Requires-Dist: mdformat<0.8,>=0.7.22; extra == 'develop'
|
|
35
|
+
Requires-Dist: nanobind<2.10.0; extra == 'develop'
|
|
36
|
+
Requires-Dist: pybind11; extra == 'develop'
|
|
37
|
+
Requires-Dist: pytest; extra == 'develop'
|
|
38
|
+
Requires-Dist: pytest-cov; extra == 'develop'
|
|
39
|
+
Requires-Dist: ruff; extra == 'develop'
|
|
40
|
+
Requires-Dist: toml; extra == 'develop'
|
|
41
|
+
Requires-Dist: twine; extra == 'develop'
|
|
42
|
+
Requires-Dist: uv; extra == 'develop'
|
|
43
|
+
Requires-Dist: wheel; extra == 'develop'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# hatch-cpp
|
|
47
|
+
|
|
48
|
+
Hatch plugin for C++ builds
|
|
49
|
+
|
|
50
|
+
[](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml)
|
|
51
|
+
[](https://codecov.io/gh/python-project-templates/hatch-cpp)
|
|
52
|
+
[](https://github.com/python-project-templates/hatch-cpp)
|
|
53
|
+
[](https://pypi.python.org/pypi/hatch-cpp)
|
|
54
|
+
|
|
55
|
+
## Overview
|
|
56
|
+
|
|
57
|
+
A simple, extensible C++ build plugin for [hatch](https://hatch.pypa.io/latest/).
|
|
58
|
+
|
|
59
|
+
```toml
|
|
60
|
+
[tool.hatch.build.hooks.hatch-cpp]
|
|
61
|
+
libraries = [
|
|
62
|
+
{name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
|
|
63
|
+
]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For more complete systems, see:
|
|
67
|
+
|
|
68
|
+
- [scikit-build-core](https://github.com/scikit-build/scikit-build-core)
|
|
69
|
+
- [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
Configuration is driven from the `[tool.hatch.build.hooks.hatch-cpp]` hatch hook configuration field in a `pyproject.toml`.
|
|
74
|
+
It is designed to closely match existing Python/C/C++ packaging tools.
|
|
75
|
+
|
|
76
|
+
```toml
|
|
77
|
+
verbose = true
|
|
78
|
+
libraries = { Library Args }
|
|
79
|
+
cmake = { CMake Args }
|
|
80
|
+
platform = { Platform, either "linux", "darwin", or "win32" }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
See the [test cases](./hatch_cpp/tests/) for more concrete examples.
|
|
84
|
+
|
|
85
|
+
`hatch-cpp` is driven by [pydantic](https://docs.pydantic.dev/latest/) models for configuration and execution of the build.
|
|
86
|
+
These models can themselves be overridden by setting `build-config-class` / `build-plan-class`.
|
|
87
|
+
|
|
88
|
+
### Library Arguments
|
|
89
|
+
|
|
90
|
+
```toml
|
|
91
|
+
name = "mylib"
|
|
92
|
+
sources = [
|
|
93
|
+
"path/to/file.cpp",
|
|
94
|
+
]
|
|
95
|
+
language = "c++"
|
|
96
|
+
|
|
97
|
+
binding = "cpython" # or "pybind11", "nanobind", "generic"
|
|
98
|
+
std = "" # Passed to -std= or /std:
|
|
99
|
+
|
|
100
|
+
include_dirs = ["paths/to/add/to/-I"]
|
|
101
|
+
library_dirs = ["paths/to/add/to/-L"]
|
|
102
|
+
libraries = ["-llibraries_to_link"]
|
|
103
|
+
|
|
104
|
+
extra_compile_args = ["--extra-compile-args"]
|
|
105
|
+
extra_link_args = ["--extra-link-args"]
|
|
106
|
+
extra_objects = ["extra_objects"]
|
|
107
|
+
|
|
108
|
+
define_macros = ["-Ddefines_to_use"]
|
|
109
|
+
undef_macros = ["-Uundefines_to_use"]
|
|
110
|
+
|
|
111
|
+
py_limited_api = "cp39" # limited API to use
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### CMake Arguments
|
|
115
|
+
|
|
116
|
+
`hatch-cpp` has some convenience integration with CMake.
|
|
117
|
+
Though this is not designed to be as full-featured as e.g. `scikit-build`, it should be satisfactory for many small projects.
|
|
118
|
+
|
|
119
|
+
```toml
|
|
120
|
+
root = "path/to/cmake/root"
|
|
121
|
+
build = "path/to/cmake/build/folder"
|
|
122
|
+
install = "path/to/cmake/install/folder"
|
|
123
|
+
|
|
124
|
+
cmake_arg_prefix = "MYPROJECT_"
|
|
125
|
+
cmake_args = {} # any other cmake args to pass
|
|
126
|
+
cmake_env_args = {} # env-specific cmake args to pass
|
|
127
|
+
|
|
128
|
+
include_flags = {} # include flags to pass -D
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Environment Variables
|
|
132
|
+
|
|
133
|
+
`hatch-cpp` will respect standard environment variables for compiler control.
|
|
134
|
+
|
|
135
|
+
| Name | Default | Description |
|
|
136
|
+
| :------------------------- | :------ | :-------------------- |
|
|
137
|
+
| `CC` | | C Compiler override |
|
|
138
|
+
| `CXX` | | C++ Compiler override |
|
|
139
|
+
| `LD` | | Linker override |
|
|
140
|
+
| `HATCH_CPP_PLATFORM` | | Platform to build |
|
|
141
|
+
| `HATCH_CPP_DISABLE_CCACHE` | | Disable CCache usage |
|
|
142
|
+
|
|
143
|
+
> [!NOTE]
|
|
144
|
+
> 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).
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# hatch-cpp
|
|
2
|
+
|
|
3
|
+
Hatch plugin for C++ builds
|
|
4
|
+
|
|
5
|
+
[](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml)
|
|
6
|
+
[](https://codecov.io/gh/python-project-templates/hatch-cpp)
|
|
7
|
+
[](https://github.com/python-project-templates/hatch-cpp)
|
|
8
|
+
[](https://pypi.python.org/pypi/hatch-cpp)
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
A simple, extensible C++ build plugin for [hatch](https://hatch.pypa.io/latest/).
|
|
13
|
+
|
|
14
|
+
```toml
|
|
15
|
+
[tool.hatch.build.hooks.hatch-cpp]
|
|
16
|
+
libraries = [
|
|
17
|
+
{name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
|
|
18
|
+
]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For more complete systems, see:
|
|
22
|
+
|
|
23
|
+
- [scikit-build-core](https://github.com/scikit-build/scikit-build-core)
|
|
24
|
+
- [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
Configuration is driven from the `[tool.hatch.build.hooks.hatch-cpp]` hatch hook configuration field in a `pyproject.toml`.
|
|
29
|
+
It is designed to closely match existing Python/C/C++ packaging tools.
|
|
30
|
+
|
|
31
|
+
```toml
|
|
32
|
+
verbose = true
|
|
33
|
+
libraries = { Library Args }
|
|
34
|
+
cmake = { CMake Args }
|
|
35
|
+
platform = { Platform, either "linux", "darwin", or "win32" }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
See the [test cases](./hatch_cpp/tests/) for more concrete examples.
|
|
39
|
+
|
|
40
|
+
`hatch-cpp` is driven by [pydantic](https://docs.pydantic.dev/latest/) models for configuration and execution of the build.
|
|
41
|
+
These models can themselves be overridden by setting `build-config-class` / `build-plan-class`.
|
|
42
|
+
|
|
43
|
+
### Library Arguments
|
|
44
|
+
|
|
45
|
+
```toml
|
|
46
|
+
name = "mylib"
|
|
47
|
+
sources = [
|
|
48
|
+
"path/to/file.cpp",
|
|
49
|
+
]
|
|
50
|
+
language = "c++"
|
|
51
|
+
|
|
52
|
+
binding = "cpython" # or "pybind11", "nanobind", "generic"
|
|
53
|
+
std = "" # Passed to -std= or /std:
|
|
54
|
+
|
|
55
|
+
include_dirs = ["paths/to/add/to/-I"]
|
|
56
|
+
library_dirs = ["paths/to/add/to/-L"]
|
|
57
|
+
libraries = ["-llibraries_to_link"]
|
|
58
|
+
|
|
59
|
+
extra_compile_args = ["--extra-compile-args"]
|
|
60
|
+
extra_link_args = ["--extra-link-args"]
|
|
61
|
+
extra_objects = ["extra_objects"]
|
|
62
|
+
|
|
63
|
+
define_macros = ["-Ddefines_to_use"]
|
|
64
|
+
undef_macros = ["-Uundefines_to_use"]
|
|
65
|
+
|
|
66
|
+
py_limited_api = "cp39" # limited API to use
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### CMake Arguments
|
|
70
|
+
|
|
71
|
+
`hatch-cpp` has some convenience integration with CMake.
|
|
72
|
+
Though this is not designed to be as full-featured as e.g. `scikit-build`, it should be satisfactory for many small projects.
|
|
73
|
+
|
|
74
|
+
```toml
|
|
75
|
+
root = "path/to/cmake/root"
|
|
76
|
+
build = "path/to/cmake/build/folder"
|
|
77
|
+
install = "path/to/cmake/install/folder"
|
|
78
|
+
|
|
79
|
+
cmake_arg_prefix = "MYPROJECT_"
|
|
80
|
+
cmake_args = {} # any other cmake args to pass
|
|
81
|
+
cmake_env_args = {} # env-specific cmake args to pass
|
|
82
|
+
|
|
83
|
+
include_flags = {} # include flags to pass -D
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Environment Variables
|
|
87
|
+
|
|
88
|
+
`hatch-cpp` will respect standard environment variables for compiler control.
|
|
89
|
+
|
|
90
|
+
| Name | Default | Description |
|
|
91
|
+
| :------------------------- | :------ | :-------------------- |
|
|
92
|
+
| `CC` | | C Compiler override |
|
|
93
|
+
| `CXX` | | C++ Compiler override |
|
|
94
|
+
| `LD` | | Linker override |
|
|
95
|
+
| `HATCH_CPP_PLATFORM` | | Platform to build |
|
|
96
|
+
| `HATCH_CPP_DISABLE_CCACHE` | | Disable CCache usage |
|
|
97
|
+
|
|
98
|
+
> [!NOTE]
|
|
99
|
+
> 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).
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from logging import getLogger
|
|
4
|
+
from os import getenv
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from platform import machine as platform_machine
|
|
7
|
+
from sys import platform as sys_platform, version_info
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
11
|
+
|
|
12
|
+
from .structs import HatchCppBuildConfig, HatchCppBuildPlan
|
|
13
|
+
from .utils import import_string
|
|
14
|
+
|
|
15
|
+
__all__ = ("HatchCppBuildHook",)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
|
|
19
|
+
"""The hatch-cpp build hook."""
|
|
20
|
+
|
|
21
|
+
PLUGIN_NAME = "hatch-cpp"
|
|
22
|
+
_logger = getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
|
|
25
|
+
"""Initialize the plugin."""
|
|
26
|
+
# Log some basic information
|
|
27
|
+
project_name = self.metadata.config["project"]["name"]
|
|
28
|
+
self._logger.info("Initializing hatch-cpp plugin version %s", version)
|
|
29
|
+
self._logger.info(f"Running hatch-cpp: {project_name}")
|
|
30
|
+
|
|
31
|
+
# Only run if creating wheel
|
|
32
|
+
# TODO: Add support for specify sdist-plan
|
|
33
|
+
if self.target_name != "wheel":
|
|
34
|
+
self._logger.info("ignoring target name %s", self.target_name)
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
# Skip if SKIP_HATCH_CPP is set
|
|
38
|
+
# TODO: Support CLI once https://github.com/pypa/hatch/pull/1743
|
|
39
|
+
if getenv("SKIP_HATCH_CPP"):
|
|
40
|
+
self._logger.info("Skipping the build hook since SKIP_HATCH_CPP was set")
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
# Get build config class or use default
|
|
44
|
+
build_config_class = import_string(self.config["build-config-class"]) if "build-config-class" in self.config else HatchCppBuildConfig
|
|
45
|
+
|
|
46
|
+
# Instantiate build config
|
|
47
|
+
config = build_config_class(name=project_name, **self.config)
|
|
48
|
+
|
|
49
|
+
# Get build plan class or use default
|
|
50
|
+
build_plan_class = import_string(self.config["build-plan-class"]) if "build-plan-class" in self.config else HatchCppBuildPlan
|
|
51
|
+
|
|
52
|
+
# Instantiate builder
|
|
53
|
+
build_plan = build_plan_class(**config.model_dump())
|
|
54
|
+
|
|
55
|
+
# Generate commands
|
|
56
|
+
build_plan.generate()
|
|
57
|
+
|
|
58
|
+
# Log commands if in verbose mode
|
|
59
|
+
if config.verbose:
|
|
60
|
+
for command in build_plan.commands:
|
|
61
|
+
self._logger.warning(command)
|
|
62
|
+
|
|
63
|
+
# Execute build plan
|
|
64
|
+
build_plan.execute()
|
|
65
|
+
|
|
66
|
+
# Perform any cleanup actions
|
|
67
|
+
build_plan.cleanup()
|
|
68
|
+
|
|
69
|
+
if build_plan.libraries:
|
|
70
|
+
# force include libraries
|
|
71
|
+
for library in build_plan.libraries:
|
|
72
|
+
name = library.get_qualified_name(build_plan.platform.platform)
|
|
73
|
+
build_data["force_include"][name] = name
|
|
74
|
+
|
|
75
|
+
build_data["pure_python"] = False
|
|
76
|
+
machine = platform_machine()
|
|
77
|
+
version_major = version_info.major
|
|
78
|
+
version_minor = version_info.minor
|
|
79
|
+
if "darwin" in sys_platform:
|
|
80
|
+
os_name = "macosx_11_0"
|
|
81
|
+
elif "linux" in sys_platform:
|
|
82
|
+
os_name = "linux"
|
|
83
|
+
else:
|
|
84
|
+
os_name = "win"
|
|
85
|
+
if all([lib.py_limited_api for lib in build_plan.libraries]):
|
|
86
|
+
build_data["tag"] = f"cp{version_major}{version_minor}-abi3-{os_name}_{machine}"
|
|
87
|
+
else:
|
|
88
|
+
build_data["tag"] = f"cp{version_major}{version_minor}-cp{version_major}{version_minor}-{os_name}_{machine}"
|
|
89
|
+
else:
|
|
90
|
+
build_data["pure_python"] = False
|
|
91
|
+
machine = platform_machine()
|
|
92
|
+
version_major = version_info.major
|
|
93
|
+
version_minor = version_info.minor
|
|
94
|
+
# TODO abi3
|
|
95
|
+
if "darwin" in sys_platform:
|
|
96
|
+
os_name = "macosx_11_0"
|
|
97
|
+
elif "linux" in sys_platform:
|
|
98
|
+
os_name = "linux"
|
|
99
|
+
else:
|
|
100
|
+
os_name = "win"
|
|
101
|
+
build_data["tag"] = f"cp{version_major}{version_minor}-cp{version_major}{version_minor}-{os_name}_{machine}"
|
|
102
|
+
|
|
103
|
+
# force include libraries
|
|
104
|
+
for path in Path(".").rglob("*"):
|
|
105
|
+
if path.is_dir():
|
|
106
|
+
continue
|
|
107
|
+
if str(path).startswith(str(build_plan.cmake.build)) or str(path).startswith("dist"):
|
|
108
|
+
continue
|
|
109
|
+
if path.suffix in (".pyd", ".dll", ".so", ".dylib"):
|
|
110
|
+
build_data["force_include"][str(path)] = str(path)
|
|
111
|
+
|
|
112
|
+
for path in build_data["force_include"]:
|
|
113
|
+
self._logger.warning(f"Force include: {path}")
|