Skip to content

Commit 90b31fe

Browse files
committed
build windows wheel
1 parent 154c87a commit 90b31fe

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

.github/workflows/wheel.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Wheel builder
2+
3+
on:
4+
pull_request:
5+
push:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build_wheels:
10+
11+
defaults:
12+
run:
13+
shell: bash -l {0}
14+
15+
name: Build wheel ${{ matrix.python[0] }}-${{ matrix.buildplat[0] }}
16+
runs-on: ${{ matrix.buildplat[0] }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
buildplat:
21+
- [ubuntu-latest, manylinux_x86_64]
22+
- [macos-13, macosx_x86_64]
23+
- [macos-14, macosx_arm64]
24+
- [windows-latest, win_amd64]
25+
python:
26+
- ["3.11", "cp311"]
27+
- ["3.12", "cp312"]
28+
29+
steps:
30+
- name: Check out #${{ inputs.project }}
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Python ${{ matrix.python[0] }}
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: ${{ matrix.python[0] }}
37+
38+
- name: Build wheels for Linux
39+
if: runner.os == 'Linux'
40+
uses: pypa/cibuildwheel@v2.21.1
41+
env:
42+
CIBW_BUILD: ${{ matrix.python[1] }}-${{ matrix.buildplat[1] }}
43+
CIBW_BEFORE_BUILD: yum install -y gsl-devel && pip install -e .
44+
with:
45+
output-dir: wheelhouse
46+
47+
- name: Build wheels for macOS
48+
if: runner.os == 'macOS'
49+
uses: pypa/cibuildwheel@v2.21.1
50+
env:
51+
CIBW_BUILD: ${{ matrix.python[1] }}-${{ matrix.buildplat[1] }}
52+
MACOSX_DEPLOYMENT_TARGET: 13.0
53+
CIBW_BEFORE_BUILD: brew install gsl && pip install -e .
54+
with:
55+
output-dir: wheelhouse
56+
57+
- name: Set up conda for Windows
58+
if: runner.os == 'Windows'
59+
uses: conda-incubator/setup-miniconda@v3
60+
with:
61+
activate-environment: gsl
62+
auto-update-conda: true
63+
environment-file: environment.yml
64+
auto-activate-base: false
65+
66+
- name: install gsl for Windows
67+
if: runner.os == 'Windows'
68+
run: |
69+
conda config --set always_yes yes --set changeps1 no
70+
conda install gsl
71+
72+
- name: Build wheels for Windows
73+
if: runner.os == 'Windows'
74+
uses: pypa/cibuildwheel@v2.21.1
75+
env:
76+
CIBW_BUILD: ${{ matrix.python[1] }}-${{ matrix.buildplat[1] }}
77+
CONDA_PREFIX: ${{ env.CONDA_PREFIX }}
78+
with:
79+
output-dir: wheelhouse
80+
81+
- uses: actions/upload-artifact@v4
82+
with:
83+
name: ${{ matrix.python[0] }}-${{ matrix.buildplat[0] }}
84+
path: ./wheelhouse/*.whl

setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import re
1414
import sys
15+
import shutil
1516
import warnings
1617

1718
from setuptools import Extension, setup
@@ -82,6 +83,17 @@ def get_gsl_config_win():
8283

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

86+
class CustomBuildExt(build_ext):
87+
def run(self):
88+
super().run()
89+
gsl_path = os.environ.get("GSL_PATH") or os.path.join(os.environ.get("CONDA_PREFIX", ""), "Library")
90+
91+
bin_path = os.path.join(gsl_path, "bin")
92+
dest_path = os.path.join(self.build_lib, "diffpy", "pdffit2")
93+
os.makedirs(dest_path, exist_ok=True)
94+
95+
for dll_file in glob.glob(os.path.join(bin_path, "gsl*.dll")):
96+
shutil.copy(dll_file, dest_path)
8597

8698
# ----------------------------------------------------------------------------
8799

@@ -134,6 +146,7 @@ def create_extensions():
134146

135147
setup_args = dict(
136148
ext_modules=[],
149+
cmdclass={"build_ext": CustomBuildExt},
137150
)
138151

139152
if __name__ == "__main__":

0 commit comments

Comments
 (0)