Skip to content

Commit d7c59e9

Browse files
author
Matthias Köppe
authored
Merge pull request #141 from mkoeppe/cibuildwheels
.github/workflows/wheels.yml: New
2 parents b1aed0b + 2be5aeb commit d7c59e9

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

.github/workflows/wheels.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Build wheels
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
concurrency:
9+
# Cancel previous runs of this workflow for the same branch
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
15+
sdists_for_pypi:
16+
name: Build sdist (and upload to PyPI on release tags)
17+
runs-on: ubuntu-latest
18+
env:
19+
CAN_DEPLOY: ${{ secrets.SAGEMATH_PYPI_API_TOKEN != '' }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Install pari
23+
run: |
24+
bash -x .install-pari.sh
25+
env:
26+
PARI_VERSION: pari-2.15.4
27+
- uses: actions/setup-python@v4
28+
- name: make sdist
29+
run: |
30+
python3 -m pip install build
31+
python3 -m build --sdist
32+
- uses: actions/upload-artifact@v3
33+
with:
34+
path: "dist/*.tar.gz"
35+
name: dist
36+
- uses: pypa/gh-action-pypi-publish@release/v1
37+
with:
38+
user: __token__
39+
password: ${{ secrets.SAGEMATH_PYPI_API_TOKEN }}
40+
skip_existing: true
41+
verbose: true
42+
if: env.CAN_DEPLOY == 'true' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
43+
44+
build_wheels:
45+
name: Build wheels on ${{ matrix.os }}, arch ${{ matrix.arch }}
46+
runs-on: ${{ matrix.os }}
47+
needs: sdists_for_pypi
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
include:
52+
- os: ubuntu-latest
53+
arch: x86_64
54+
- os: ubuntu-latest
55+
arch: i686
56+
- os: macos-latest
57+
arch: auto
58+
- os: macos-14
59+
arch: auto
60+
env:
61+
# SPKGs to install as system packages
62+
SPKGS: _bootstrap _prereq
63+
# Non-Python packages to install as spkgs
64+
TARGETS_PRE: pari
65+
# Disable building PyPy wheels on all platforms
66+
# Disable musllinux until #33083 provides alpine package information
67+
CIBW_SKIP: "pp* *-musllinux*"
68+
#
69+
CIBW_ARCHS: ${{ matrix.arch }}
70+
# https://cibuildwheel.readthedocs.io/en/stable/options/#requires-python
71+
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.9"
72+
# Environment during wheel build
73+
CIBW_ENVIRONMENT: "PATH=$(pwd)/local/bin:$PATH CPATH=$(pwd)/local/include:$CPATH LIBRARY_PATH=$(pwd)/local/lib:$LIBRARY_PATH LD_LIBRARY_PATH=$(pwd)/local/lib:$LD_LIBRARY_PATH PKG_CONFIG_PATH=$(pwd)/local/share/pkgconfig:$PKG_CONFIG_PATH ACLOCAL_PATH=/usr/share/aclocal"
74+
# Use 'build', not 'pip wheel'
75+
CIBW_BUILD_FRONTEND: build
76+
steps:
77+
- uses: actions/checkout@v4
78+
with:
79+
repository: sagemath/sage
80+
ref: develop
81+
82+
- uses: actions/download-artifact@v3
83+
with:
84+
name: dist
85+
path: dist
86+
87+
- uses: actions/setup-python@v5
88+
# As of 2024-02-03, the macOS M1 runners do not have preinstalled python or pipx.
89+
# Installing pipx follows the approach of https://github.com/pypa/cibuildwheel/pull/1743
90+
id: python
91+
with:
92+
python-version: "3.8 - 3.12"
93+
update-environment: false
94+
95+
- name: Build platform wheels
96+
# We build the wheel from the sdist.
97+
# But we must run cibuildwheel with the unpacked source directory, not a tarball,
98+
# so that SAGE_ROOT is copied into the build containers.
99+
#
100+
# In the CIBW_BEFORE_ALL phase, we install libraries using the Sage distribution.
101+
# https://cibuildwheel.readthedocs.io/en/stable/options/#before-all
102+
run: |
103+
"${{ steps.python.outputs.python-path }}" -m pip install pipx
104+
export PATH=build/bin:$PATH
105+
export CIBW_BEFORE_ALL="( $(sage-print-system-package-command debian --yes --no-install-recommends install $(sage-get-system-packages debian $SPKGS)) || $(sage-print-system-package-command fedora --yes --no-install-recommends install $(sage-get-system-packages fedora $SPKGS | sed s/pkg-config/pkgconfig/)) || ( $(sage-print-system-package-command homebrew --yes --no-install-recommends install $(sage-get-system-packages homebrew $SPKGS)) || echo error ignored) ) && ./bootstrap && ./configure --enable-build-as-root && make -j4 V=0 $TARGETS_PRE"
106+
mkdir -p unpacked
107+
for pkg in cypari2; do
108+
(cd unpacked && tar xfz - ) < dist/$pkg*.tar.gz
109+
"${{ steps.python.outputs.python-path }}" -m pipx run cibuildwheel==2.17.0 unpacked/$pkg*
110+
done
111+
112+
- uses: actions/upload-artifact@v3
113+
with:
114+
name: wheels
115+
path: ./wheelhouse/*.whl
116+
117+
pypi-publish:
118+
# https://github.com/pypa/gh-action-pypi-publish
119+
name: Upload wheels to PyPI
120+
needs: build_wheels
121+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
122+
runs-on: ubuntu-latest
123+
env:
124+
CAN_DEPLOY: ${{ secrets.SAGEMATH_PYPI_API_TOKEN != '' }}
125+
steps:
126+
127+
- uses: actions/download-artifact@v3
128+
with:
129+
name: wheels
130+
path: wheelhouse
131+
132+
- name: Publish package distributions to PyPI
133+
uses: pypa/gh-action-pypi-publish@release/v1
134+
with:
135+
user: __token__
136+
password: ${{ secrets.SAGEMATH_PYPI_API_TOKEN }}
137+
packages_dir: wheelhouse/
138+
skip_existing: true
139+
verbose: true
140+
if: env.CAN_DEPLOY == 'true'

0 commit comments

Comments
 (0)