Fix macOS wheel build: use brew for cmake/swig #22
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
| name: CI | |
| on: | |
| push: | |
| branches: [main, master] | |
| tags: ["v*"] | |
| pull_request: | |
| branches: [main, master] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| name: Build wheel | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Set up Python | |
| run: uv python install 3.12 | |
| - name: Clone libcdoc | |
| run: git clone https://github.com/open-eid/libcdoc.git | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libssl-dev libxml2-dev zlib1g-dev flatbuffers-compiler libflatbuffers-dev | |
| - name: Build wheel | |
| run: uv build --wheel | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheel | |
| path: dist/*.whl | |
| test: | |
| name: Test | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Set up Python | |
| run: uv python install 3.12 | |
| - name: Download wheel | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: wheel | |
| path: dist | |
| - name: Install wheel and test | |
| run: | | |
| uv venv | |
| uv pip install dist/*.whl pytest cryptography | |
| uv run --no-project pytest tests/ -v | |
| build_wheels: | |
| name: Build wheels on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Clone libcdoc | |
| run: git clone https://github.com/open-eid/libcdoc.git | |
| - name: Install dependencies (Ubuntu) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libssl-dev libxml2-dev zlib1g-dev | |
| - name: Install dependencies (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| brew install openssl@3 libxml2 flatbuffers cmake swig | |
| - name: Install dependencies (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| choco install openssl | |
| - name: Build wheels | |
| uses: pypa/cibuildwheel@v2.22.0 | |
| env: | |
| # Use uv for faster builds | |
| CIBW_BUILD_FRONTEND: "build[uv]" | |
| # Build for Python 3.9-3.13 | |
| CIBW_BUILD: "cp39-* cp310-* cp311-* cp312-* cp313-*" | |
| # Skip 32-bit builds and musllinux | |
| CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux_*" | |
| # Install build dependencies in the container (need OpenSSL 3.x) | |
| CIBW_BEFORE_ALL_LINUX: > | |
| yum install -y perl-IPC-Cmd libxml2-devel zlib-devel && | |
| curl -L https://www.openssl.org/source/openssl-3.0.13.tar.gz | tar xz && | |
| cd openssl-3.0.13 && | |
| ./config --prefix=/usr/local/openssl3 --openssldir=/usr/local/openssl3 && | |
| make -j$(nproc) && | |
| make install | |
| CIBW_ENVIRONMENT_LINUX: > | |
| OPENSSL_ROOT_DIR=/usr/local/openssl3 | |
| PKG_CONFIG_PATH=/usr/local/openssl3/lib64/pkgconfig | |
| # Install flatbuffers from source on Linux | |
| CIBW_BEFORE_BUILD_LINUX: > | |
| uv pip install --system cmake swig && | |
| if ! command -v flatc; then | |
| cd /tmp && | |
| curl -L https://github.com/google/flatbuffers/archive/refs/tags/v24.3.25.tar.gz | tar xz && | |
| cd flatbuffers-24.3.25 && | |
| cmake -B build -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF && | |
| cmake --build build --target install; | |
| fi | |
| # cmake and swig installed via brew in Install dependencies step | |
| CIBW_BEFORE_BUILD_WINDOWS: uv pip install --system cmake swig | |
| # Set OpenSSL path on macOS | |
| CIBW_ENVIRONMENT_MACOS: > | |
| OPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl@3 | |
| CMAKE_PREFIX_PATH=/opt/homebrew | |
| # Repair wheels | |
| CIBW_REPAIR_WHEEL_COMMAND_LINUX: auditwheel repair -w {dest_dir} {wheel} | |
| CIBW_REPAIR_WHEEL_COMMAND_MACOS: delocate-wheel -w {dest_dir} {wheel} | |
| # Test the wheel | |
| CIBW_TEST_REQUIRES: pytest | |
| CIBW_TEST_COMMAND: pytest {project}/tests -v | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.os }} | |
| path: ./wheelhouse/*.whl | |
| build_sdist: | |
| name: Build source distribution | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Clone libcdoc | |
| run: git clone https://github.com/open-eid/libcdoc.git | |
| - name: Build sdist | |
| run: uv build --sdist | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: sdist | |
| path: dist/*.tar.gz | |
| publish: | |
| name: Publish to PyPI | |
| needs: [build_wheels, build_sdist] | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/pycdoc | |
| permissions: | |
| id-token: write | |
| 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 |