Skip to content

Commit

Permalink
Merge pull request #34 from AMYPAD/scikit-build-core
Browse files Browse the repository at this point in the history
scikit build core
  • Loading branch information
casperdcl authored Dec 8, 2023
2 parents 9ee534b + 206318b commit b1df21d
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 117 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/comment-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
if: startsWith(github.event.comment.body, '/tag ')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: React Seen
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
const perm = await github.rest.repos.getCollaboratorPermissionLevel({
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
BODY: ${{ github.event.comment.body }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: React Success
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
post = (context.eventName == "issue_comment"
Expand Down
63 changes: 38 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
if: github.event_name != 'pull_request' || !contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: set PYSHA
Expand Down Expand Up @@ -47,26 +47,32 @@ jobs:
matrix:
python: [3.7, 3.11]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- run: pip install -U -e .[dev]
env:
# https://github.com/scikit-build/scikit-build/issues/740
SETUPTOOLS_ENABLE_FEATURES: legacy-editable
- name: pip install -U -e .[dev]
# in-place for pytest (-e . doesn't work yet for scikit-build-core)
run: |
pip install toml
python -c 'import toml; c=toml.load("pyproject.toml")
print("\0".join(c["build-system"]["requires"] + ["cmake>=" + c["tool"]["scikit-build"]["cmake"]["minimum-version"]]), end="")' \
| xargs -0 pip install ninja
pip install --no-build-isolation --no-deps -t . -U -v . -Ccmake.define.CUVEC_DEBUG=1
git restore cuvec/src
python -c 'import toml; c=toml.load("pyproject.toml")
print("\0".join(c["project"]["dependencies"] + c["project"]["optional-dependencies"]["dev"]), end="")' \
| xargs -0 pip install
- run: pytest
- uses: codecov/codecov-action@v3
- name: compile -Wall
run: |
git clean -Xdf
pip install toml
python -c 'import toml; c=toml.load("pyproject.toml"); print("\0".join(c["build-system"]["requires"]), end="")' \
| xargs -0 pip install
python setup.py build -- -DCUVEC_DEBUG=1 \
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-cast-function-type"
pip install build
python -m build -n -w \
-Ccmake.define.CMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-cast-function-type"
cuda:
if: github.event_name != 'pull_request' || !contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association)
name: CUDA py${{ matrix.python }}
Expand All @@ -75,25 +81,32 @@ jobs:
matrix:
python: [3.7, 3.11]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run setup-python
run: setup-python -p${{ matrix.python }} 'cuda-version<12' cupy
- run: pip install -U -e .[dev]
env:
# https://github.com/scikit-build/scikit-build/issues/740
SETUPTOOLS_ENABLE_FEATURES: legacy-editable
- name: pip install -U -e .[dev]
# in-place for pytest (-e . doesn't work yet for scikit-build-core)
run: |
pip install toml
python -c 'import toml; c=toml.load("pyproject.toml")
print("\0".join(c["build-system"]["requires"] + ["cmake>=" + c["tool"]["scikit-build"]["cmake"]["minimum-version"]]), end="")' \
| xargs -0 pip install ninja
pip install --no-build-isolation --no-deps -t . -U -v . -Ccmake.define.CUVEC_DEBUG=1
git restore cuvec/src
python -c 'import toml; c=toml.load("pyproject.toml")
print("\0".join(c["project"]["dependencies"] + c["project"]["optional-dependencies"]["dev"]), end="")' \
| xargs -0 pip install
- run: pytest
- uses: codecov/codecov-action@v3
- name: compile -Wall
run: |
git clean -Xdf
pip install toml
python -c 'import toml; c=toml.load("pyproject.toml"); print("\0".join(c["build-system"]["requires"]), end="")' \
| xargs -0 pip install
python setup.py build -- -DCUVEC_DEBUG=1 \
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-cast-function-type"
pip install build
python -m build -n -w \
-Ccmake.define.CMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-cast-function-type" \
-Ccmake.define.CMAKE_CUDA_ARCHITECTURES=all
- name: Post Run setup-python
run: setup-python -p${{ matrix.python }} -Dr
if: ${{ always() }}
Expand All @@ -102,11 +115,11 @@ jobs:
name: PyPI Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN || github.token }}
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- id: dist
Expand Down
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
__pycache__/

# build
/MANIFEST.in
/*.egg*/
*.so
/cuvec/cmake/
/cuvec/_dist_ver.py
/build/
/cuvec/cmake/
/cuvec-*.dist-info/
/cuvec/*PYTHON_wrap.cxx
/cuvec/example_swig.py
/cuvec/swvec.py
/dist/
/_skbuild/
/_cmake_test_compile/
/docs/build/

# Unit test / coverage reports
/.coverage*
/coverage.xml
/.pytest_cache/
/.mypy_cache/
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -26,7 +26,7 @@ repos:
types: [text]
exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.1.0
hooks:
- id: flake8
args: [-j8]
Expand All @@ -39,12 +39,12 @@ repos:
- flake8-pyproject
- flake8-string-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
rev: v1.7.1
hooks:
- id: mypy
additional_dependencies: [types-setuptools]
- repo: https://github.com/google/yapf
rev: v0.40.0
rev: v0.40.2
hooks:
- id: yapf
args: [-i]
Expand Down
59 changes: 32 additions & 27 deletions cuvec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
if("${CUVEC_BUILD_VERSION}" STREQUAL "")
set(CUVEC_BUILD_VERSION 2 CACHE STRING "version" FORCE)
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
if(NOT DEFINED SKBUILD_PROJECT_VERSION)
set(SKBUILD_PROJECT_VERSION 2 CACHE STRING "version" FORCE)
endif()
project(cuvec LANGUAGES C CXX VERSION "${CUVEC_BUILD_VERSION}")
string(REGEX REPLACE [[([0-9]+)\.([0-9]+)\.([0-9]+).*]] [[\1.\2.\3]] SKBUILD_PROJECT_VERSION "${SKBUILD_PROJECT_VERSION}")
project(cuvec LANGUAGES C CXX VERSION "${SKBUILD_PROJECT_VERSION}")

option(CUVEC_CUDA_OPTIONAL "Make CUDA optional rather than forced" ON)

cmake_policy(PUSH)
cmake_policy(SET CMP0074 NEW) # <PackageName>_ROOT hints for find_package
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES native CACHE STRING "CUDA arch" FORCE)
endif()
cmake_policy(SET CMP0104 NEW) # CMAKE_CUDA_ARCHITECTURES
find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED) # NumPy
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) # NumPy
if(NOT CUVEC_CUDA_OPTIONAL)
find_package(CUDAToolkit REQUIRED)
enable_language(CUDA)
Expand All @@ -27,22 +31,17 @@ else()
endif()
endif()
if(SKBUILD)
find_package(PythonExtensions REQUIRED)
set(LIB_TYPE "MODULE")

find_package(SWIG 3.0 COMPONENTS python)
find_package(SWIG 4.0)
if(SWIG_FOUND)
include(${SWIG_USE_FILE})
set(${CMAKE_PROJECT_NAME}_SWIG_SRC "${CMAKE_CURRENT_LIST_DIR}/include/${CMAKE_PROJECT_NAME}.i")
set_source_files_properties("${${CMAKE_PROJECT_NAME}_SWIG_SRC}" PROPERTIES CPLUSPLUS ON)
include(${SWIG_USE_FILE})
set(${CMAKE_PROJECT_NAME}_SWIG_SRC "${CMAKE_CURRENT_LIST_DIR}/include/${CMAKE_PROJECT_NAME}.i")
set_source_files_properties("${${CMAKE_PROJECT_NAME}_SWIG_SRC}" PROPERTIES CPLUSPLUS ON)
endif()
else()
set(LIB_TYPE "SHARED")
endif()
cmake_policy(POP)

message(STATUS "CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
Expand All @@ -61,27 +60,25 @@ install(DIRECTORY "${${CMAKE_PROJECT_NAME}_INCLUDE_DIRS}" DESTINATION ${CMAKE_PR
file(GLOB SRC LIST_DIRECTORIES false "src/*.cu")
include_directories(src)
include_directories(${Python3_INCLUDE_DIRS})
#include_directories(${Python3_NumPy_INCLUDE_DIRS})

add_library(${PROJECT_NAME} SHARED ${SRC})
if(SKBUILD)
python_add_library(${PROJECT_NAME} MODULE WITH_SOABI ${SRC})
else()
add_library(${PROJECT_NAME} SHARED ${SRC})
endif()
add_library(AMYPAD::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${${CMAKE_PROJECT_NAME}_INCLUDE_DIRS}>"
"$<INSTALL_INTERFACE:${CMAKE_PROJECT_NAME}/include>")
if(CUDAToolkit_FOUND)
target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES} CUDA::cudart_static)
target_link_libraries(${PROJECT_NAME} PRIVATE CUDA::cudart_static)
else()
set_source_files_properties(${SRC} PROPERTIES LANGUAGE CXX)
target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES})
endif()

if(SKBUILD)
python_extension_module(${PROJECT_NAME})
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 11
#VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
PREFIX "" # remove shared lib prefix to make importable
VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR})
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION)
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets
Expand All @@ -98,14 +95,22 @@ if(SWIG_FOUND AND SKBUILD)
endif()
set_source_files_properties(src/swvec.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(src/swvec.i PROPERTIES USE_TARGET_INCLUDE_DIRECTORIES ON)
swig_add_library(swvec LANGUAGE python SOURCES src/swvec.i)
swig_add_library(swvec LANGUAGE python
OUTPUT_DIR "${SKBUILD_PLATLIB_DIR}/${CMAKE_PROJECT_NAME}"
SOURCES src/swvec.i)
if(WIN32)
set_property(TARGET swvec PROPERTY SUFFIX ".${Python_SOABI}.pyd")
else()
set_property(TARGET swvec PROPERTY SUFFIX ".${Python_SOABI}${CMAKE_SHARED_MODULE_SUFFIX}")
endif()
if(CUDAToolkit_FOUND)
swig_link_libraries(swvec CUDA::cudart_static)
target_link_libraries(swvec PRIVATE Python::Module CUDA::cudart_static)
else()
target_link_libraries(swvec PRIVATE Python::Module)
endif()
target_include_directories(swvec PUBLIC
"$<BUILD_INTERFACE:${${CMAKE_PROJECT_NAME}_INCLUDE_DIRS}>"
"$<INSTALL_INTERFACE:${CMAKE_PROJECT_NAME}/include>")
python_extension_module(swvec)
set_target_properties(swvec PROPERTIES
CXX_STANDARD 11
VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
Expand Down
13 changes: 6 additions & 7 deletions cuvec/src/example_mod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ project(example_mod)
file(GLOB SRC LIST_DIRECTORIES false "*.cu")

include_directories(${Python3_INCLUDE_DIRS})
#include_directories(${Python3_NumPy_INCLUDE_DIRS})

add_library(${PROJECT_NAME} MODULE ${SRC})
if(SKBUILD)
python_add_library(${PROJECT_NAME} MODULE WITH_SOABI ${SRC})
else()
add_library(${PROJECT_NAME} MODULE ${SRC})
endif()
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${${CMAKE_PROJECT_NAME}_INCLUDE_DIRS}>"
"$<INSTALL_INTERFACE:${CMAKE_PROJECT_NAME}/include>")
if(CUDAToolkit_FOUND)
target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES} CUDA::cudart_static)
target_link_libraries(${PROJECT_NAME} PRIVATE CUDA::cudart_static)
else()
set_source_files_properties(${SRC} PROPERTIES LANGUAGE CXX)
target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES})
endif()

if(SKBUILD)
python_extension_module(${PROJECT_NAME})
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 11
VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
Expand Down
16 changes: 10 additions & 6 deletions cuvec/src/example_swig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ file(GLOB SRC LIST_DIRECTORIES false "*.cu")
file(GLOB ISRC LIST_DIRECTORIES false "*.i")

#include_directories(${Python3_INCLUDE_DIRS})
#include_directories(${Python3_NumPy_INCLUDE_DIRS})

if(SWIG_FOUND)
if(CUDAToolkit_FOUND)
include_directories(${CUDAToolkit_INCLUDE_DIRS})
endif()
set_source_files_properties(${PROJECT_NAME}.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(${PROJECT_NAME}.i PROPERTIES USE_TARGET_INCLUDE_DIRECTORIES ON)
swig_add_library(${PROJECT_NAME} LANGUAGE python SOURCES ${ISRC} ${SRC})
swig_add_library(${PROJECT_NAME} LANGUAGE python
OUTPUT_DIR "${SKBUILD_PLATLIB_DIR}/${CMAKE_PROJECT_NAME}"
SOURCES ${ISRC} ${SRC})
if(WIN32)
set_property(TARGET ${PROJECT_NAME} PROPERTY SUFFIX ".${Python_SOABI}.pyd")
else()
set_property(TARGET ${PROJECT_NAME} PROPERTY SUFFIX ".${Python_SOABI}${CMAKE_SHARED_MODULE_SUFFIX}")
endif()
if(CUDAToolkit_FOUND)
swig_link_libraries(${PROJECT_NAME} CUDA::cudart_static)
target_link_libraries(${PROJECT_NAME} PRIVATE Python::Module CUDA::cudart_static)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE Python::Module)
set_source_files_properties(${SRC} PROPERTIES LANGUAGE CXX)
endif()
else()
Expand All @@ -29,9 +36,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${${CMAKE_PROJECT_NAME}_INCLUDE_DIRS}>"
"$<INSTALL_INTERFACE:${CMAKE_PROJECT_NAME}/include>")

if(SKBUILD AND SWIG_FOUND)
python_extension_module(${PROJECT_NAME})
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 11
VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
Expand Down
Loading

0 comments on commit b1df21d

Please sign in to comment.