Skip to content

Commit 0d5b630

Browse files
committed
Try to build wheels
1 parent f5c1a4c commit 0d5b630

2 files changed

Lines changed: 135 additions & 0 deletions

File tree

.github/workflows/wheels.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Build and Publish Wheels
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
tags: [ "v*.*.*" ]
7+
pull_request:
8+
branches: [ "main" ]
9+
workflow_dispatch:
10+
11+
jobs:
12+
build_sdist:
13+
name: Build source distribution
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.x"
21+
22+
- name: Build SDist
23+
run: |
24+
pip install build
25+
python -m build --sdist
26+
27+
- uses: actions/upload-artifact@v4
28+
with:
29+
name: cibw-sdist
30+
path: dist/*.tar.gz
31+
32+
build_wheels:
33+
name: Build wheels on ${{ matrix.os }} (${{ matrix.arch }})
34+
runs-on: ${{ matrix.os }}
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
include:
39+
# Linux
40+
- os: ubuntu-latest
41+
arch: x86_64
42+
- os: ubuntu-latest
43+
arch: aarch64
44+
45+
# macOS (Intel and Apple Silicon)
46+
- os: macos-13
47+
arch: x86_64
48+
- os: macos-14
49+
arch: arm64
50+
51+
# Windows
52+
- os: windows-latest
53+
arch: AMD64
54+
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Set up QEMU (for Linux ARM64)
59+
if: runner.os == 'Linux' && matrix.arch == 'aarch64'
60+
uses: docker/setup-qemu-action@v3
61+
62+
- name: Install dependencies (macOS)
63+
if: runner.os == 'macOS'
64+
run: |
65+
brew install gcc ninja
66+
67+
- name: Setup MSYS2 (Windows)
68+
if: runner.os == 'Windows'
69+
uses: msys2/setup-msys2@v2
70+
with:
71+
msystem: MINGW64
72+
update: true
73+
install: >-
74+
mingw-w64-x86_64-gcc
75+
mingw-w64-x86_64-gcc-fortran
76+
mingw-w64-x86_64-cmake
77+
mingw-w64-x86_64-ninja
78+
# crucial to allow cibuildwheel to see the MSYS2 tools
79+
path-type: inherit
80+
81+
- name: Build wheels
82+
uses: pypa/cibuildwheel@v2.17.0
83+
env:
84+
CIBW_ARCHS: "${{ matrix.arch }}"
85+
86+
- uses: actions/upload-artifact@v4
87+
with:
88+
name: cibw-wheels-${{ matrix.os }}-${{ matrix.arch }}
89+
path: ./wheelhouse/*.whl
90+
91+
upload_pypi:
92+
name: Upload to PyPI
93+
needs: [build_wheels, build_sdist]
94+
runs-on: ubuntu-latest
95+
# Only publish on version tags
96+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
97+
98+
# Required for PyPI Trusted Publishing (OIDC)
99+
environment:
100+
name: pypi
101+
url: https://pypi.org/p/mpi-stubs
102+
permissions:
103+
id-token: write
104+
105+
steps:
106+
- uses: actions/download-artifact@v4
107+
with:
108+
pattern: cibw-*
109+
merge-multiple: true
110+
path: dist
111+
112+
- name: Publish package distributions to PyPI
113+
uses: pypa/gh-action-pypi-publish@release/v1

pyproject.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,25 @@ mpiexec = "mpi_stubs:mpiexec"
3030
wheel.packages = ["python/mpi_stubs"]
3131
# Tell CMake to install its artifacts into an inner 'data' folder
3232
wheel.install-dir = "mpi_stubs/data"
33+
34+
35+
# ... (Keep existing pyproject.toml contents) ...
36+
37+
[tool.cibuildwheel]
38+
# Skip PyPy (unless you specifically want to support it) and Musllinux (to save CI time, add back if needed)
39+
skip = ["pp*", "*-musllinux*"]
40+
build-frontend = "build"
41+
# Run a quick sanity check to ensure the python package imports correctly
42+
test-command = "python -c \"import mpi_stubs; print('Successfully imported mpi_stubs')\""
43+
44+
[tool.cibuildwheel.linux]
45+
# manylinux images are CentOS/AlmaLinux based; we need to install gfortran before building
46+
before-all = "yum install -y gcc-gfortran"
47+
48+
[tool.cibuildwheel.macos]
49+
# Force scikit-build-core to use the Homebrew gfortran we will install in the workflow
50+
environment = { FC = "$(ls $(brew --prefix)/bin/gfortran* | sort -V | tail -n 1)" }
51+
52+
[tool.cibuildwheel.windows]
53+
# Force scikit-build-core to use MSYS2/MinGW toolchain instead of MSVC (which lacks Fortran)
54+
environment = { CC = "gcc", CXX = "g++", FC = "gfortran", CMAKE_GENERATOR = "MinGW Makefiles", PATH = "C:\\msys64\\mingw64\\bin;%PATH%" }

0 commit comments

Comments
 (0)