Browse Source

feat: support python package building

master
Dnomd343 1 month ago
parent
commit
a211d49d04
  1. 2
      CMakeLists.txt
  2. 9
      src/CMakeLists.txt
  3. 2
      src/core/CMakeLists.txt
  4. 2
      src/core_ffi/py_ffi/CMakeLists.txt
  5. 2
      src/core_ffi/py_ffi/klotski.cc
  6. 7
      src/core_ffi/py_ffi/packing/CMakeLists.txt
  7. 8
      src/core_ffi/py_ffi/packing/MANIFEST.in
  8. 1
      src/core_ffi/py_ffi/packing/README.md
  9. 8
      src/core_ffi/py_ffi/packing/pyproject.toml
  10. 13
      src/core_ffi/py_ffi/packing/setup.py
  11. 3
      src/core_ffi/py_ffi/packing/src/klotski/__init__.py
  12. 1
      src/core_ffi/py_ffi/packing/src/project

2
CMakeLists.txt

@ -24,7 +24,7 @@ add_compile_options(-Wall -Wextra)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-flto=full)
else ()
add_compile_options(-flto) # TODO: only for g++
#add_compile_options(-flto) # TODO: only for g++
endif ()
# TODO: for python-ffi

9
src/CMakeLists.txt

@ -2,13 +2,10 @@ cmake_minimum_required(VERSION 3.12)
add_subdirectory(core)
add_subdirectory(core_ffi)
if (KLSK_ENABLE_TESTING)
add_subdirectory(core_test)
endif()
#project(klotski-cli LANGUAGES C)
#set(CMAKE_C_STANDARD 90)
#add_executable(klotski_cli main.c)
#target_link_libraries(klotski_cli PRIVATE klotski-core)
#target_link_libraries(klotski_cli PRIVATE klotski absl::flat_hash_map)
# -labsl_hash -labsl_city -labsl_low_level_hash -labsl_raw_hash_set

2
src/core/CMakeLists.txt

@ -41,6 +41,7 @@ add_library(klotski::core ALIAS klotski_core)
add_executable(klotski_core_bin main.cc)
target_link_libraries(klotski_core_bin PRIVATE klotski_core)
if (KLSK_ENABLE_BENCHMARK)
set(KLSK_BENCHMARK_OPTS -fno-rtti -fno-exceptions -fno-access-control)
set(KLSK_BENCHMARK_LIBS klotski::core benchmark::benchmark_main bs::thread_pool)
@ -67,3 +68,4 @@ target_link_libraries(bm_klsk_utility PRIVATE ${KLSK_BENCHMARK_LIBS})
add_executable(bm_klsk_fast_cal benchmark/fast_cal.cc)
target_compile_options(bm_klsk_fast_cal PRIVATE ${KLSK_BENCHMARK_OPTS})
target_link_libraries(bm_klsk_fast_cal PRIVATE ${KLSK_BENCHMARK_LIBS})
endif()

2
src/core_ffi/py_ffi/CMakeLists.txt

@ -22,4 +22,4 @@ pybind11_add_module(klotski_py
)
target_include_directories(klotski_py PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(klotski_py PRIVATE klotski::core)
set_target_properties(klotski_py PROPERTIES OUTPUT_NAME klotski)
set_target_properties(klotski_py PROPERTIES OUTPUT_NAME _klotski)

2
src/core_ffi/py_ffi/klotski.cc

@ -28,7 +28,7 @@ using klotski::ffi::PyExc_GroupError;
// return PyCases::from_ref(klotski::cases::AllCases::instance().fetch());
// }
PYBIND11_MODULE(klotski, m) {
PYBIND11_MODULE(_klotski, m) {
py::register_exception<PyExc_GroupError>(m, "GroupError", PyExc_ValueError);
py::register_exception<PyExc_CodecError>(m, "CodecError", PyExc_ValueError);

7
src/core_ffi/py_ffi/packing/CMakeLists.txt

@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.12)
project(klotski_py_demo VERSION "0.0.1")
add_subdirectory(src/project)
install(TARGETS klotski_py DESTINATION .)

8
src/core_ffi/py_ffi/packing/MANIFEST.in

@ -0,0 +1,8 @@
include CMakeLists.txt
include README.md
include pyproject.toml
include setup.py
include src/klotski/__init__.py
recursive-include src/project *
recursive-exclude src/project/src/core_ffi/py_ffi/packing *
exclude MANIFEST.in

1
src/core_ffi/py_ffi/packing/README.md

@ -0,0 +1 @@
# klotski python ffi

8
src/core_ffi/py_ffi/packing/pyproject.toml

@ -0,0 +1,8 @@
[build-system]
requires = [
"setuptools",
"scikit-build>=0.13",
"cmake",
"ninja",
]
build-backend = "setuptools.build_meta"

13
src/core_ffi/py_ffi/packing/setup.py

@ -0,0 +1,13 @@
from skbuild import setup
setup(
name="py-klotski",
version="0.0.1",
description="klotski engine",
author="Dnomd343",
license="MIT",
packages=["klotski"],
package_dir={"": "src"},
cmake_install_dir="src/klotski",
python_requires=">=3.9",
)

3
src/core_ffi/py_ffi/packing/src/klotski/__init__.py

@ -0,0 +1,3 @@
from ._klotski import Cases, CommonCode, FastCal, Group, GroupUnion, ShortCode
__all__ = ["Cases", "CommonCode", "FastCal", "Group", "GroupUnion", "ShortCode"]

1
src/core_ffi/py_ffi/packing/src/project

@ -0,0 +1 @@
../../../../../../klotski/
Loading…
Cancel
Save