3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-20 07:36:31 +00:00

python: build a PyPI-publishable Pyodide (PEP 783) wheel

z3 already builds under Pyodide, but via `pyodide build` the resulting
wheel is tagged `emscripten_<pyodide-version>_wasm32` and only usable as a
CI artifact. PEP 783 introduced the portable `pyemscripten_<date>_wasm32`
tag that PyPI accepts and micropip can install at runtime. This makes z3
produce that wheel via `cibuildwheel --platform pyodide`.

Changes:

* setup.py: for the emscripten target, use the wheel platform tag that
  pyodide-build supplies verbatim via _PYTHON_HOST_PLATFORM (e.g.
  `pyemscripten_2026_0_wasm32`) instead of reconstructing an
  `emscripten_*` tag, falling back to the old behaviour when that env var
  is absent.

* setup.py / CMakeLists.txt / pyproject.toml: switch the Pyodide build
  from JS-based exceptions (`-fexceptions`, `-sDISABLE_EXCEPTION_CATCHING=0`)
  to native wasm exception handling (`-fwasm-exceptions
  -sSUPPORT_LONGJMP=wasm`), matching the ABI of the Pyodide 314 /
  emscripten 5 main module. With the old flags libz3.so imports `invoke_*`
  trampolines the runtime no longer provides, so the wheel builds but the
  first Z3 call fails at runtime with
  "Dynamic linking error: cannot resolve symbol invoke_vi".

* pyproject.toml: add [tool.cibuildwheel] / [tool.pyodide.build] config so
  `cibuildwheel --platform pyodide` builds and tests the wheel.

* add .github/workflows/pyodide-pypi.yml building the wheel with
  cibuildwheel and publishing it to PyPI (trusted publishing) on tags. The
  existing pyodide.yml artifact build is left unchanged.

Verified with cibuildwheel 4.1.0 / pyodide-build 0.35.0 / emscripten 5.0.3:
the resulting z3_solver-4.17.0.0-py3-none-pyemscripten_2026_0_wasm32.whl
passes z3test.py in the Pyodide runtime and solves SMT problems both under
node and in a browser via micropip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Alcides Fonseca 2026-06-17 12:36:27 +01:00
parent f508854fe5
commit 78818f9ae1
4 changed files with 114 additions and 4 deletions

57
.github/workflows/pyodide-pypi.yml vendored Normal file
View file

@ -0,0 +1,57 @@
name: Pyodide Wheel (PyPI)
# Builds a PEP 783 `pyemscripten_*_wasm32` wheel for z3-solver using cibuildwheel
# and publishes it to PyPI on tag pushes. Unlike the legacy pyodide.yml (which
# uses `pyodide build` and produces a Pyodide-version-locked emscripten_* wheel
# uploaded only as a CI artifact), this wheel is installable at runtime with
# micropip from PyPI. See src/api/python/pyproject.toml [tool.cibuildwheel].
on:
release:
types: [created]
workflow_dispatch:
permissions:
contents: read
jobs:
build-pyodide:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Build Pyodide wheel
uses: pypa/cibuildwheel@v4.1.0
with:
# The Python bindings live in a subdirectory of the repo.
package-dir: src/api/python
env:
CIBW_PLATFORM: pyodide
# Exception/longjmp/bigint flags are declared in
# src/api/python/pyproject.toml ([tool.pyodide.build]) and combined
# with Pyodide's -fwasm-exceptions defaults. Don't set CFLAGS/CXXFLAGS
# here — a JS-EH -fexceptions value conflicts with the wasm-EH ABI.
- name: Store Pyodide wheel
uses: actions/upload-artifact@v7
with:
name: pyodide-wheel
path: wheelhouse/*.whl
publish:
name: Publish to PyPI
runs-on: ubuntu-24.04
if: startsWith(github.ref, 'refs/tags/')
needs: [build-pyodide]
environment: release
permissions:
id-token: write # trusted publishing (OIDC), no API token needed
steps:
- name: Download Pyodide wheel
uses: actions/download-artifact@v8
with:
name: pyodide-wheel
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1