Skip to content

Commit 0d9a024

Browse files
author
zacharyburnett
committed
attempt to use cibuildwheel to build library port
1 parent 0c173d8 commit 0d9a024

File tree

3 files changed

+99
-39
lines changed

3 files changed

+99
-39
lines changed

.github/workflows/build.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,19 @@ jobs:
3939
working-directory: build/
4040
- run: sudo cmake --build . --parallel --target=install
4141
working-directory: build/
42+
cibuildwheel:
43+
strategy:
44+
matrix:
45+
# macos-13 is an intel runner, macos-14 is apple silicon
46+
os:
47+
- ubuntu-latest
48+
- macos-13
49+
- macos-latest
50+
runs-on: ${{ matrix.os }}
51+
steps:
52+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
53+
- uses: pypa/[email protected]
54+
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
55+
with:
56+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
57+
path: ./wheelhouse/*.whl

pyproject.toml

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22
name = "s2geometry"
33
description = "Computational geometry and spatial indexing on the sphere"
44
authors = [
5-
{ name = "Dan Larkin-York", email = "[email protected]" },
6-
{ name = "Eric Veach", email = "[email protected]" },
7-
{ name = "Jesse Rosenstock", email = "[email protected]" },
8-
{ name = "Julien Basch", email = "[email protected]" },
9-
{ name = "Mike Playle", email = "[email protected]" },
10-
{ name = "Phil Elson", email = "[email protected]" },
11-
{ name = "Robert Coup", email = "[email protected]" },
12-
{ name = "Tiago Brito", email = "[email protected]" },
13-
{ name = "Zachary Burnett", email = "[email protected]" },
5+
{ name = "Dan Larkin-York", email = "[email protected]" },
6+
{ name = "Eric Veach", email = "[email protected]" },
7+
{ name = "Jesse Rosenstock", email = "[email protected]" },
8+
{ name = "Julien Basch", email = "[email protected]" },
9+
{ name = "Mike Playle", email = "[email protected]" },
10+
{ name = "Phil Elson", email = "[email protected]" },
11+
{ name = "Robert Coup", email = "[email protected]" },
12+
{ name = "Tiago Brito", email = "[email protected]" },
13+
{ name = "Zachary Burnett", email = "[email protected]" },
1414
]
1515
requires-python = ">=3.7"
1616
classifiers = [
17-
"Programming Language :: Python :: 3",
18-
"Operating System :: POSIX",
19-
"License :: OSI Approved :: Apache Software License",
20-
]
21-
dynamic = [
22-
"version",
17+
"Programming Language :: Python :: 3",
18+
"Operating System :: POSIX",
19+
"License :: OSI Approved :: Apache Software License",
2320
]
21+
dynamic = ["version"]
2422

2523
[project.license]
2624
file = "LICENSE"
@@ -30,16 +28,15 @@ content-type = "text/plain"
3028
Source = "https://github.com/google/s2geometry"
3129

3230
[project.optional-dependencies]
33-
test = [
34-
"pytest",
35-
]
31+
test = ["pytest"]
3632

3733
[build-system]
3834
requires = [
39-
"wheel",
40-
"setuptools",
41-
"setuptools_scm[toml]",
42-
"cmake_build_extension",
35+
"wheel",
36+
"setuptools",
37+
"setuptools_scm[toml]",
38+
"cmake_build_extension",
39+
"swig",
4340
]
4441
build-backend = "setuptools.build_meta"
4542

@@ -48,11 +45,53 @@ zip-safe = false
4845
include-package-data = false
4946

5047
[tool.setuptools.packages.find]
51-
where = [
52-
"src",
53-
]
48+
where = ["src"]
5449
namespaces = false
5550

5651
[tool.setuptools.package-dir]
5752
"" = "src"
5853

54+
[tool.cibuildwheel]
55+
# manylinux-x86_64-image = "quay.io/pypa/manylinux2014_x86_64"
56+
build-frontend = "build[uv]"
57+
build = "cp3*-manylinux_x86_64 cp3*-macosx_x86_64 cp3*-macosx_arm64"
58+
# test-requires = "pytest"
59+
# test-command = "pytest {project}/src/python/"
60+
61+
[tool.cibuildwheel.environment]
62+
MACOSX_DEPLOYMENT_TARGET = 14.0
63+
64+
[tool.cibuildwheel.linux]
65+
# repair-wheel-command = ""
66+
# the EPEL9 package `abseil-cpp` is out of date, so we have to build `abseil-cpp` from source
67+
before-all = """
68+
yum install -y gflags-devel glog-devel gtest-devel openssl-devel
69+
git clone https://github.com/abseil/abseil-cpp.git && cd ./abseil-cpp
70+
git checkout 20240116.2
71+
mkdir ./build && cd ./build
72+
cmake -DCMAKE_CXX_STANDARD=17 -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON -DBUILD_TESTING=off ..
73+
cmake --build . --parallel --target=install
74+
"""
75+
76+
[tool.cibuildwheel.macos]
77+
before-all = """
78+
git clone https://github.com/gflags/gflags.git && cd ./gflags
79+
mkdir ./build && cd ./build
80+
cmake .. -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF
81+
cmake --build . --parallel --target install
82+
cd ../../
83+
git clone https://github.com/google/glog.git && cd ./glog
84+
cmake -S . -B ./build && cd ./build
85+
cmake --build . --parallel --target install
86+
cd ../../
87+
git clone https://github.com/openssl/openssl.git && cd ./openssl
88+
mkdir ./build && cd ./build
89+
../Configure install
90+
cmake --build . --parallel --target install
91+
cd ../../
92+
git clone https://github.com/abseil/abseil-cpp.git && cd ./abseil-cpp
93+
git checkout 20240116.2
94+
mkdir ./build && cd ./build
95+
cmake -DCMAKE_CXX_STANDARD=17 -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON -DBUILD_TESTING=off ..
96+
cmake --build . --parallel --target=install
97+
"""

setup.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
1+
import os
12
import sys
23
from pathlib import Path
34

45
import cmake_build_extension
56
import setuptools
67

8+
# Extra options passed to the CI/CD pipeline that uses cibuildwheel
9+
CIBW_CMAKE_OPTIONS = []
10+
if "CIBUILDWHEEL" in os.environ and os.environ["CIBUILDWHEEL"] == "1":
11+
# The manylinux variant runs in Debian Stretch and it uses lib64 folder
12+
if sys.platform == "linux":
13+
CIBW_CMAKE_OPTIONS += ["-DCMAKE_INSTALL_LIBDIR=lib"]
714

815
setuptools.setup(
916
ext_modules=[
1017
cmake_build_extension.CMakeExtension(
11-
# This could be anything you like, it is used to create build folders
12-
name="SwigBindings",
13-
# Name of the resulting package name (import s2geometry)
18+
name="s2geometry",
1419
install_prefix="s2geometry",
15-
# Selects the folder where the main CMakeLists.txt is stored
16-
# (it could be a subfolder)
1720
source_dir=str(Path(__file__).parent.absolute()),
1821
cmake_configure_options=[
19-
# This option points CMake to the right Python interpreter, and helps
20-
# the logic of FindPython3.cmake to find the active version
21-
f"-DPython3_ROOT_DIR={Path(sys.prefix)}",
22-
'-DCALL_FROM_SETUP_PY:BOOL=ON',
23-
'-DBUILD_SHARED_LIBS:BOOL=OFF',
24-
'-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
25-
'-DWITH_PYTHON=ON'
26-
]
22+
# This option points CMake to the right Python interpreter, and helps
23+
# the logic of FindPython3.cmake to find the active version
24+
# f"-DPython3_ROOT_DIR={Path(sys.prefix)}",
25+
"-DCALL_FROM_SETUP_PY:BOOL=ON",
26+
"-DBUILD_SHARED_LIBS:BOOL=OFF",
27+
"-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON",
28+
"-DWITH_PYTHON:BOOL=ON",
29+
"-DBUILD_TESTS:BOOL=OFF",
30+
]
31+
+ CIBW_CMAKE_OPTIONS,
2732
)
2833
],
2934
cmdclass=dict(
30-
# Enable the CMakeExtension entries defined above
3135
build_ext=cmake_build_extension.BuildExtension,
36+
sdist=cmake_build_extension.GitSdistFolder,
3237
),
3338
)

0 commit comments

Comments
 (0)