Skip to content

Commit

Permalink
CI: setup cibuildwheel (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Jinzhe Zeng <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
njzjz and pre-commit-ci[bot] authored Nov 21, 2024
1 parent d0b3209 commit 0d51c62
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 3 deletions.
47 changes: 46 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,49 @@ jobs:
with:
name: release-dists
path: dist/
release-wheel:
name: Build wheels for cp${{ matrix.python }}-${{ matrix.platform_id }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# linux-64
- os: ubuntu-latest
python: 312
platform_id: manylinux_x86_64
# macos-x86-64
- os: macos-13
python: 312
platform_id: macosx_x86_64
# macos-arm64
- os: macos-14
python: 312
platform_id: macosx_arm64
# win-64
- os: windows-2019
python: 312
platform_id: win_amd64
steps:
- uses: actions/checkout@v4
- name: Set up uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: |
**/requirements*.txt
**/pyproject.toml
if: runner.os != 'Linux'
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS: all
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_BUILD_FRONTEND: "build[uv]"
- uses: actions/upload-artifact@v4
with:
name: release-cibw-cp${{ matrix.python }}-${{ matrix.platform_id }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl
pypi-publish:
name: Release to pypi
runs-on: ubuntu-latest
Expand All @@ -37,13 +80,15 @@ jobs:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs:
- release-build
- release-wheel
permissions:
id-token: write
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: release-dists
merge-multiple: true
pattern: release-*
path: dist/
- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ endif()
if(BUILD_CPP_IF
AND USE_PT_PYTHON_LIBS
AND NOT CMAKE_CROSSCOMPILING
AND NOT SKBUILD)
AND NOT SKBUILD
OR "$ENV{CIBUILDWHEEL}" STREQUAL "1")
find_package(
Python
COMPONENTS Interpreter
Expand Down
1 change: 1 addition & 0 deletions build_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Customized PEP-517 build backend."""
48 changes: 48 additions & 0 deletions build_backend/dp_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""A PEP-517 backend to add customized dependencies."""

import os

from scikit_build_core import build as _orig

__all__ = [
"build_sdist",
"build_wheel",
"get_requires_for_build_sdist",
"get_requires_for_build_wheel",
"prepare_metadata_for_build_wheel",
"prepare_metadata_for_build_editable",
"build_editable",
"get_requires_for_build_editable",
]


def __dir__() -> list[str]:
return __all__


prepare_metadata_for_build_wheel = _orig.prepare_metadata_for_build_wheel
build_wheel = _orig.build_wheel
build_sdist = _orig.build_sdist
get_requires_for_build_sdist = _orig.get_requires_for_build_sdist
prepare_metadata_for_build_editable = _orig.prepare_metadata_for_build_editable
build_editable = _orig.build_editable
get_requires_for_build_editable = _orig.get_requires_for_build_editable


def cibuildwheel_dependencies() -> list[str]:
if os.environ.get("CIBUILDWHEEL", "0") == "1":
return [
"deepmd-kit[torch]>=3.0.0b2",
]
return []


def get_requires_for_build_wheel(
config_settings: dict,
) -> list[str]:
"""Return the dependencies for building a wheel."""
return (
_orig.get_requires_for_build_wheel(config_settings)
+ cibuildwheel_dependencies()
)
26 changes: 25 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
requires = [
"scikit-build-core>=0.3.0",
]
build-backend = "scikit_build_core.build"
build-backend = "build_backend.dp_backend"
backend-path = ["."]

[project]
name = "deepmd-gnn"
Expand Down Expand Up @@ -98,3 +99,26 @@ convention = "numpy"

[tool.coverage.report]
include = ["deepmd_gnn/*"]


[tool.cibuildwheel]
test-command = [
"""python -c "import deepmd_gnn.op" """,
]
build = ["cp312-*"]
skip = ["*-win32", "*-manylinux_i686", "*-musllinux*"]
manylinux-x86_64-image = "manylinux_2_28"

[tool.cibuildwheel.macos]
repair-wheel-command = """delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} --ignore-missing-dependencies"""

[tool.cibuildwheel.linux]
repair-wheel-command = "auditwheel repair --exclude libc10.so --exclude libtorch.so --exclude libtorch_cpu.so -w {dest_dir} {wheel}"
environment-pass = [
"CIBW_BUILD",
]
[tool.cibuildwheel.linux.environment]
# use CPU version of torch for building, which should also work for GPU
# note: uv has different behavior from pip on extra index url
# https://github.com/astral-sh/uv/blob/main/PIP_COMPATIBILITY.md#packages-that-exist-on-multiple-indexes
UV_EXTRA_INDEX_URL = "https://download.pytorch.org/whl/cpu"

0 comments on commit 0d51c62

Please sign in to comment.