-
Notifications
You must be signed in to change notification settings - Fork 106
Add CI tests for wasm32-emscripten wheels in Pyodide #244
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
Changes from 3 commits
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,6 @@ | ||
| builddir | ||
| main.* | ||
| !main.c | ||
| pybuilddir.txt | ||
| pyodide | ||
| node_modules |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # system configuration generated and used by the sysconfig module | ||
| build_time_vars = { | ||
| "ABIFLAGS": "", | ||
| "AR": "/src/emsdk/emsdk/upstream/emscripten/emar", | ||
| "ARFLAGS": "rcs", | ||
| "BLDSHARED": "emcc -sSIDE_MODULE=1 -L/src/emscripten/python-lib/", | ||
| "CC": "emcc -I/src/emscripten/python-include/", | ||
| "CCSHARED": "", | ||
| "CFLAGS": "-Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g " | ||
| "-fwrapv -O3 -Wall -O2 -g0 -fPIC", | ||
| "EXT_SUFFIX": ".cpython-310-wasm32-emscripten.so", | ||
| "HOST_GNU_TYPE": "wasm32-unknown-emscripten", | ||
| "LDSHARED": "emcc -sSIDE_MODULE=1", | ||
| "Py_DEBUG": "0", | ||
| "py_version_nodot": "310", | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/usr/bin/env python3 | ||
| import subprocess | ||
| import sys | ||
|
|
||
|
|
||
| def update_args(args): | ||
| # remove -lc. Not sure if it makes a difference but -lc doesn't belong here. | ||
| # https://github.com/emscripten-core/emscripten/issues/17191 | ||
| for i in reversed(range(len(args))): | ||
| if args[i] == "c" and args[i - 1] == "-l": | ||
| del args[i - 1 : i + 1] | ||
|
|
||
| return args | ||
|
|
||
|
|
||
| def main(args): | ||
| args = update_args(args) | ||
| return subprocess.call(["emcc"] + args) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| args = sys.argv[1:] | ||
| sys.exit(main(args)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| implementation=CPython | ||
| version=3.10 | ||
| shared=true | ||
| abi3=false | ||
| lib_name=python3.10 | ||
| pointer_width=32 | ||
| suppress_build_script_link_lines=false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| const { opendir } = require("node:fs/promises"); | ||
| const { loadPyodide } = require("pyodide"); | ||
|
|
||
| async function findWheel(distDir) { | ||
| const dir = await opendir(distDir); | ||
| for await (const dirent of dir) { | ||
| if (dirent.name.endsWith("whl")) { | ||
| return dirent.name; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const pkgDir = process.argv[2]; | ||
| const distDir = pkgDir + "/dist"; | ||
| const testDir = pkgDir + "/tests"; | ||
|
|
||
| async function main() { | ||
| const wheelName = await findWheel(distDir); | ||
| const wheelURL = `file:${distDir}/${wheelName}`; | ||
|
|
||
| try { | ||
| pyodide = await loadPyodide(); | ||
| const FS = pyodide.FS; | ||
| const NODEFS = FS.filesystems.NODEFS; | ||
| FS.mkdir("/test_dir"); | ||
| FS.mount(NODEFS, { root: testDir }, "/test_dir"); | ||
| await pyodide.loadPackage(["micropip", "pytest", "tomli"]); | ||
| const micropip = pyodide.pyimport("micropip"); | ||
| await micropip.install(wheelURL); | ||
| const pytest = pyodide.pyimport("pytest"); | ||
| errcode = pytest.main(pyodide.toPy(["/test_dir", "-vv"])); | ||
| } catch (e) { | ||
| console.error(e); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| main(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import sys | ||
| import pytest | ||
|
|
||
| if sys.platform == "emscripten": | ||
|
|
||
| @pytest.fixture | ||
| def benchmark(): | ||
| def result(func, *args, **kwargs): | ||
| return func(*args, **kwargs) | ||
|
|
||
| return result |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import os | ||
| import sys | ||
| import tarfile | ||
| from glob import glob | ||
| from pathlib import Path | ||
|
|
@@ -73,3 +74,42 @@ def chdir(path: Path): | |
| session.install("pytest", "cffi") | ||
| session.install("--no-build-isolation", str(examples / "html-py-ever")) | ||
| session.run("pytest", str(examples / "html-py-ever")) | ||
|
|
||
|
|
||
| @nox.session(name="test-examples-emscripten") | ||
| def test_examples_emscripten(session: nox.Session): | ||
| session.install(".") | ||
| emscripten_dir = Path("./emscripten").resolve() | ||
|
|
||
| session.run( | ||
| "rustup", | ||
| "component", | ||
| "add", | ||
| "rust-src", | ||
| "--toolchain", | ||
| "nightly", | ||
| external=True, | ||
| ) | ||
| examples_dir = Path("examples").absolute() | ||
| test_crates = [ | ||
| examples_dir / "html-py-ever", | ||
| examples_dir / "namespace_package", | ||
| ] | ||
| for example in test_crates: | ||
| env = os.environ.copy() | ||
| env.update( | ||
| RUSTUP_TOOLCHAIN="nightly", | ||
| PYTHONPATH=str(emscripten_dir), | ||
| _PYTHON_SYSCONFIGDATA_NAME="_sysconfigdata__emscripten_wasm32-emscripten", | ||
| _PYTHON_HOST_PLATFORM="emscripten_3_1_14_wasm32", | ||
| CARGO_BUILD_TARGET="wasm32-unknown-emscripten", | ||
| CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_LINKER=str( | ||
| emscripten_dir / "emcc_wrapper.py" | ||
| ), | ||
| PYO3_CONFIG_FILE=str(emscripten_dir / "pyo3_config.ini"), | ||
|
Member
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. From this should I infer that
Contributor
Author
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 not sure. I think it may just be that I don't know how to use the tool correctly. How would I check this?
Member
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. So usually in cross-compile situations like for emscripten the I view the |
||
| ) | ||
| with session.chdir(example): | ||
| session.run("python", "setup.py", "bdist_wheel", env=env, external=True) | ||
|
|
||
| with session.chdir(emscripten_dir): | ||
| session.run("node", "runner.js", str(example), external=True) | ||
Uh oh!
There was an error while loading. Please reload this page.