|
| 1 | +# Copied from NumPy https://github.com/numpy/numpy/pull/24603 |
| 2 | +# https://github.com/numpy/numpy/blob/328a9a488c3a146497be704d2cee2f9134e43b5b/.github/workflows/emscripten.yml |
| 3 | +# |
| 4 | +# To enable this workflow on a fork, comment out: |
| 5 | +# |
| 6 | +# if: github.repository == 'scikit-image/scikit-image' |
| 7 | +name: Test Emscripten/Pyodide build |
| 8 | + |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + - maintenance/** |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read # to fetch code (actions/checkout) |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-wasm-emscripten: |
| 24 | + runs-on: ubuntu-22.04 |
| 25 | + if: "github.repository == 'scikit-image/scikit-image'" |
| 26 | + env: |
| 27 | + PYODIDE_VERSION: 0.23.1 |
| 28 | + # PYTHON_VERSION and EMSCRIPTEN_VERSION are determined by PYODIDE_VERSION. |
| 29 | + # The appropriate versions can be found in the Pyodide repodata.json |
| 30 | + # "info" field, or in Makefile.envs: |
| 31 | + # https://github.com/pyodide/pyodide/blob/main/Makefile.envs#L2 |
| 32 | + PYTHON_VERSION: 3.11.2 |
| 33 | + EMSCRIPTEN_VERSION: 3.1.32 |
| 34 | + NODE_VERSION: 18 |
| 35 | + steps: |
| 36 | + - name: Checkout scikit-image |
| 37 | + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 |
| 38 | + |
| 39 | + - name: set up python |
| 40 | + id: setup-python |
| 41 | + uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0 |
| 42 | + with: |
| 43 | + python-version: ${{ env.PYTHON_VERSION }} |
| 44 | + |
| 45 | + - uses: mymindstorm/setup-emsdk@ab889da2abbcbb280f91ec4c215d3bb4f3a8f775 # v12 |
| 46 | + with: |
| 47 | + version: ${{ env.EMSCRIPTEN_VERSION }} |
| 48 | + actions-cache-folder: emsdk-cache |
| 49 | + |
| 50 | + - name: Install pyodide-build |
| 51 | + run: pip install "pydantic<2" build pyodide-build==$PYODIDE_VERSION |
| 52 | + |
| 53 | + - name: Build |
| 54 | + run: | |
| 55 | + # Note that we need to cross-compile here. Using `pyodide build` |
| 56 | + # fails on not having a cross file. The `source() function in |
| 57 | + # `pyodide_build/cli/build.py` needs a --backend-flags parameter so |
| 58 | + # that we can pass config-settings arguments to the backend. |
| 59 | + # We'll then run into static assert issues in `pyconfig.h` due to: |
| 60 | + # https://github.com/pyodide/pyodide/pull/2494#issuecomment-1118500743 |
| 61 | + # See also https://github.com/pyodide/pyodide/pull/2238 and the patches |
| 62 | + # to _numpyconfig.h in https://github.com/pyodide/pyodide/tree/main/packages/numpy |
| 63 | + # |
| 64 | + # tl;dr this needs some work, and it seems like cross-compilation is |
| 65 | + # hard because Pyodide doesn't ship its own Python interpreter that |
| 66 | + # we can actually target during a direct cross build. |
| 67 | + python -m build --wheel -Csetup-args=--cross-file=$PWD/tools/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true |
| 68 | +
|
| 69 | + - name: set up node |
| 70 | + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 |
| 71 | + with: |
| 72 | + node-version: ${{ env.NODE_VERSION }} |
| 73 | + |
| 74 | + - name: Set up Pyodide virtual environment |
| 75 | + run: | |
| 76 | + pyodide venv .venv-pyodide |
| 77 | + source .venv-pyodide/bin/activate |
| 78 | + pip install dist/*.whl |
| 79 | + python -c "import sys; print(sys.platform)" |
| 80 | + pip install -r test_requirements.txt |
| 81 | + - name: Test |
| 82 | + run: | |
| 83 | + source .venv-pyodide/bin/activate |
| 84 | + cd .. |
| 85 | + pytest --pyargs numpy -m "not slow" |
0 commit comments