Skip to content

Commit

Permalink
tests: run on pyodide
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Jul 14, 2023
1 parent b33d06f commit 1932d36
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 3 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/emscripten.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: WASM

on:
workflow_dispatch:
pull_request:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-wasm-emscripten:
name: Pyodide wheel
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: "3.11"

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

- name: Compute emsdk version
id: compute-emsdk-version
run: |
# Prepare xbuild environment (side-effect)
pyodide config list
# Save EMSDK version
EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version)
echo "emsdk-version=$EMSCRIPTEN_VERSION" >> $GITHUB_OUTPUT
- uses: mymindstorm/setup-emsdk@v12
with:
version: ${{ steps.compute-emsdk-version.outputs.emsdk-version }}
actions-cache-folder: emsdk-cache

- name: Build
run: PYODIDE_BUILD_EXPORTS=whole_archive CFLAGS=-fexceptions LDFLAGS=-fexceptions pyodide build
working-directory: tests

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Set up Pyodide virtual environment
run: |
pyodide venv .venv-pyodide
.venv-pyodide/bin/pip install $(echo -n tests/dist/*.whl)
- name: Test
run: .venv-pyodide/bin/pytest
2 changes: 1 addition & 1 deletion include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class cpp_function : public function {

/* Dispatch code which converts function arguments and performs the actual function call */
rec->impl = [](function_call &call) -> handle {
cast_in args_converter;
cast_in args_converter{};

/* Try to cast the function arguments into the C++ domain */
if (!args_converter.load_args(call)) {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ log_cli_level = "info"
testpaths = [
"tests",
]
timeout=300
# timeout=300


[tool.pylint]
Expand Down
10 changes: 9 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ set(PYBIND11_TEST_FILTER
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
# We're being loaded directly, i.e. not via add_subdirectory, so make this
# work as its own project and load the pybind11Config to get the tools we need
find_package(pybind11 REQUIRED CONFIG)

if(SKBUILD)
add_subdirectory(.. pybind11_src)
else()
find_package(pybind11 REQUIRED CONFIG)
endif()
endif()

if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES)
Expand Down Expand Up @@ -488,6 +493,9 @@ foreach(target ${test_targets})
endforeach()
endif()
endif()
if(SKBUILD)
install(TARGETS ${target} LIBRARY DESTINATION .)
endif()
endforeach()

# Provide nice organisation in IDEs
Expand Down
11 changes: 11 additions & 0 deletions tests/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Warning: this is currently used for pyodide, and is not a general out-of-tree
# builder for the tests (yet). Specifically, wheels can't be built from SDists.

[build-system]
requires = ["scikit-build-core[pyproject]"]
build-backend = "scikit_build_core.build"

[project]
name = "pybind11_tests"
version = "0.0.1"
dependencies = ["pytest", "pytest-timeout"]
7 changes: 7 additions & 0 deletions tests/test_embed/test_interpreter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import sys

import pytest

if sys.platform.startswith("emscripten"):
pytest.skip(
"Test not implemented from single wheel on Pyodide", allow_module_level=True
)

from widget_module import Widget


Expand Down
9 changes: 9 additions & 0 deletions tests/test_embed/test_trampoline.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import sys

import pytest

if sys.platform.startswith("emscripten"):
pytest.skip(
"Test not implemented from single wheel on Pyodide", allow_module_level=True
)

import trampoline_module


Expand Down

0 comments on commit 1932d36

Please sign in to comment.