Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM build #262

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions .github/workflows/ci-emscripten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: Run Pyodide CI

on:
pull_request:
workflow_dispatch:

env:
FORCE_COLOR: 3

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
env:
PYODIDE_VERSION: 0.27.3
# PYTHON_VERSION and EMSCRIPTEN_VERSION are determined by PYODIDE_VERSION.
# The appropriate versions can be found in the Pyodide repodata.json
# "info" field, or in Makefile.envs:
# https://github.com/pyodide/pyodide/blob/main/Makefile.envs#L2
PYTHON_VERSION: 3.12 # any 3.12.x version works
EMSCRIPTEN_VERSION: 3.1.58
NODE_VERSION: 20
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Set up Emscripten toolchain
uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14
with:
version: ${{ env.EMSCRIPTEN_VERSION }}
actions-cache-folder: emsdk-cache

- name: Set up Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install pyodide-build
run: pip install pyodide-build

- name: Restore WASM library directory from cache
id: cache-wasm-library-dir
uses: actions/cache/restore@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
with:
path: ${{ github.workspace }}/wasm-library-dir
key: wasm-library-dir-${{ hashFiles('.github/workflows/ci-emscripten.yml') }}

- name: Build libgmp
if: steps.cache-wasm-library-dir.outputs.cache-hit != 'true'
env:
CFLAGS: "-fPIC"
WASM_LIBRARY_DIR: ${{ github.workspace }}/wasm-library-dir
run: |
curl -L https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz -o gmp-6.3.0.tar.xz
tar -xf gmp-6.3.0.tar.xz

cd gmp-6.3.0

emconfigure ./configure \
--disable-dependency-tracking \
--host none \
--disable-shared \
--enable-static \
--enable-cxx \
--prefix=${{ env.WASM_LIBRARY_DIR }}
emmake make -j $(nproc)
emmake make install

- name: Build libmpfr
if: steps.cache-wasm-library-dir.outputs.cache-hit != 'true'
env:
CFLAGS: "-fPIC"
WASM_LIBRARY_DIR: ${{ github.workspace }}/wasm-library-dir
run: |
curl -L https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz -o mpfr-4.2.1.tar.xz
tar -xf mpfr-4.2.1.tar.xz

cd mpfr-4.2.1

emconfigure ./configure \
--disable-dependency-tracking \
--disable-shared \
--with-gmp="${{ env.WASM_LIBRARY_DIR }}" \
--prefix=${{ env.WASM_LIBRARY_DIR }}
emmake make -j $(nproc)
emmake make install

# might need patch
- name: Build flint
if: steps.cache-wasm-library-dir.outputs.cache-hit != 'true'
env:
CFLAGS: "-fPIC"
WASM_LIBRARY_DIR: ${{ github.workspace }}/wasm-library-dir
run: |
curl -L https://github.com/flintlib/flint/releases/download/v3.2.0-rc1/flint-3.2.0-rc1.tar.xz -o flint-3.2.0-rc1.tar.xz
tar -xf flint-3.2.0-rc1.tar.xz

cd flint-3.2.0-rc1

emconfigure ./configure \
--disable-dependency-tracking \
--disable-shared \
--prefix=${{ env.WASM_LIBRARY_DIR }} \
--with-gmp=${{ env.WASM_LIBRARY_DIR }} \
--with-mpfr=${{ env.WASM_LIBRARY_DIR }}
Comment on lines +105 to +112
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to set something like --disable-assembly or --host=... here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what the host triple is for WASM

emmake make -j $(nproc)
emmake make install

- name: Persist WASM library directory to cache
uses: actions/cache/save@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
with:
path: ${{ github.workspace }}/wasm-library-dir
key: wasm-library-dir-${{ hashFiles('.github/workflows/ci-emscripten.yml') }}

- name: Build python-flint
env:
WASM_LIBRARY_DIR: ${{ github.workspace }}/wasm-library-dir
run: |
export PKG_CONFIG_PATH="${{ env.WASM_LIBRARY_DIR }}/lib/pkgconfig:${PKG_CONFIG_PATH}"
export CFLAGS="-I${{ env.WASM_LIBRARY_DIR }}/include ${CFLAGS:-}"
export LDFLAGS="-L${{ env.WASM_LIBRARY_DIR }}/lib -lflint -lmpfr -lgmp ${LDFLAGS:-}"

echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}"
echo "CFLAGS=${CFLAGS}"
echo "LDFLAGS=${LDFLAGS}"

pkg-config --modversion python3
pkg-config --modversion mpfr
pkg-config --modversion flint

pyodide build

- name: Set up Pyodide virtual environment and test python-flint
run: |
pyodide xbuildenv install ${{ env.PYODIDE_VERSION }}
pyodide venv .venv-pyodide

source .venv-pyodide/bin/activate
pip install dist/*.whl

cd doc

pip install pytest hypothesis
# Don't use the cache provider plugin, as it doesn't work with Pyodide
# right now: https://github.com/pypa/cibuildwheel/issues/1966
pytest -svra -p no:cacheprovider --pyargs flint
Loading
Loading