-
Notifications
You must be signed in to change notification settings - Fork 96
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
Add out-of-tree Pyodide builds in CI for numcodecs
#529
base: main
Are you sure you want to change the base?
Changes from 43 commits
db77ad5
22cede6
3c2b0be
a8c956f
8769743
28674c3
f6df488
d678be8
6ce4127
199928d
1f5e7b7
da909f8
a54c555
494dd2f
a7446c8
9271054
764f34e
d41f75f
ee39d1e
731c6b2
0616dd5
1aa838b
0638a91
53f2096
7133abb
bc9b6dc
5a4e234
4ce9e4d
d6c43ef
55a2690
9a0482b
bf42491
9924e8e
0847241
b6713ca
a590785
3e1a968
e4f6670
4c348f2
dacbd09
6caf076
85252f4
6b8d139
8aee545
c3e346a
2e0e759
4e6f2b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Attributed to NumPy https://github.com/numpy/numpy/pull/25894 | ||
# https://github.com/numpy/numpy/blob/d2d2c25fa81b47810f5cbd85ea6485eb3a3ffec3/.github/workflows/emscripten.yml | ||
# | ||
|
||
name: Pyodide CI | ||
|
||
on: | ||
# TODO: refine after this is ready to merge | ||
[push, pull_request, workflow_dispatch] | ||
|
||
env: | ||
FORCE_COLOR: 3 | ||
# Disable instructions: AVX2 and SSE2 because Emscripten-specific SIMD | ||
# support has not been implemented yet | ||
DISABLE_NUMCODECS_AVX2: 1 | ||
DISABLE_NUMCODECS_SSE2: 1 | ||
# Common environment variables for both build and test jobs | ||
PYODIDE_VERSION: 0.27.0 | ||
# 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 | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
contents: read # to fetch code (actions/checkout) | ||
|
||
jobs: | ||
build-wasm-emscripten: | ||
name: Build numcodecs Pyodide distribution | ||
runs-on: ubuntu-22.04 | ||
# To enable this workflow on a fork, comment out: | ||
# FIXME: uncomment after this is ready to merge | ||
# if: github.repository == 'zarr-developers/numcodecs' | ||
steps: | ||
- name: Checkout source | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Set up Python ${{ env.PYTHON_VERSION }} | ||
id: setup-python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ env.PYTHON_VERSION }} | ||
|
||
- name: Set up Emscripten toolchain | ||
uses: mymindstorm/setup-emsdk@v14 | ||
with: | ||
version: ${{ env.EMSCRIPTEN_VERSION }} | ||
actions-cache-folder: emsdk-cache | ||
|
||
- name: Apply necessary patch(es) | ||
run: | | ||
patch -p1 < tools/ci/patches/0001-disable-multiprocessing-and-pthreads.patch | ||
patch -p1 < tools/ci/patches/0002-add-missing-unistd-headers.patch -d c-blosc/internal-complibs/zlib-*/ | ||
|
||
- name: Install pyodide-build | ||
run: python -m pip install pyodide-build | ||
|
||
- name: Build numcodecs for Pyodide/WASM | ||
run: pyodide build | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
|
||
- name: Set up Pyodide virtual environment and test numcodecs for Pyodide | ||
run: | | ||
# Pin to a specific version of Pyodide to ensure reliability | ||
pyodide xbuildenv install ${{ env.PYODIDE_VERSION }} | ||
|
||
# Set up Pyodide virtual environment and activate it | ||
pyodide venv .venv-pyodide | ||
source .venv-pyodide/bin/activate | ||
|
||
# For tests in test_zarr3.py | ||
pip install zarr==3.0.0b1 | ||
|
||
# Install the built numcodecs WASM wheel and relevant dependencies | ||
pip install $(ls dist/*.whl)"[msgpack,crc32c,test,test_extras]" | ||
# TODO: get zfpy built in Pyodide and install it here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# Change into a different directory before running tests to avoid | ||
# the test runner picking up the local numcodecs package | ||
cd docs | ||
|
||
# Don't use the cache provider plugin, as it doesn't currently work | ||
# with Pyodide: https://github.com/pypa/cibuildwheel/issues/1966 | ||
python -m pytest -p no:cacheprovider -svra --pyargs numcodecs |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,19 @@ | |
|
||
from __future__ import annotations | ||
|
||
# Short workaround for skipping the doctest above in a WASM environment | ||
# compiled via Emscripten where threads are not available, and accessing | ||
# the pytest config has no effect and ignoring warnings does not work. | ||
try: | ||
import pytest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would it take to not import pytest here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last time I checked, we would need a way to run this doctest and not raise a warning that gets converted to an error. The other way could be to not add this doctest here, which is not the best way to proceed. |
||
|
||
from numcodecs.tests.common import is_wasm | ||
|
||
if is_wasm: | ||
pytest.skip("zarr3 doctests not supported in WASM", allow_module_level=True) | ||
except (ImportError, ModuleNotFoundError): # not running tests | ||
pass | ||
|
||
import asyncio | ||
import math | ||
from dataclasses import dataclass, replace | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am also happy to upstream this patch (and the one below) to Blosc if it is suggested to do so. :) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
This patch disables multiprocessing and pthread for blosc. This file | ||
is adapted from and attributed to the Pyodide developers and can be | ||
viewed at the upstream Pyodide repository at the following link: | ||
|
||
https://github.com/pyodide/pyodide/blob/d32e376013d8977b66c6aa828042b1fee8047aea/packages/numcodecs/patches/fixblosc.patch | ||
|
||
|
||
diff --git a/c-blosc/blosc/blosc.h b/c-blosc/blosc/blosc.h | ||
index 40857d0..8a1e969 100644 | ||
--- a/c-blosc/blosc/blosc.h | ||
+++ b/c-blosc/blosc/blosc.h | ||
@@ -50,7 +50,7 @@ extern "C" { | ||
((INT_MAX - BLOSC_MAX_TYPESIZE * sizeof(int32_t)) / 3) | ||
|
||
/* The maximum number of threads (for some static arrays) */ | ||
-#define BLOSC_MAX_THREADS 256 | ||
+#define BLOSC_MAX_THREADS 1 | ||
|
||
/* Codes for shuffling (see blosc_compress) */ | ||
#define BLOSC_NOSHUFFLE 0 /* no shuffle */ | ||
|
||
diff --git a/c-blosc/blosc/blosc.c b/c-blosc/blosc/blosc.c | ||
index a5a5bd5..2a7797c 100644 | ||
--- a/c-blosc/blosc/blosc.c | ||
+++ b/c-blosc/blosc/blosc.c | ||
@@ -2236,6 +2236,7 @@ void blosc_atfork_child(void) { | ||
|
||
void blosc_init(void) | ||
{ | ||
+ g_initlib = 1; | ||
/* Return if we are already initialized */ | ||
if (g_initlib) return; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.