hatch-cpp 0.1.7__tar.gz → 0.1.9__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.
Files changed (64) hide show
  1. hatch_cpp-0.1.9/.gitignore +162 -0
  2. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/LICENSE +4 -0
  3. hatch_cpp-0.1.9/PKG-INFO +144 -0
  4. hatch_cpp-0.1.9/README.md +99 -0
  5. hatch_cpp-0.1.9/hatch_cpp/__init__.py +6 -0
  6. hatch_cpp-0.1.9/hatch_cpp/config.py +101 -0
  7. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/plugin.py +1 -1
  8. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_cmake_vcpkg/CMakeLists.txt +92 -0
  9. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_cmake_vcpkg/Makefile +140 -0
  10. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_cmake_vcpkg/project/include/project/basic.hpp +17 -0
  11. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_cmake_vcpkg/pyproject.toml +39 -0
  12. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_cmake_vcpkg/vcpkg.json +8 -0
  13. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_limited_api/cpp/project/basic.hpp +17 -0
  14. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.cpp +5 -0
  15. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.hpp +17 -0
  16. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.cpp +5 -0
  17. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.hpp +17 -0
  18. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_override_toolchain/pyproject.toml +38 -0
  19. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.cpp +6 -0
  20. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.hpp +9 -0
  21. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_pybind_vcpkg/project/__init__.py +0 -0
  22. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_pybind_vcpkg/pyproject.toml +35 -0
  23. hatch_cpp-0.1.9/hatch_cpp/tests/test_project_pybind_vcpkg/vcpkg.json +8 -0
  24. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_projects.py +5 -2
  25. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_structs.py +9 -1
  26. hatch_cpp-0.1.9/hatch_cpp/toolchains/__init__.py +3 -0
  27. hatch_cpp-0.1.9/hatch_cpp/toolchains/cmake.py +87 -0
  28. hatch_cpp-0.1.7/hatch_cpp/structs.py → hatch_cpp-0.1.9/hatch_cpp/toolchains/common.py +26 -105
  29. hatch_cpp-0.1.9/hatch_cpp/toolchains/vcpkg.py +64 -0
  30. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/pyproject.toml +18 -9
  31. hatch_cpp-0.1.7/.gitignore +0 -170
  32. hatch_cpp-0.1.7/PKG-INFO +0 -72
  33. hatch_cpp-0.1.7/README.md +0 -35
  34. hatch_cpp-0.1.7/hatch_cpp/__init__.py +0 -5
  35. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/hooks.py +0 -0
  36. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_basic/cpp/project/basic.cpp +0 -0
  37. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_basic/cpp/project/basic.hpp +0 -0
  38. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_basic/project/__init__.py +0 -0
  39. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_basic/pyproject.toml +0 -0
  40. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_cmake/CMakeLists.txt +0 -0
  41. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_cmake/Makefile +0 -0
  42. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_cmake/cpp/project/basic.cpp +0 -0
  43. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_cmake/cpp/project/basic.hpp +0 -0
  44. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_cmake/project/__init__.py +0 -0
  45. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_limited_api/cpp → hatch_cpp-0.1.9/hatch_cpp/tests/test_project_cmake/project/include}/project/basic.hpp +0 -0
  46. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_cmake/pyproject.toml +0 -0
  47. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_limited_api → hatch_cpp-0.1.9/hatch_cpp/tests/test_project_cmake_vcpkg}/cpp/project/basic.cpp +0 -0
  48. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_override_classes → hatch_cpp-0.1.9/hatch_cpp/tests/test_project_cmake_vcpkg}/cpp/project/basic.hpp +0 -0
  49. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_limited_api → hatch_cpp-0.1.9/hatch_cpp/tests/test_project_cmake_vcpkg}/project/__init__.py +0 -0
  50. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_override_classes → hatch_cpp-0.1.9/hatch_cpp/tests/test_project_limited_api}/cpp/project/basic.cpp +0 -0
  51. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_nanobind → hatch_cpp-0.1.9/hatch_cpp/tests/test_project_limited_api}/project/__init__.py +0 -0
  52. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_limited_api/pyproject.toml +0 -0
  53. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.cpp +0 -0
  54. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.hpp +0 -0
  55. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_override_classes → hatch_cpp-0.1.9/hatch_cpp/tests/test_project_nanobind}/project/__init__.py +0 -0
  56. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_nanobind/pyproject.toml +0 -0
  57. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_pybind → hatch_cpp-0.1.9/hatch_cpp/tests/test_project_override_classes}/project/__init__.py +0 -0
  58. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_override_classes/pyproject.toml +0 -0
  59. {hatch_cpp-0.1.7/hatch_cpp/toolchains → hatch_cpp-0.1.9/hatch_cpp/tests/test_project_override_toolchain/project}/__init__.py +0 -0
  60. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.cpp +0 -0
  61. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.hpp +0 -0
  62. /hatch_cpp-0.1.7/hatch_cpp/toolchains/cmake.py → /hatch_cpp-0.1.9/hatch_cpp/tests/test_project_pybind/project/__init__.py +0 -0
  63. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/tests/test_project_pybind/pyproject.toml +0 -0
  64. {hatch_cpp-0.1.7 → hatch_cpp-0.1.9}/hatch_cpp/utils.py +0 -0
@@ -0,0 +1,162 @@
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
160
+
161
+ vcpkg
162
+ vcpkg_installed
@@ -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.
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: hatch-cpp
3
+ Version: 0.1.9
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<1.1,>=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<0.15,>=0.9; 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
+ [![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)
51
+ [![codecov](https://codecov.io/gh/python-project-templates/hatch-cpp/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/hatch-cpp)
52
+ [![License](https://img.shields.io/github/license/python-project-templates/hatch-cpp)](https://github.com/python-project-templates/hatch-cpp)
53
+ [![PyPI](https://img.shields.io/pypi/v/hatch-cpp.svg)](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
+ [![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)
6
+ [![codecov](https://codecov.io/gh/python-project-templates/hatch-cpp/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/hatch-cpp)
7
+ [![License](https://img.shields.io/github/license/python-project-templates/hatch-cpp)](https://github.com/python-project-templates/hatch-cpp)
8
+ [![PyPI](https://img.shields.io/pypi/v/hatch-cpp.svg)](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,6 @@
1
+ __version__ = "0.1.9"
2
+
3
+ from .config import *
4
+ from .hooks import *
5
+ from .plugin import *
6
+ from .toolchains import *
@@ -0,0 +1,101 @@
1
+ from __future__ import annotations
2
+
3
+ from logging import getLogger
4
+ from os import system as system_call
5
+ from pathlib import Path
6
+ from typing import List, Optional
7
+
8
+ from pydantic import BaseModel, Field, model_validator
9
+
10
+ from .toolchains import BuildType, HatchCppCmakeConfiguration, HatchCppLibrary, HatchCppPlatform, HatchCppVcpkgConfiguration, Toolchain
11
+
12
+ __all__ = (
13
+ "HatchCppBuildConfig",
14
+ "HatchCppBuildPlan",
15
+ )
16
+
17
+
18
+ _log = getLogger(__name__)
19
+
20
+
21
+ class HatchCppBuildConfig(BaseModel):
22
+ """Build config values for Hatch C++ Builder."""
23
+
24
+ verbose: Optional[bool] = Field(default=False)
25
+ name: Optional[str] = Field(default=None)
26
+ libraries: List[HatchCppLibrary] = Field(default_factory=list)
27
+ cmake: Optional[HatchCppCmakeConfiguration] = Field(default=None)
28
+ platform: Optional[HatchCppPlatform] = Field(default_factory=HatchCppPlatform.default)
29
+ vcpkg: Optional[HatchCppVcpkgConfiguration] = Field(default_factory=HatchCppVcpkgConfiguration)
30
+
31
+ @model_validator(mode="wrap")
32
+ @classmethod
33
+ def validate_model(cls, data, handler):
34
+ if "toolchain" in data:
35
+ data["platform"] = HatchCppPlatform.platform_for_toolchain(data["toolchain"])
36
+ data.pop("toolchain")
37
+ elif "platform" not in data:
38
+ data["platform"] = HatchCppPlatform.default()
39
+ if "cc" in data:
40
+ data["platform"].cc = data["cc"]
41
+ data.pop("cc")
42
+ if "cxx" in data:
43
+ data["platform"].cxx = data["cxx"]
44
+ data.pop("cxx")
45
+ if "ld" in data:
46
+ data["platform"].ld = data["ld"]
47
+ data.pop("ld")
48
+ if "vcpkg" in data and data["vcpkg"] == "false":
49
+ data["vcpkg"] = None
50
+ model = handler(data)
51
+ if model.cmake and model.libraries:
52
+ raise ValueError("Must not provide libraries when using cmake toolchain.")
53
+ return model
54
+
55
+
56
+ class HatchCppBuildPlan(HatchCppBuildConfig):
57
+ build_type: BuildType = "release"
58
+ commands: List[str] = Field(default_factory=list)
59
+
60
+ _active_toolchains: List[Toolchain] = []
61
+
62
+ def generate(self):
63
+ self.commands = []
64
+
65
+ # Evaluate toolchains
66
+ if self.vcpkg and Path(self.vcpkg.vcpkg).exists():
67
+ self._active_toolchains.append("vcpkg")
68
+ if self.libraries:
69
+ self._active_toolchains.append("vanilla")
70
+ elif self.cmake:
71
+ self._active_toolchains.append("cmake")
72
+
73
+ # Collect toolchain commands
74
+ if "vcpkg" in self._active_toolchains:
75
+ self.commands.extend(self.vcpkg.generate(self))
76
+
77
+ if "vanilla" in self._active_toolchains:
78
+ if "vcpkg" in self._active_toolchains:
79
+ _log.warning("vcpkg toolchain is active; ensure that your compiler is configured to use vcpkg includes and libs.")
80
+
81
+ for library in self.libraries:
82
+ compile_flags = self.platform.get_compile_flags(library, self.build_type)
83
+ link_flags = self.platform.get_link_flags(library, self.build_type)
84
+ self.commands.append(
85
+ f"{self.platform.cc if library.language == 'c' else self.platform.cxx} {' '.join(library.sources)} {compile_flags} {link_flags}"
86
+ )
87
+
88
+ if "cmake" in self._active_toolchains:
89
+ self.commands.extend(self.cmake.generate(self))
90
+
91
+ return self.commands
92
+
93
+ def execute(self):
94
+ for command in self.commands:
95
+ system_call(command)
96
+ return self.commands
97
+
98
+ def cleanup(self):
99
+ if self.platform.platform == "win32":
100
+ for temp_obj in Path(".").glob("*.obj"):
101
+ temp_obj.unlink()
@@ -9,7 +9,7 @@ from typing import Any
9
9
 
10
10
  from hatchling.builders.hooks.plugin.interface import BuildHookInterface
11
11
 
12
- from .structs import HatchCppBuildConfig, HatchCppBuildPlan
12
+ from .config import HatchCppBuildConfig, HatchCppBuildPlan
13
13
  from .utils import import_string
14
14
 
15
15
  __all__ = ("HatchCppBuildHook",)
@@ -0,0 +1,92 @@
1
+ cmake_minimum_required(VERSION 3.20.0)
2
+ project(hatch-cpp-test-project-basic VERSION "0.1.0")
3
+ set(CMAKE_CXX_STANDARD 20)
4
+ include(CheckCCompilerFlag)
5
+ include(CheckLinkerFlag)
6
+
7
+ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
8
+ set(WIN32 ON)
9
+ set(MACOS OFF)
10
+ set(LINUX OFF)
11
+ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
12
+ set(WIN32 OFF)
13
+ set(MACOS ON)
14
+ set(LINUX OFF)
15
+ else()
16
+ set(WIN32 OFF)
17
+ set(MACOS OFF)
18
+ set(LINUX ON)
19
+ endif()
20
+
21
+ option(CMAKE_BUILD_TYPE "Release/Debug build" RELEASE)
22
+ option(HATCH_CPP_TEST_PROJECT_BASIC_BUILD_TESTS "Build tests" OFF)
23
+ option(HATCH_CPP_TEST_PROJECT_BASIC_MANYLINUX "Build for python's manylinux setup" OFF)
24
+
25
+ string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
26
+
27
+ set(BUILD_SHARED_LIBS TRUE)
28
+ set(CMAKE_MACOSX_RPATH TRUE)
29
+ set(CMAKE_SKIP_RPATH FALSE)
30
+ set(CMAKE_SKIP_BUILD_RPATH FALSE)
31
+ set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
32
+ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
33
+ set(CMAKE_INSTALL_NAME_DIR "@rpath")
34
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
35
+
36
+ string(REGEX REPLACE "[ ]*-O[^ ]+[ ]*" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
37
+ string(REGEX REPLACE "[ ]*-Wl,-O2 -Wl,[^ ]+[ ]*" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
38
+ string(REGEX REPLACE "[ ]*-Wl,-O2 -Wl,[^ ]+[ ]*" " " CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
39
+
40
+
41
+ if(MACOS)
42
+ set(CMAKE_THREAD_LIBS_INIT "-lpthread")
43
+ set(CMAKE_HAVE_THREADS_LIBRARY 1)
44
+ set(CMAKE_USE_WIN32_THREADS_INIT 0)
45
+ set(CMAKE_USE_PTHREADS_INIT 1)
46
+ set(THREADS_PREFER_PTHREAD_FLAG ON)
47
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
48
+ endif()
49
+
50
+
51
+ if(MACOS)
52
+ set(CMAKE_INSTALL_RPATH "@loader_path/")
53
+ elseif(LINUX)
54
+ set(CMAKE_INSTALL_RPATH "\$ORIGIN")
55
+ endif()
56
+
57
+ if(WIN32)
58
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj")
59
+ foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
60
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd${warning}")
61
+ endforeach(warning)
62
+ else()
63
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
64
+ -g \
65
+ -Wall \
66
+ -Werror \
67
+ -Wno-deprecated-declarations \
68
+ -Wno-deprecated \
69
+ ")
70
+ endif()
71
+
72
+
73
+ find_package(Python ${CSP_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development.Module)
74
+ link_directories(${Python_LIBRARY_DIRS})
75
+ include_directories(${Python_INCLUDE_DIRS})
76
+
77
+ set(CMAKE_SHARED_LIBRARY_PREFIX "")
78
+ if(NOT WIN32)
79
+ set(CMAKE_SHARED_LIBRARY_SUFFIX .so)
80
+ else()
81
+ set(CMAKE_SHARED_LIBRARY_SUFFIX .pyd)
82
+ endif()
83
+
84
+ include_directories("${CMAKE_SOURCE_DIR}/cpp")
85
+
86
+ add_library(extension SHARED cpp/project/basic.cpp)
87
+ set_target_properties(extension PROPERTIES PUBLIC_HEADER cpp/project/basic.hpp)
88
+ install(TARGETS extension
89
+ PUBLIC_HEADER DESTINATION project/include/project
90
+ RUNTIME DESTINATION project/
91
+ LIBRARY DESTINATION project/
92
+ )