Skip to content

Commit

Permalink
add scikit build core config to build Python wheel file
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewprock committed Sep 25, 2024
1 parent 1d9ca41 commit d67da05
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*~
build
_build
dist
*.pyc
*.vscode
*.swp
Expand Down
24 changes: 13 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
cmake_minimum_required(VERSION 3.5)

project(pokerstove)
project(
pokerstove
VERSION "1.2"
LANGUAGES CXX)

# TODO: This flags only works for GCC compatible compilers (Clang, Intel).
# TODO: This, ideally, should be per library requirement,
# but since all of them require C++11, the flag is set globally.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
#include(GNUInstallDirs)

# TODO: Remove the deprecated register keywords
# set up some global compiler opions
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register")

# Set up gtest. This must be set up before any subdirectories are
# added which will use gtest.
# TODO: clean this up a bit, maybe make this optional?
add_subdirectory(src/ext/googletest)
include_directories(${GTEST_INCLUDE_DIRS})
link_directories(${GTEST_LIBS_DIR})
Expand Down Expand Up @@ -45,8 +47,8 @@ add_subdirectory(src/lib)
add_subdirectory(src/programs)

# Add make install functionality
install(TARGETS peval)
install(TARGETS penum)
install(TARGETS ps-colex)
install(TARGETS ps-eval)
install(TARGETS ps-lut)
#install(TARGETS peval)
#install(TARGETS penum)
#install(TARGETS ps-colex)
#install(TARGETS ps-eval)
#install(TARGETS ps-lut)
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ If you would like to also build the Python library as well, append the
directive when the first cmake invocation is run:

cmake -DCMAKE_BUILD_TYPE=Release -S \. -B build -DBUILD_PYTHON=ON
cmake --build build --target all test -j 16

Once you have built the project with Python support there will be a
python loader file and a shared object file. To test run the script
Expand All @@ -168,6 +169,19 @@ shell:

export PYTHONPATH=~/git/pokerstove/build/python/pokerstove/

## Python wheel package

There is also a `pyproject.toml` file which can be used to create an
installable wheel for the pythong package. The commands below can be
used to build/install/verify the package.

pipx run build
python3 -m venv venv
. venv/bin/activate
pip install dist/pokerstove-1.2-cp310-cp310-linux_x86_64.whl
python src/lib/python/test-python
deactivate

# Breaking changes

Version 1.2 will migrate from boost::shared_ptr to std::shared_ptr, breaking API compatibility.
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[build-system]
requires = ["scikit-build-core", "swig"]
build-backend = "scikit_build_core.build"

[project]
name = "pokerstove"
version = "1.2"

[tool.scikit-build]
build-dir = "_build"
wheel.packages = ["_build/python/pokerstove"]
cmake.version = ">=3.5"
cmake.build-type = "Release"
build.targets = ["pokerstove"]
install.components = ["pokerstove"]
# build.verbose = true
# logging.level = "DEBUG"

[tool.scikit-build.cmake.define]
BUILD_PYTHON = "ON"

5 changes: 4 additions & 1 deletion src/lib/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if(UNIX AND NOT APPLE)
list(APPEND CMAKE_SWIG_FLAGS "-DSWIGWORDSIZE64")
endif()
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
list(APPEND CMAKE_SWIG_FLAGS "-py3" "-DPY3")
list(APPEND CMAKE_SWIG_FLAGS "-DPY3")

### wrapping code below

Expand Down Expand Up @@ -47,6 +47,9 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/python/${PYTHON_PROJECT})
message(STATUS "PYTHON_PROJECT ${PYTHON_PROJECT_DIR}")
message(STATUS "swig_add_library OUTPUT_DIR ${PYTHON_PROJECT_DIR}/${PS_TARGET}")

file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/__init__.py
CONTENT "__version__ = \"${PROJECT_VERSION}\"\nfrom .pokerstove import *\n")

# This file is nested within the library source dir, so
# look to the parent directory for the include files. The
# python includes should be in the standard place.
Expand Down

0 comments on commit d67da05

Please sign in to comment.