Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try building wheels with CI for pdffit2 #93

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
93 changes: 93 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Wheel builder

on:
# workflow_call:
# inputs:
# project:
# description: 'Name of the project to test'
# default: 'PROJECT_NAME'
# required: false
# type: string
# c_extension:
# description: 'Whether the project has a C extension'
# default: false
# required: false
# type: boolean
pull_request:
workflow_dispatch:

jobs:
build_wheels:

defaults:
run:
shell: bash -l {0}

name: Build wheel ${{ matrix.python[0] }}-${{ matrix.buildplat[0] }}
runs-on: ${{ matrix.buildplat[0] }}
strategy:
fail-fast: false
matrix:
buildplat:
- [ubuntu-latest, manylinux_x86_64]
- [macos-13, macosx_x86_64]
- [macos-14, macosx_arm64]
- [windows-latest, win_amd64]
python:
- ["3.10", "cp310"]
- ["3.11", "cp311"]
- ["3.12", "cp312"]

steps:
- name: Check out #${{ inputs.project }}
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python[0] }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python[0] }}

- name: Build wheels for Linux
if: runner.os == 'Linux'
uses: pypa/[email protected]
env:
CIBW_BUILD: ${{ matrix.python[1] }}-${{ matrix.buildplat[1] }}
CIBW_BEFORE_BUILD: yum install -y gsl-devel && pip install -e .
with:
output-dir: wheelhouse

- name: Build wheels for macOS
if: runner.os == 'macOS'
uses: pypa/[email protected]
env:
CIBW_BUILD: ${{ matrix.python[1] }}-${{ matrix.buildplat[1] }}
MACOSX_DEPLOYMENT_TARGET: 13.0
CIBW_BEFORE_BUILD: brew install gsl && pip install -e .
with:
output-dir: wheelhouse

- name: Install GSL and Set Environment for GSL on Windows
if: runner.os == 'Windows'
shell: pwsh
run: |
git clone https://github.com/microsoft/vcpkg.git C:\vcpkg
cd C:\vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg integrate install
.\vcpkg install gsl gsl:x64-windows

- name: Build wheels for Windows
if: runner.os == 'Windows'
uses: pypa/[email protected]
env:
CIBW_BUILD: ${{ matrix.python[1] }}-${{ matrix.buildplat[1] }}
CIBW_ENVIRONMENT: |
GSL_PATH=C:/vcpkg/installed/x64-windows
CONDA_PREFIX: ${{ env.CONDA_PREFIX }}
with:
output-dir: wheelhouse

- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.python[0] }}-${{ matrix.buildplat[0] }}
path: ./wheelhouse/*.whl
37 changes: 24 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,23 @@ def get_gsl_config():


def get_gsl_config_win():
"""Return dictionary with paths to GSL library, windwows version.
This version is installed with conda.
"""
conda_prefix = os.environ["CONDA_PREFIX"]
inc = os.path.join(conda_prefix, "Library", "include")
lib = os.path.join(conda_prefix, "Library", "lib")
rv = {"include_dirs": [], "library_dirs": []}
rv["include_dirs"] += [inc]
rv["library_dirs"] += [lib]
return rv
"""Return dictionary with paths to GSL library on Windows."""
gsl_path = os.environ.get("GSL_PATH")
if gsl_path:
inc = os.path.join(gsl_path, "include")
lib = os.path.join(gsl_path, "lib")
else:
conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix:
inc = os.path.join(conda_prefix, "Library", "include")
lib = os.path.join(conda_prefix, "Library", "lib")
else:
raise EnvironmentError(
"Neither GSL_PATH nor CONDA_PREFIX environment variables are set. "
"Please ensure GSL is installed and GSL_PATH is correctly set."
)

return {"include_dirs": [inc], "library_dirs": [lib]}


# ----------------------------------------------------------------------------
Expand All @@ -87,19 +94,23 @@ def get_gsl_config_win():
gcfg = get_gsl_config()
include_dirs = [MYDIR] + gcfg["include_dirs"]
library_dirs = []
libraries = []
if sys.platform == "darwin":
libraries = []
else:
libraries = ["gsl"]
extra_objects = []
extra_compile_args = []
extra_link_args = []

compiler_type = get_compiler_type()
if compiler_type in ("unix", "cygwin", "mingw32"):
extra_compile_args = ["-std=c++11", "-Wall", "-Wno-write-strings", "-O3", "-funroll-loops", "-ffast-math"]
extra_objects += ((p + "/libgsl.a") for p in gcfg["library_dirs"])
extra_objects += [
os.path.join(p, "libgsl.a") for p in gcfg["library_dirs"] if os.path.isfile(os.path.join(p, "libgsl.a"))
]
elif compiler_type == "msvc":
define_macros += [("_USE_MATH_DEFINES", None)]
extra_compile_args = ["/EHs"]
libraries += ["gsl"]
library_dirs += gcfg["library_dirs"]
# add optimization flags for other compilers if needed

Expand Down
Loading