Skip to content

Commit 7d29312

Browse files
committed
Use cibuildwheel to build pyodide wheels
1 parent bdcad6c commit 7d29312

File tree

7 files changed

+61
-71
lines changed

7 files changed

+61
-71
lines changed

.github/workflows/ci-emscripten.yml

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,93 +15,42 @@ jobs:
1515
build:
1616
runs-on: ubuntu-latest
1717
env:
18-
PYODIDE_VERSION: "https://github.com/pyodide/pyodide-build-environment-nightly/releases/download/20250523-emscripten_4.0.9/xbuildenv.tar.bz2"
1918
PYTHON_VERSION: 3.13 # any 3.13.x version works
20-
EMSCRIPTEN_VERSION: 4.0.9
2119
NODE_VERSION: 22
2220
steps:
23-
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v4.2.2
21+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2422

2523
- name: Set up Python ${{ env.PYTHON_VERSION }}
26-
uses: actions/setup-python@2e3e4b15a884dc73a63f962bff250a855150a234 # v5.4.0
24+
uses: actions/setup-python@v6
2725
with:
2826
python-version: ${{ env.PYTHON_VERSION }}
2927

30-
- name: Set up Emscripten toolchain
31-
uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14
32-
with:
33-
version: ${{ env.EMSCRIPTEN_VERSION }}
34-
actions-cache-folder: emsdk-cache
35-
3628
- name: Set up Node.js
37-
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
29+
uses: actions/setup-node@v6
3830
with:
3931
node-version: ${{ env.NODE_VERSION }}
4032

41-
- name: Install pyodide-build
42-
run: |
43-
pip install pyodide-build
44-
pyodide xbuildenv install --url ${{ env.PYODIDE_VERSION }}
45-
4633
- name: Restore WASM library directory from cache
4734
id: cache-wasm-library-dir
4835
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
4936
with:
5037
path: ${{ github.workspace }}/wasm-library-dir
51-
key: wasm-library-dir-${{ hashFiles('bin/pyodide_build_dependencies.sh', 'bin/build_variables.sh') }}-0
38+
key: wasm-library-dir-${{ hashFiles('pyproject.toml', 'bin/cibw_before_all_pyodide.sh', 'bin/pyodide_build_dependencies.sh', 'bin/build_variables.sh') }}-0
5239

53-
- name: Build GMP, MPFR and FLINT
54-
if: steps.cache-wasm-library-dir.outputs.cache-hit != 'true'
40+
- name: Build and test Pyodide wheel
41+
uses: pypa/cibuildwheel@298ed2fb2c105540f5ed055e8a6ad78d82dd3a7e # v3.3.1
5542
env:
56-
CFLAGS: "-fPIC"
57-
run: bin/pyodide_build_dependencies.sh --wasm-library-dir ${{ github.workspace }}/wasm-library-dir
43+
CIBW_PLATFORM: pyodide
44+
CIBW_BUILD: cp313-*
5845

5946
- name: Persist WASM library directory to cache
47+
if: steps.cache-wasm-library-dir.outputs.cache-hit != 'true'
6048
uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
6149
with:
6250
path: ${{ github.workspace }}/wasm-library-dir
63-
key: wasm-library-dir-${{ hashFiles('bin/pyodide_build_dependencies.sh', 'bin/build_variables.sh') }}-0
64-
65-
- name: Restore python-flint build directory from cache
66-
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
67-
with:
68-
path: ${{ github.workspace }}/flint_wasm_build
69-
key: flint-wasm-build-${{ hashFiles('**/meson.build', '**/pyproject.toml', '**/setup.py') }}
70-
71-
- name: Build python-flint
72-
env:
73-
WASM_LIBRARY_DIR: ${{ github.workspace }}/wasm-library-dir
74-
run: |
75-
export PKG_CONFIG_PATH="${{ env.WASM_LIBRARY_DIR }}/lib/pkgconfig:${PKG_CONFIG_PATH}"
76-
export CFLAGS="-I${{ env.WASM_LIBRARY_DIR }}/include ${CFLAGS:-}"
77-
export LDFLAGS="-L${{ env.WASM_LIBRARY_DIR }}/lib -lflint -lmpfr -lgmp ${LDFLAGS:-}"
78-
79-
echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}"
80-
echo "CFLAGS=${CFLAGS}"
81-
echo "LDFLAGS=${LDFLAGS}"
82-
83-
pkg-config --modversion python3
84-
pkg-config --modversion mpfr
85-
pkg-config --modversion flint
51+
key: wasm-library-dir-${{ hashFiles('pyproject.toml', 'bin/cibw_before_all_pyodide.sh', 'bin/pyodide_build_dependencies.sh', 'bin/build_variables.sh') }}-0
8652

87-
pyodide build -Cbuild-dir=flint_wasm_build -Csetup-args="-Dflint_version_check=false"
88-
89-
- name: Persist python-flint build directory to cache
90-
uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
53+
- uses: actions/upload-artifact@v7
9154
with:
92-
path: ${{ github.workspace }}/flint_wasm_build
93-
key: flint-wasm-build-${{ hashFiles('**/meson.build', '**/pyproject.toml', '**/setup.py') }}
94-
95-
- name: Set up Pyodide virtual environment and test python-flint
96-
run: |
97-
pyodide venv .venv-pyodide
98-
99-
source .venv-pyodide/bin/activate
100-
pip install dist/*.whl
101-
102-
cd doc
103-
104-
pip install pytest hypothesis
105-
# Don't use the cache provider plugin, as it doesn't work with Pyodide
106-
# right now: https://github.com/pypa/cibuildwheel/issues/1966
107-
pytest -svra -p no:cacheprovider --pyargs flint
55+
name: wheels-pyodide
56+
path: wheelhouse/*.whl

bin/build_dependencies_unix.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ done
140140

141141
source bin/build_variables.sh
142142

143+
mkdir -p "$PREFIX"
143144
cd $PREFIX
144145
mkdir -p src
145146
cd src

bin/build_variables.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#!/usr/bin/env bash
22
#
3-
# Create a local directory .local to be used as --prefix when building
4-
# local installs of python-flint's dependencies. This also sets the PREFIX
5-
# shell variable and environment variables giving the versions to use for each
6-
# dependency. This script should be sourced rather than executed e.g.:
3+
# Set the PREFIX shell variable and environment variables giving the versions
4+
# to use for each dependency. This script should be sourced rather than
5+
# executed e.g.:
76
#
87
# $ source bin/build_variables.sh
98
#
109
# This is used implicitly by the other build scripts and does not need to be
1110
# executed directly.
1211

1312
PREFIX=$(pwd)/.local
14-
mkdir -p $PREFIX
1513

1614
ARBVER=2.23.0 # Not needed with flint >= 3.0.0 (Arb is included in flint)
1715

bin/build_wheel.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -o errexit
77

88
source bin/build_variables.sh
99

10+
mkdir -p "$PREFIX"
1011
python3 -m venv $PREFIX/venv
1112
source $PREFIX/venv/bin/activate
1213
pip install -U pip

bin/cibw_before_all_pyodide.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
6+
PROJECT_DIR=$(cd -- "$SCRIPT_DIR/.." && pwd)
7+
WASM_LIBRARY_DIR=${WASM_LIBRARY_DIR:-"$PROJECT_DIR/wasm-library-dir"}
8+
9+
if [ -f "$WASM_LIBRARY_DIR/lib/pkgconfig/flint.pc" ]; then
10+
echo "Using cached Pyodide dependencies from $WASM_LIBRARY_DIR"
11+
exit 0
12+
fi
13+
14+
mkdir -p "$WASM_LIBRARY_DIR"
15+
16+
export CFLAGS="-fPIC ${CFLAGS:-}"
17+
18+
"$SCRIPT_DIR/pyodide_build_dependencies.sh" --wasm-library-dir "$WASM_LIBRARY_DIR"

bin/pyodide_build_dependencies.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -e
44

5+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
6+
57
while [[ $# -gt 0 ]]
68
do
79
key="$1"
@@ -43,9 +45,12 @@ if [ -z "$WASM_LIBRARY_DIR" ]; then
4345
exit 1
4446
fi
4547

48+
mkdir -p "$WASM_LIBRARY_DIR/src"
49+
cd "$WASM_LIBRARY_DIR/src"
50+
4651
# Sets versions of GMP, MPFR and FLINT:
4752

48-
source bin/build_variables.sh
53+
source "$SCRIPT_DIR/build_variables.sh"
4954

5055
# Download mirrored copy of source distributions for GMP and MPFR
5156

@@ -106,7 +111,7 @@ fi
106111

107112
# Patch needed for FLINT == 3.4.0
108113
# This is https://github.com/flintlib/flint/pull/2594
109-
patch -N -Z -p1 < ../bin/patch-flint-emscripten-profiler.diff
114+
patch -N -Z -p1 < "$SCRIPT_DIR/patch-flint-emscripten-profiler.diff"
110115

111116
./bootstrap.sh
112117

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,21 @@ repair-wheel-command = [
176176
""",
177177
"delvewheel repair -w {dest_dir} {wheel} --add-path .local/bin",
178178
]
179+
180+
[tool.cibuildwheel.pyodide]
181+
before-all = "bin/cibw_before_all_pyodide.sh"
182+
pyodide-version = "0.28.2"
183+
# GMP, MPFR, and FLINT are built as static libraries for Pyodide.
184+
repair-wheel-command = ""
185+
test-command = "python -m pytest -svra -p no:cacheprovider --pyargs flint"
186+
test-requires = ["pytest", "hypothesis"]
187+
188+
[tool.cibuildwheel.pyodide.environment]
189+
WASM_LIBRARY_DIR = "$(pwd)/wasm-library-dir"
190+
PKG_CONFIG_PATH = "$(pwd)/wasm-library-dir/lib/pkgconfig:$PKG_CONFIG_PATH"
191+
CFLAGS = "-I$(pwd)/wasm-library-dir/include $CFLAGS"
192+
LDFLAGS = "-L$(pwd)/wasm-library-dir/lib -lflint -lmpfr -lgmp $LDFLAGS"
193+
194+
[tool.cibuildwheel.pyodide.config-settings]
195+
build-dir = "flint_wasm_build"
196+
setup-args = ["-Dflint_version_check=false"]

0 commit comments

Comments
 (0)