-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (179 loc) · 6.83 KB
/
wheels.yml
File metadata and controls
208 lines (179 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# PyQuantLib: Python bindings for QuantLib
# Copyright (c) 2025 Yassine Idyiahia
#
# Build wheels for multiple platforms using cibuildwheel.
# QuantLib is built from source during the wheel build process.
name: Build wheels
on:
workflow_dispatch:
pull_request:
paths:
- "src/**"
- "include/**"
- "CMakeLists.txt"
- "pyproject.toml"
- ".github/workflows/wheels.yml"
release:
types: [published]
env:
QUANTLIB_VERSION: "1.41"
BOOST_VERSION: "1.86.0"
jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-14]
steps:
- uses: actions/checkout@v4
- name: Pre-cache virtualenv for cibuildwheel
shell: bash
run: |
VER=20.26.6
if [ "$RUNNER_OS" = "Windows" ]; then
CACHE_DIR="$LOCALAPPDATA/pypa/cibuildwheel/Cache"
elif [ "$RUNNER_OS" = "macOS" ]; then
CACHE_DIR="$HOME/Library/Caches/cibuildwheel"
else
CACHE_DIR="$HOME/.cache/cibuildwheel"
fi
mkdir -p "$CACHE_DIR"
DEST="$CACHE_DIR/virtualenv-${VER}.pyz"
if [ ! -f "$DEST" ]; then
for i in 1 2 3 4 5; do
if curl -sL --retry 3 --retry-delay 10 -o "$DEST" \
"https://github.com/pypa/get-virtualenv/blob/${VER}/public/virtualenv.pyz?raw=true"; then
echo "Downloaded virtualenv-${VER}.pyz (attempt $i)"
break
fi
echo "Attempt $i failed, waiting 30s..."
sleep 30
done
fi
ls -la "$DEST"
- name: Build wheels
uses: pypa/cibuildwheel@v2.21
env:
# Build for CPython only (no PyPy)
CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-*"
CIBW_SKIP: "*-musllinux_*"
CIBW_BUILD_VERBOSITY: 1
# macOS: ARM only (macos-14)
CIBW_ARCHS_MACOS: "arm64"
CIBW_ARCHS_LINUX: "x86_64"
CIBW_ARCHS_WINDOWS: "AMD64"
# Environment variables for build
CIBW_ENVIRONMENT: >
QUANTLIB_VERSION=${{ env.QUANTLIB_VERSION }}
BOOST_VERSION=${{ env.BOOST_VERSION }}
# Linux: Build QuantLib in manylinux container
# Note: CIBW_ENVIRONMENT is NOT available during before_all,
# so we use ${{ env.* }} (evaluated by GitHub Actions before cibuildwheel runs).
CIBW_BEFORE_ALL_LINUX: |
set -ex
yum install -y wget tar gzip
# Install Boost headers
BOOST_UNDERSCORE=$(echo ${{ env.BOOST_VERSION }} | tr '.' '_')
wget -q https://archives.boost.io/release/${{ env.BOOST_VERSION }}/source/boost_${BOOST_UNDERSCORE}.tar.gz
tar xzf boost_${BOOST_UNDERSCORE}.tar.gz
mkdir -p /usr/local/include
cp -r boost_${BOOST_UNDERSCORE}/boost /usr/local/include/
rm -rf boost_${BOOST_UNDERSCORE}*
# Build QuantLib
wget -q https://github.com/lballabio/QuantLib/releases/download/v${{ env.QUANTLIB_VERSION }}/QuantLib-${{ env.QUANTLIB_VERSION }}.tar.gz
tar xzf QuantLib-${{ env.QUANTLIB_VERSION }}.tar.gz
cd QuantLib-${{ env.QUANTLIB_VERSION }}
mkdir -p build && cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_POLICY_DEFAULT_CMP0167=OLD \
-DBUILD_SHARED_LIBS=OFF \
-DQL_USE_STD_SHARED_PTR=ON \
-DQL_USE_STD_OPTIONAL=ON \
-DQL_USE_STD_ANY=ON \
-DQL_BUILD_EXAMPLES=OFF \
-DQL_BUILD_TEST_SUITE=OFF \
-DQL_BUILD_BENCHMARK=OFF
cmake --build . --parallel $(nproc)
cmake --install .
cd ../..
rm -rf QuantLib-${{ env.QUANTLIB_VERSION }}*
CIBW_ENVIRONMENT_LINUX: >
QuantLib_ROOT=/usr/local
Boost_INCLUDE_DIR=/usr/local/include
# macOS: Build QuantLib
CIBW_BEFORE_ALL_MACOS: |
set -ex
brew install boost cmake
# Build QuantLib
curl -sL -o QuantLib.tar.gz https://github.com/lballabio/QuantLib/releases/download/v${{ env.QUANTLIB_VERSION }}/QuantLib-${{ env.QUANTLIB_VERSION }}.tar.gz
tar xzf QuantLib.tar.gz
cd QuantLib-${{ env.QUANTLIB_VERSION }}
mkdir -p build && cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/tmp/quantlib \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
-DBUILD_SHARED_LIBS=OFF \
-DQL_USE_STD_SHARED_PTR=ON \
-DQL_USE_STD_OPTIONAL=ON \
-DQL_USE_STD_ANY=ON \
-DQL_BUILD_EXAMPLES=OFF \
-DQL_BUILD_TEST_SUITE=OFF \
-DQL_BUILD_BENCHMARK=OFF
cmake --build . --parallel $(sysctl -n hw.ncpu)
cmake --install .
cd ../..
rm -rf QuantLib-${{ env.QUANTLIB_VERSION }}*
CIBW_ENVIRONMENT_MACOS: >
QuantLib_ROOT=/tmp/quantlib
# Windows: Build QuantLib (PowerShell script, since cibuildwheel uses cmd on Windows)
CIBW_BEFORE_ALL_WINDOWS: "powershell -ExecutionPolicy Bypass -File {project}/.github/scripts/build-quantlib-windows.ps1"
CIBW_ENVIRONMENT_WINDOWS: >
QuantLib_ROOT=C:/quantlib
Boost_INCLUDE_DIR=C:/boost/include
# Run tests
CIBW_TEST_REQUIRES: pytest numpy
CIBW_TEST_COMMAND: pytest {project}/tests -v --ignore={project}/tests/test_pricingengines_vanilla.py
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
run: pipx run build --sdist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
upload_pypi:
name: Upload to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
environment:
name: pypi
url: https://pypi.org/p/pyquantlib
permissions:
id-token: write # Required for trusted publishing
steps:
- uses: actions/download-artifact@v4
with:
pattern: wheels-*
path: dist
merge-multiple: true
- uses: actions/download-artifact@v4
with:
name: sdist
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1