Build wheels #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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.40" | |
| 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: 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 |