diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 356609c8..a5c6051f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,3 +39,19 @@ jobs: working-directory: build/ - run: sudo cmake --build . --parallel --target=install working-directory: build/ + cibuildwheel: + strategy: + matrix: + # macos-13 is an intel runner, macos-14 is apple silicon + os: + - ubuntu-latest + - macos-13 + - macos-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: pypa/cibuildwheel@v2.22.0 + - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 + with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} + path: ./wheelhouse/*.whl diff --git a/pyproject.toml b/pyproject.toml index 6a55b8c3..5fe12a17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,25 +2,23 @@ name = "s2geometry" description = "Computational geometry and spatial indexing on the sphere" authors = [ - { name = "Dan Larkin-York", email = "dan@arangodb.com" }, - { name = "Eric Veach", email = "ericv@google.com" }, - { name = "Jesse Rosenstock", email = "jmr@google.com" }, - { name = "Julien Basch", email = "julienbasch@google.com" }, - { name = "Mike Playle", email = "mike@mythik.co.uk" }, - { name = "Phil Elson", email = "pelson.pub@gmail.com" }, - { name = "Robert Coup", email = "robert.coup@koordinates.com" }, - { name = "Tiago Brito", email = "tiago.brito@90poe.io" }, - { name = "Zachary Burnett", email = "zachary.r.burnett@gmail.com" }, + { name = "Dan Larkin-York", email = "dan@arangodb.com" }, + { name = "Eric Veach", email = "ericv@google.com" }, + { name = "Jesse Rosenstock", email = "jmr@google.com" }, + { name = "Julien Basch", email = "julienbasch@google.com" }, + { name = "Mike Playle", email = "mike@mythik.co.uk" }, + { name = "Phil Elson", email = "pelson.pub@gmail.com" }, + { name = "Robert Coup", email = "robert.coup@koordinates.com" }, + { name = "Tiago Brito", email = "tiago.brito@90poe.io" }, + { name = "Zachary Burnett", email = "zachary.r.burnett@gmail.com" }, ] requires-python = ">=3.7" classifiers = [ - "Programming Language :: Python :: 3", - "Operating System :: POSIX", - "License :: OSI Approved :: Apache Software License", -] -dynamic = [ - "version", + "Programming Language :: Python :: 3", + "Operating System :: POSIX", + "License :: OSI Approved :: Apache Software License", ] +dynamic = ["version"] [project.license] file = "LICENSE" @@ -30,16 +28,15 @@ content-type = "text/plain" Source = "https://github.com/google/s2geometry" [project.optional-dependencies] -test = [ - "pytest", -] +test = ["pytest"] [build-system] requires = [ - "wheel", - "setuptools", - "setuptools_scm[toml]", - "cmake_build_extension", + "wheel", + "setuptools", + "setuptools_scm[toml]", + "cmake_build_extension", + "swig", ] build-backend = "setuptools.build_meta" @@ -48,11 +45,53 @@ zip-safe = false include-package-data = false [tool.setuptools.packages.find] -where = [ - "src", -] +where = ["src"] namespaces = false [tool.setuptools.package-dir] "" = "src" +[tool.cibuildwheel] +# manylinux-x86_64-image = "quay.io/pypa/manylinux2014_x86_64" +build-frontend = "build[uv]" +build = "cp3*-manylinux_x86_64 cp3*-macosx_x86_64 cp3*-macosx_arm64" +# test-requires = "pytest" +# test-command = "pytest {project}/src/python/" + +[tool.cibuildwheel.environment] +MACOSX_DEPLOYMENT_TARGET = 14.0 + +[tool.cibuildwheel.linux] +# repair-wheel-command = "" +# the EPEL9 package `abseil-cpp` is out of date, so we have to build `abseil-cpp` from source +before-all = """ +yum install -y gflags-devel glog-devel gtest-devel openssl-devel +git clone https://github.com/abseil/abseil-cpp.git && cd ./abseil-cpp +git checkout 20240116.2 +mkdir ./build && cd ./build +cmake -DCMAKE_CXX_STANDARD=17 -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON -DBUILD_TESTING=off .. +cmake --build . --parallel --target=install +""" + +[tool.cibuildwheel.macos] +before-all = """ +git clone https://github.com/gflags/gflags.git && cd ./gflags +mkdir ./build && cd ./build +cmake .. -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF +cmake --build . --parallel --target install +cd ../../ +git clone https://github.com/google/glog.git && cd ./glog +cmake -S . -B ./build && cd ./build +cmake --build . --parallel --target install +cd ../../ +git clone https://github.com/openssl/openssl.git && cd ./openssl +mkdir ./build && cd ./build +../Configure install +cmake --build . --parallel --target install +cd ../../ +git clone https://github.com/abseil/abseil-cpp.git && cd ./abseil-cpp +git checkout 20240116.2 +mkdir ./build && cd ./build +cmake -DCMAKE_CXX_STANDARD=17 -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON -DBUILD_TESTING=off .. +cmake --build . --parallel --target=install +""" diff --git a/setup.py b/setup.py index 242882ab..388ad49e 100644 --- a/setup.py +++ b/setup.py @@ -1,33 +1,38 @@ +import os import sys from pathlib import Path import cmake_build_extension import setuptools +# Extra options passed to the CI/CD pipeline that uses cibuildwheel +CIBW_CMAKE_OPTIONS = [] +if "CIBUILDWHEEL" in os.environ and os.environ["CIBUILDWHEEL"] == "1": + # The manylinux variant runs in Debian Stretch and it uses lib64 folder + if sys.platform == "linux": + CIBW_CMAKE_OPTIONS += ["-DCMAKE_INSTALL_LIBDIR=lib"] setuptools.setup( ext_modules=[ cmake_build_extension.CMakeExtension( - # This could be anything you like, it is used to create build folders - name="SwigBindings", - # Name of the resulting package name (import s2geometry) + name="s2geometry", install_prefix="s2geometry", - # Selects the folder where the main CMakeLists.txt is stored - # (it could be a subfolder) source_dir=str(Path(__file__).parent.absolute()), cmake_configure_options=[ - # This option points CMake to the right Python interpreter, and helps - # the logic of FindPython3.cmake to find the active version - f"-DPython3_ROOT_DIR={Path(sys.prefix)}", - '-DCALL_FROM_SETUP_PY:BOOL=ON', - '-DBUILD_SHARED_LIBS:BOOL=OFF', - '-DCMAKE_POSITION_INDEPENDENT_CODE=ON', - '-DWITH_PYTHON=ON' - ] + # This option points CMake to the right Python interpreter, and helps + # the logic of FindPython3.cmake to find the active version + # f"-DPython3_ROOT_DIR={Path(sys.prefix)}", + "-DCALL_FROM_SETUP_PY:BOOL=ON", + "-DBUILD_SHARED_LIBS:BOOL=OFF", + "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON", + "-DWITH_PYTHON:BOOL=ON", + "-DBUILD_TESTS:BOOL=OFF", + ] + + CIBW_CMAKE_OPTIONS, ) ], cmdclass=dict( - # Enable the CMakeExtension entries defined above build_ext=cmake_build_extension.BuildExtension, + sdist=cmake_build_extension.GitSdistFolder, ), )