|
| 1 | +import nox |
1 | 2 | import os |
| 3 | +import sys |
2 | 4 | import tarfile |
3 | 5 | from glob import glob |
4 | 6 | from pathlib import Path |
5 | 7 |
|
6 | | -import nox |
7 | | - |
8 | 8 |
|
9 | 9 | @nox.session(name="test-examples", venv_backend="none") |
10 | 10 | def test_examples(session: nox.Session): |
@@ -35,3 +35,51 @@ def mypy(session: nox.Session): |
35 | 35 | def test(session: nox.Session): |
36 | 36 | session.install("pytest", ".") |
37 | 37 | session.run("pytest", "setuptools_rust", *session.posargs) |
| 38 | + |
| 39 | + |
| 40 | +@nox.session(name="test-examples-emscripten") |
| 41 | +def test_examples_emscripten(session: nox.Session): |
| 42 | + session.install(".") |
| 43 | + emscripten_dir = Path("./emscripten").resolve() |
| 44 | + |
| 45 | + session.run( |
| 46 | + "rustup", |
| 47 | + "component", |
| 48 | + "add", |
| 49 | + "rust-src", |
| 50 | + "--toolchain", |
| 51 | + "nightly", |
| 52 | + external=True, |
| 53 | + ) |
| 54 | + examples_dir = Path("examples") |
| 55 | + test_crates = [ |
| 56 | + examples_dir / "html-py-ever", |
| 57 | + examples_dir / "namespace_package", |
| 58 | + ] |
| 59 | + for example in test_crates: |
| 60 | + env = os.environ.copy() |
| 61 | + env.update( |
| 62 | + RUSTUP_TOOLCHAIN="nightly", |
| 63 | + _SETUPTOOLSRUST_BUILD_STD="1", |
| 64 | + PYTHONPATH=str(emscripten_dir), |
| 65 | + _PYTHON_SYSCONFIGDATA_NAME="_sysconfigdata__emscripten_wasm32-emscripten", |
| 66 | + _PYTHON_HOST_PLATFORM="emscripten_3_1_14_wasm32", |
| 67 | + CARGO_BUILD_TARGET="wasm32-unknown-emscripten", |
| 68 | + CARGO_UNSTABLE_BUILD_STD="true", |
| 69 | + CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_LINKER=str( |
| 70 | + emscripten_dir / "emcc_wrapper.py" |
| 71 | + ), |
| 72 | + PYO3_CONFIG_FILE=str(emscripten_dir / "pyo3_config.ini"), |
| 73 | + RUSTFLAGS=" ".join( |
| 74 | + [ |
| 75 | + "-C relocation-model=pic", |
| 76 | + "-C link-arg=-sSIDE_MODULE=2", |
| 77 | + "-C link-arg=-sWASM_BIGINT", |
| 78 | + ] |
| 79 | + ), |
| 80 | + ) |
| 81 | + with session.chdir(example): |
| 82 | + session.run("python", "setup.py", "bdist_wheel", env=env, external=True) |
| 83 | + |
| 84 | + with session.chdir(emscripten_dir): |
| 85 | + session.run("node", "runner.js", str(example), external=True) |
0 commit comments