hatch-cpp 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl
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/__init__.py +5 -4
- hatch_cpp/config.py +101 -0
- hatch_cpp/plugin.py +1 -1
- hatch_cpp/tests/test_project_cmake/project/include/project/basic.hpp +17 -0
- hatch_cpp/tests/test_project_cmake_vcpkg/CMakeLists.txt +92 -0
- hatch_cpp/tests/test_project_cmake_vcpkg/Makefile +140 -0
- hatch_cpp/tests/test_project_cmake_vcpkg/cpp/project/basic.cpp +5 -0
- hatch_cpp/tests/test_project_cmake_vcpkg/cpp/project/basic.hpp +17 -0
- hatch_cpp/tests/test_project_cmake_vcpkg/project/__init__.py +0 -0
- hatch_cpp/tests/test_project_cmake_vcpkg/project/include/project/basic.hpp +17 -0
- hatch_cpp/tests/test_project_cmake_vcpkg/pyproject.toml +39 -0
- hatch_cpp/tests/test_project_cmake_vcpkg/vcpkg.json +8 -0
- hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.cpp +5 -0
- hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.hpp +17 -0
- hatch_cpp/tests/test_project_override_toolchain/project/__init__.py +0 -0
- hatch_cpp/tests/test_project_override_toolchain/pyproject.toml +38 -0
- hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.cpp +6 -0
- hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.hpp +9 -0
- hatch_cpp/tests/test_project_pybind_vcpkg/project/__init__.py +0 -0
- hatch_cpp/tests/test_project_pybind_vcpkg/pyproject.toml +35 -0
- hatch_cpp/tests/test_project_pybind_vcpkg/vcpkg.json +8 -0
- hatch_cpp/tests/test_projects.py +5 -2
- hatch_cpp/tests/test_structs.py +9 -1
- hatch_cpp/toolchains/__init__.py +3 -0
- hatch_cpp/toolchains/cmake.py +87 -0
- hatch_cpp/{structs.py → toolchains/common.py} +26 -105
- hatch_cpp/toolchains/vcpkg.py +64 -0
- hatch_cpp-0.1.9.dist-info/METADATA +144 -0
- hatch_cpp-0.1.9.dist-info/RECORD +60 -0
- {hatch_cpp-0.1.7.dist-info → hatch_cpp-0.1.9.dist-info}/licenses/LICENSE +4 -0
- hatch_cpp-0.1.7.dist-info/METADATA +0 -72
- hatch_cpp-0.1.7.dist-info/RECORD +0 -40
- {hatch_cpp-0.1.7.dist-info → hatch_cpp-0.1.9.dist-info}/WHEEL +0 -0
- {hatch_cpp-0.1.7.dist-info → hatch_cpp-0.1.9.dist-info}/entry_points.txt +0 -0
hatch_cpp/__init__.py
CHANGED
hatch_cpp/config.py
ADDED
|
@@ -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()
|
hatch_cpp/plugin.py
CHANGED
|
@@ -9,7 +9,7 @@ from typing import Any
|
|
|
9
9
|
|
|
10
10
|
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
11
11
|
|
|
12
|
-
from .
|
|
12
|
+
from .config import HatchCppBuildConfig, HatchCppBuildPlan
|
|
13
13
|
from .utils import import_string
|
|
14
14
|
|
|
15
15
|
__all__ = ("HatchCppBuildHook",)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "Python.h"
|
|
3
|
+
|
|
4
|
+
PyObject* hello(PyObject*, PyObject*);
|
|
5
|
+
|
|
6
|
+
static PyMethodDef extension_methods[] = {
|
|
7
|
+
{"hello", (PyCFunction)hello, METH_NOARGS},
|
|
8
|
+
{nullptr, nullptr, 0, nullptr}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
static PyModuleDef extension_module = {
|
|
12
|
+
PyModuleDef_HEAD_INIT, "extension", "extension", -1, extension_methods};
|
|
13
|
+
|
|
14
|
+
PyMODINIT_FUNC PyInit_extension(void) {
|
|
15
|
+
Py_Initialize();
|
|
16
|
+
return PyModule_Create(&extension_module);
|
|
17
|
+
}
|
|
@@ -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
|
+
)
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# CMAKE generated file: DO NOT EDIT!
|
|
2
|
+
# Generated by "Unix Makefiles" Generator, CMake Version 3.31
|
|
3
|
+
|
|
4
|
+
# Default target executed when no arguments are given to make.
|
|
5
|
+
default_target: all
|
|
6
|
+
.PHONY : default_target
|
|
7
|
+
|
|
8
|
+
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
|
|
9
|
+
.NOTPARALLEL:
|
|
10
|
+
|
|
11
|
+
#=============================================================================
|
|
12
|
+
# Special targets provided by cmake.
|
|
13
|
+
|
|
14
|
+
# Disable implicit rules so canonical targets will work.
|
|
15
|
+
.SUFFIXES:
|
|
16
|
+
|
|
17
|
+
# Disable VCS-based implicit rules.
|
|
18
|
+
% : %,v
|
|
19
|
+
|
|
20
|
+
# Disable VCS-based implicit rules.
|
|
21
|
+
% : RCS/%
|
|
22
|
+
|
|
23
|
+
# Disable VCS-based implicit rules.
|
|
24
|
+
% : RCS/%,v
|
|
25
|
+
|
|
26
|
+
# Disable VCS-based implicit rules.
|
|
27
|
+
% : SCCS/s.%
|
|
28
|
+
|
|
29
|
+
# Disable VCS-based implicit rules.
|
|
30
|
+
% : s.%
|
|
31
|
+
|
|
32
|
+
.SUFFIXES: .hpux_make_needs_suffix_list
|
|
33
|
+
|
|
34
|
+
# Command-line flag to silence nested $(MAKE).
|
|
35
|
+
$(VERBOSE)MAKESILENT = -s
|
|
36
|
+
|
|
37
|
+
#Suppress display of executed commands.
|
|
38
|
+
$(VERBOSE).SILENT:
|
|
39
|
+
|
|
40
|
+
# A target that is always out of date.
|
|
41
|
+
cmake_force:
|
|
42
|
+
.PHONY : cmake_force
|
|
43
|
+
|
|
44
|
+
#=============================================================================
|
|
45
|
+
# Set environment variables for the build.
|
|
46
|
+
|
|
47
|
+
# The shell in which to execute make rules.
|
|
48
|
+
SHELL = /bin/sh
|
|
49
|
+
|
|
50
|
+
# The CMake executable.
|
|
51
|
+
CMAKE_COMMAND = /opt/homebrew/bin/cmake
|
|
52
|
+
|
|
53
|
+
# The command to remove a file.
|
|
54
|
+
RM = /opt/homebrew/bin/cmake -E rm -f
|
|
55
|
+
|
|
56
|
+
# Escaping for special characters.
|
|
57
|
+
EQUALS = =
|
|
58
|
+
|
|
59
|
+
# The top-level source directory on which CMake was run.
|
|
60
|
+
CMAKE_SOURCE_DIR = /Users/timkpaine/Developer/projects/templates/hatch-cpp/hatch_cpp/tests/test_project_cmake
|
|
61
|
+
|
|
62
|
+
# The top-level build directory on which CMake was run.
|
|
63
|
+
CMAKE_BINARY_DIR = /Users/timkpaine/Developer/projects/templates/hatch-cpp/hatch_cpp/tests/test_project_cmake
|
|
64
|
+
|
|
65
|
+
#=============================================================================
|
|
66
|
+
# Targets provided globally by CMake.
|
|
67
|
+
|
|
68
|
+
# Special rule for the target edit_cache
|
|
69
|
+
edit_cache:
|
|
70
|
+
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake cache editor..."
|
|
71
|
+
/opt/homebrew/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
|
|
72
|
+
.PHONY : edit_cache
|
|
73
|
+
|
|
74
|
+
# Special rule for the target edit_cache
|
|
75
|
+
edit_cache/fast: edit_cache
|
|
76
|
+
.PHONY : edit_cache/fast
|
|
77
|
+
|
|
78
|
+
# Special rule for the target rebuild_cache
|
|
79
|
+
rebuild_cache:
|
|
80
|
+
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake to regenerate build system..."
|
|
81
|
+
/opt/homebrew/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
|
|
82
|
+
.PHONY : rebuild_cache
|
|
83
|
+
|
|
84
|
+
# Special rule for the target rebuild_cache
|
|
85
|
+
rebuild_cache/fast: rebuild_cache
|
|
86
|
+
.PHONY : rebuild_cache/fast
|
|
87
|
+
|
|
88
|
+
# The main all target
|
|
89
|
+
all: cmake_check_build_system
|
|
90
|
+
$(CMAKE_COMMAND) -E cmake_progress_start /Users/timkpaine/Developer/projects/templates/hatch-cpp/hatch_cpp/tests/test_project_cmake/CMakeFiles /Users/timkpaine/Developer/projects/templates/hatch-cpp/hatch_cpp/tests/test_project_cmake//CMakeFiles/progress.marks
|
|
91
|
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all
|
|
92
|
+
$(CMAKE_COMMAND) -E cmake_progress_start /Users/timkpaine/Developer/projects/templates/hatch-cpp/hatch_cpp/tests/test_project_cmake/CMakeFiles 0
|
|
93
|
+
.PHONY : all
|
|
94
|
+
|
|
95
|
+
# The main clean target
|
|
96
|
+
clean:
|
|
97
|
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean
|
|
98
|
+
.PHONY : clean
|
|
99
|
+
|
|
100
|
+
# The main clean target
|
|
101
|
+
clean/fast: clean
|
|
102
|
+
.PHONY : clean/fast
|
|
103
|
+
|
|
104
|
+
# Prepare targets for installation.
|
|
105
|
+
preinstall: all
|
|
106
|
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
|
|
107
|
+
.PHONY : preinstall
|
|
108
|
+
|
|
109
|
+
# Prepare targets for installation.
|
|
110
|
+
preinstall/fast:
|
|
111
|
+
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
|
|
112
|
+
.PHONY : preinstall/fast
|
|
113
|
+
|
|
114
|
+
# clear depends
|
|
115
|
+
depend:
|
|
116
|
+
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
|
|
117
|
+
.PHONY : depend
|
|
118
|
+
|
|
119
|
+
# Help Target
|
|
120
|
+
help:
|
|
121
|
+
@echo "The following are some of the valid targets for this Makefile:"
|
|
122
|
+
@echo "... all (the default if no target is provided)"
|
|
123
|
+
@echo "... clean"
|
|
124
|
+
@echo "... depend"
|
|
125
|
+
@echo "... edit_cache"
|
|
126
|
+
@echo "... rebuild_cache"
|
|
127
|
+
.PHONY : help
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
#=============================================================================
|
|
132
|
+
# Special targets to cleanup operation of make.
|
|
133
|
+
|
|
134
|
+
# Special rule to run CMake to check the build system integrity.
|
|
135
|
+
# No rule that depends on this can have commands that come from listfiles
|
|
136
|
+
# because they might be regenerated.
|
|
137
|
+
cmake_check_build_system:
|
|
138
|
+
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
|
|
139
|
+
.PHONY : cmake_check_build_system
|
|
140
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "Python.h"
|
|
3
|
+
|
|
4
|
+
PyObject* hello(PyObject*, PyObject*);
|
|
5
|
+
|
|
6
|
+
static PyMethodDef extension_methods[] = {
|
|
7
|
+
{"hello", (PyCFunction)hello, METH_NOARGS},
|
|
8
|
+
{nullptr, nullptr, 0, nullptr}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
static PyModuleDef extension_module = {
|
|
12
|
+
PyModuleDef_HEAD_INIT, "extension", "extension", -1, extension_methods};
|
|
13
|
+
|
|
14
|
+
PyMODINIT_FUNC PyInit_extension(void) {
|
|
15
|
+
Py_Initialize();
|
|
16
|
+
return PyModule_Create(&extension_module);
|
|
17
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "Python.h"
|
|
3
|
+
|
|
4
|
+
PyObject* hello(PyObject*, PyObject*);
|
|
5
|
+
|
|
6
|
+
static PyMethodDef extension_methods[] = {
|
|
7
|
+
{"hello", (PyCFunction)hello, METH_NOARGS},
|
|
8
|
+
{nullptr, nullptr, 0, nullptr}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
static PyModuleDef extension_module = {
|
|
12
|
+
PyModuleDef_HEAD_INIT, "extension", "extension", -1, extension_methods};
|
|
13
|
+
|
|
14
|
+
PyMODINIT_FUNC PyInit_extension(void) {
|
|
15
|
+
Py_Initialize();
|
|
16
|
+
return PyModule_Create(&extension_module);
|
|
17
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.20"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hatch-cpp-test-project-basic"
|
|
7
|
+
description = "Basic test project for hatch-cpp"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"hatchling>=1.20",
|
|
12
|
+
"hatch-cpp",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[tool.hatch.build]
|
|
16
|
+
artifacts = [
|
|
17
|
+
"project/*.dll",
|
|
18
|
+
"project/*.dylib",
|
|
19
|
+
"project/*.so",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.sources]
|
|
23
|
+
src = "/"
|
|
24
|
+
|
|
25
|
+
[tool.hatch.build.targets.sdist]
|
|
26
|
+
packages = ["project"]
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel]
|
|
29
|
+
packages = ["project"]
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build.hooks.hatch-cpp]
|
|
32
|
+
verbose = true
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.hooks.hatch-cpp.cmake]
|
|
35
|
+
root = "CMakeLists.txt"
|
|
36
|
+
cmake_args = {"BUILD_TESTS" = "OFF"}
|
|
37
|
+
include_flags = {"python_version" = true}
|
|
38
|
+
[tool.hatch.build.hooks.hatch-cpp.cmake.cmake_env_args]
|
|
39
|
+
linux = {"MANYLINUX" = "ON"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "Python.h"
|
|
3
|
+
|
|
4
|
+
PyObject* hello(PyObject*, PyObject*);
|
|
5
|
+
|
|
6
|
+
static PyMethodDef extension_methods[] = {
|
|
7
|
+
{"hello", (PyCFunction)hello, METH_NOARGS},
|
|
8
|
+
{nullptr, nullptr, 0, nullptr}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
static PyModuleDef extension_module = {
|
|
12
|
+
PyModuleDef_HEAD_INIT, "extension", "extension", -1, extension_methods};
|
|
13
|
+
|
|
14
|
+
PyMODINIT_FUNC PyInit_extension(void) {
|
|
15
|
+
Py_Initialize();
|
|
16
|
+
return PyModule_Create(&extension_module);
|
|
17
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.20"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hatch-cpp-test-project-toolchain"
|
|
7
|
+
description = "Toolchain override test project for hatch-cpp"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"hatchling>=1.20",
|
|
12
|
+
"hatch-cpp",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[tool.hatch.build]
|
|
16
|
+
artifacts = [
|
|
17
|
+
"project/*.dll",
|
|
18
|
+
"project/*.dylib",
|
|
19
|
+
"project/*.so",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.sources]
|
|
23
|
+
src = "/"
|
|
24
|
+
|
|
25
|
+
[tool.hatch.build.targets.sdist]
|
|
26
|
+
packages = ["project"]
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel]
|
|
29
|
+
packages = ["project"]
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build.hooks.hatch-cpp]
|
|
32
|
+
verbose = true
|
|
33
|
+
libraries = [
|
|
34
|
+
{name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
|
|
35
|
+
]
|
|
36
|
+
toolchain = "gcc"
|
|
37
|
+
cc = "clang"
|
|
38
|
+
cxx = "clang++"
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.20"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hatch-cpp-test-project-pybind"
|
|
7
|
+
description = "Basic test project for hatch-cpp"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"hatchling>=1.20",
|
|
12
|
+
"hatch-cpp",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[tool.hatch.build]
|
|
16
|
+
artifacts = [
|
|
17
|
+
"project/*.dll",
|
|
18
|
+
"project/*.dylib",
|
|
19
|
+
"project/*.so",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.sources]
|
|
23
|
+
src = "/"
|
|
24
|
+
|
|
25
|
+
[tool.hatch.build.targets.sdist]
|
|
26
|
+
packages = ["project"]
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel]
|
|
29
|
+
packages = ["project"]
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build.hooks.hatch-cpp]
|
|
32
|
+
verbose = true
|
|
33
|
+
libraries = [
|
|
34
|
+
{name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"], binding="pybind11"},
|
|
35
|
+
]
|
hatch_cpp/tests/test_projects.py
CHANGED
|
@@ -13,10 +13,14 @@ class TestProject:
|
|
|
13
13
|
[
|
|
14
14
|
"test_project_basic",
|
|
15
15
|
"test_project_override_classes",
|
|
16
|
+
"test_project_override_classes",
|
|
17
|
+
"test_project_override_toolchain",
|
|
16
18
|
"test_project_pybind",
|
|
19
|
+
"test_project_pybind_vcpkg",
|
|
17
20
|
"test_project_nanobind",
|
|
18
21
|
"test_project_limited_api",
|
|
19
22
|
"test_project_cmake",
|
|
23
|
+
"test_project_cmake_vcpkg",
|
|
20
24
|
],
|
|
21
25
|
)
|
|
22
26
|
def test_basic(self, project):
|
|
@@ -29,8 +33,7 @@ class TestProject:
|
|
|
29
33
|
# compile
|
|
30
34
|
check_call(
|
|
31
35
|
[
|
|
32
|
-
"
|
|
33
|
-
"build",
|
|
36
|
+
"hatch-build",
|
|
34
37
|
"--hooks-only",
|
|
35
38
|
],
|
|
36
39
|
cwd=f"hatch_cpp/tests/{project}",
|
hatch_cpp/tests/test_structs.py
CHANGED
|
@@ -5,7 +5,7 @@ import pytest
|
|
|
5
5
|
from pydantic import ValidationError
|
|
6
6
|
from toml import loads
|
|
7
7
|
|
|
8
|
-
from hatch_cpp
|
|
8
|
+
from hatch_cpp import HatchCppBuildConfig, HatchCppBuildPlan, HatchCppLibrary, HatchCppPlatform
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class TestStructs:
|
|
@@ -46,3 +46,11 @@ class TestStructs:
|
|
|
46
46
|
assert f"-DHATCH_CPP_TEST_PROJECT_BASIC_PYTHON_VERSION=3.{version_info.minor}" in hatch_build_plan.commands[0]
|
|
47
47
|
if hatch_build_plan.platform.platform == "darwin":
|
|
48
48
|
assert "-DCMAKE_OSX_DEPLOYMENT_TARGET=11" in hatch_build_plan.commands[0]
|
|
49
|
+
|
|
50
|
+
def test_platform_toolchain_override(self):
|
|
51
|
+
txt = (Path(__file__).parent / "test_project_override_toolchain" / "pyproject.toml").read_text()
|
|
52
|
+
toml = loads(txt)
|
|
53
|
+
hatch_build_config = HatchCppBuildConfig(name=toml["project"]["name"], **toml["tool"]["hatch"]["build"]["hooks"]["hatch-cpp"])
|
|
54
|
+
assert "clang" in hatch_build_config.platform.cc
|
|
55
|
+
assert "clang++" in hatch_build_config.platform.cxx
|
|
56
|
+
assert hatch_build_config.platform.toolchain == "gcc"
|
hatch_cpp/toolchains/__init__.py
CHANGED