Skip to content

Commit 1932d36

Browse files
committed
tests: run on pyodide
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent b33d06f commit 1932d36

File tree

7 files changed

+96
-3
lines changed

7 files changed

+96
-3
lines changed

.github/workflows/emscripten.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: WASM
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- master
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build-wasm-emscripten:
15+
name: Pyodide wheel
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
submodules: true
21+
fetch-depth: 0
22+
23+
- uses: actions/setup-python@v4
24+
with:
25+
python-version: "3.11"
26+
27+
- name: Install pyodide-build
28+
run: pip install pyodide-build==0.23.4
29+
30+
- name: Compute emsdk version
31+
id: compute-emsdk-version
32+
run: |
33+
# Prepare xbuild environment (side-effect)
34+
pyodide config list
35+
# Save EMSDK version
36+
EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version)
37+
echo "emsdk-version=$EMSCRIPTEN_VERSION" >> $GITHUB_OUTPUT
38+
39+
- uses: mymindstorm/setup-emsdk@v12
40+
with:
41+
version: ${{ steps.compute-emsdk-version.outputs.emsdk-version }}
42+
actions-cache-folder: emsdk-cache
43+
44+
- name: Build
45+
run: PYODIDE_BUILD_EXPORTS=whole_archive CFLAGS=-fexceptions LDFLAGS=-fexceptions pyodide build
46+
working-directory: tests
47+
48+
- uses: actions/setup-node@v3
49+
with:
50+
node-version: 18
51+
52+
- name: Set up Pyodide virtual environment
53+
run: |
54+
pyodide venv .venv-pyodide
55+
.venv-pyodide/bin/pip install $(echo -n tests/dist/*.whl)
56+
57+
- name: Test
58+
run: .venv-pyodide/bin/pytest

include/pybind11/pybind11.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class cpp_function : public function {
222222

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

227227
/* Try to cast the function arguments into the C++ domain */
228228
if (!args_converter.load_args(call)) {

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ log_cli_level = "info"
3939
testpaths = [
4040
"tests",
4141
]
42-
timeout=300
42+
# timeout=300
4343

4444

4545
[tool.pylint]

tests/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ set(PYBIND11_TEST_FILTER
8888
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
8989
# We're being loaded directly, i.e. not via add_subdirectory, so make this
9090
# work as its own project and load the pybind11Config to get the tools we need
91-
find_package(pybind11 REQUIRED CONFIG)
91+
92+
if(SKBUILD)
93+
add_subdirectory(.. pybind11_src)
94+
else()
95+
find_package(pybind11 REQUIRED CONFIG)
96+
endif()
9297
endif()
9398

9499
if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES)
@@ -488,6 +493,9 @@ foreach(target ${test_targets})
488493
endforeach()
489494
endif()
490495
endif()
496+
if(SKBUILD)
497+
install(TARGETS ${target} LIBRARY DESTINATION .)
498+
endif()
491499
endforeach()
492500

493501
# Provide nice organisation in IDEs

tests/pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Warning: this is currently used for pyodide, and is not a general out-of-tree
2+
# builder for the tests (yet). Specifically, wheels can't be built from SDists.
3+
4+
[build-system]
5+
requires = ["scikit-build-core[pyproject]"]
6+
build-backend = "scikit_build_core.build"
7+
8+
[project]
9+
name = "pybind11_tests"
10+
version = "0.0.1"
11+
dependencies = ["pytest", "pytest-timeout"]

tests/test_embed/test_interpreter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import sys
22

3+
import pytest
4+
5+
if sys.platform.startswith("emscripten"):
6+
pytest.skip(
7+
"Test not implemented from single wheel on Pyodide", allow_module_level=True
8+
)
9+
310
from widget_module import Widget
411

512

tests/test_embed/test_trampoline.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import sys
2+
3+
import pytest
4+
5+
if sys.platform.startswith("emscripten"):
6+
pytest.skip(
7+
"Test not implemented from single wheel on Pyodide", allow_module_level=True
8+
)
9+
110
import trampoline_module
211

312

0 commit comments

Comments
 (0)