Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/deploy-github-page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ jobs:
emmake make check-xeus-cpp -j ${{ env.ncpus }}
emmake make -j ${{ env.ncpus }} install

- name: Setup headless display
if: runner.os == 'Linux'
uses: pyvista/setup-headless-display-action@v5

- name: Test Emscripten xeus-cpp in browser
shell: bash -l {0}
run: |
Expand Down Expand Up @@ -111,9 +115,9 @@ jobs:

# Run tests in browsers
echo "Running test_xeus_cpp in Firefox"
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --browser-args="--headless" test_xeus_cpp.html
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="Google Chrome" --kill_exit --browser-args="--headless" test_xeus_cpp.html
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="Google Chrome" --kill_exit test_xeus_cpp.html
else
# Install Google Chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Expand All @@ -131,9 +135,13 @@ jobs:

# Run tests in browsers
echo "Running test_xeus_cpp in Firefox"
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
# Linux CI uses Mesa llvmpipe for software rendering. Chrome
# blocklists that driver and its Vulkan/compositing path fails on
# the virtual display, so allow the blocklisted driver and disable
# Vulkan and GPU compositing. macOS uses the native GPU instead.
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--no-sandbox --ignore-gpu-blocklist --disable-gpu-compositing --disable-features=Vulkan" test_xeus_cpp.html
fi
timeout-minutes: 4

Expand Down
19 changes: 14 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ jobs:
emmake make check-xeus-cpp -j ${{ env.ncpus }}
emmake make -j ${{ env.ncpus }} install

- name: Setup headless display
if: runner.os == 'Linux'
uses: pyvista/setup-headless-display-action@v5

- name: Test Emscripten xeus-cpp in browser
shell: bash -l {0}
run: |
Expand Down Expand Up @@ -309,14 +313,14 @@ jobs:

# Run tests in browsers
echo "Running test_xeus_cpp in Firefox"
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--no-sandbox" test_xeus_cpp.html
sudo safaridriver --enable
python -m ensurepip
python -m pip install selenium
echo "Running test_xeus_cpp in Safari"
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --no_browser --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html &
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --no_browser --kill_exit --timeout 60 test_xeus_cpp.html &
python ../../scripts/browser_tests_safari.py test_xeus_cpp.html
else
# Install Google Chrome
Expand All @@ -335,9 +339,14 @@ jobs:

# Run tests in browsers
echo "Running test_xeus_cpp in Firefox"
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
# Linux CI uses Mesa llvmpipe for software rendering:
# - --ignore-gpu-blocklist: Chrome otherwise rejects the software driver.
# - --disable-gpu-compositing: the llvmpipe compositing path fails.
# - --disable-features=Vulkan: Chrome's Vulkan path fails on this display.
# macOS uses its native GPU and needs none of these flags.
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--no-sandbox --ignore-gpu-blocklist --disable-gpu-compositing --disable-features=Vulkan" test_xeus_cpp.html
Comment thread
mcbarton marked this conversation as resolved.
Resolved
fi
timeout-minutes: 4

Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,24 @@ endif()

if(EMSCRIPTEN)
include(WasmBuildOptions)
include(XeusCppWasm)
find_package(xeus-lite ${xeus_lite_REQUIRED_VERSION} REQUIRED)
add_executable(xcpp src/main_emscripten_kernel.cpp )
target_link_libraries(xcpp PRIVATE xeus-lite)
xeus_cpp_set_kernel_options(xcpp)
xeus_wasm_compile_options(xcpp)
xeus_wasm_link_options(xcpp "web,worker")
# Emscripten-only WebGL flags. Native builds must not receive these.
message(STATUS "Enabling WebGL2/OffscreenCanvas support for xcpp")
set(XEUS_CPP_WASM_WEBGL_LINK_OPTIONS
"SHELL: -s GL_ENABLE_GET_PROC_ADDRESS=1"
"SHELL: -s OFFSCREENCANVAS_SUPPORT=1"
"SHELL: -s MAX_WEBGL_VERSION=2"
"SHELL: -s FULL_ES3=1"
"SHELL: -Wl,--undefined=emscripten_webgl2_get_proc_address"
)
target_link_options(xcpp PUBLIC ${XEUS_CPP_WASM_WEBGL_LINK_OPTIONS})
xeus_cpp_wasm_append_runtime_method(xcpp GL)
string(REPLACE "@" "@@" ESCAPED_SYSROOT_PATH "${SYSROOT_PATH}")
string(REPLACE "@" "@@" ESCAPED_XEUS_CPP_RESOURCE_DIR "${XEUS_CPP_RESOURCE_DIR}")
string(REPLACE "\\" "/" ESCAPED_XEUS_CPP_RESOURCE_DIR "${ESCAPED_XEUS_CPP_RESOURCE_DIR}")
Expand Down
20 changes: 14 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ emmake make check-xeus-cpp
emmake make install
```

It is possible to run the Emscripten tests in a headless browser. We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this for Chrome and Firefox on MacOS execute the following from the build folder
The Emscripten tests can be run in a browser. We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this for Chrome and Firefox on MacOS execute the following from the build folder

```bash
cd test
Expand All @@ -115,9 +115,9 @@ export PATH="$PWD:$PATH"
cd –

echo "Running test_xeus_cpp in Firefox"
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --browser-args="--headless" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python $BUILD_PREFIX/bin/emrun.py --browser="Google Chrome" --kill_exit --browser-args="--headless --no-sandbox" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--no-sandbox" test_xeus_cpp.html
```

To run tests in Safari you can make use of safaridriver. How to enable this will depend on
Expand All @@ -126,7 +126,7 @@ python package. This only needs to be enable once, and then you can execute the

```bash
echo "Running test_xeus_cpp in Safari"
python $BUILD_PREFIX/bin/emrun.py --no_browser --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html &
python $BUILD_PREFIX/bin/emrun.py --no_browser --kill_exit --timeout 60 test_xeus_cpp.html &
python ../../scripts/browser_tests_safari.py test_xeus_cpp.html
```

Expand All @@ -147,11 +147,19 @@ export PATH="$PWD:$PATH"
cd -

echo "Running test_xeus_cpp in Firefox"
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python $BUILD_PREFIX/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--no-sandbox --ignore-gpu-blocklist --disable-gpu-compositing --disable-features=Vulkan" test_xeus_cpp.html
```

When Chrome runs on a Linux CI display backed by Mesa llvmpipe, these flags are required:

- `--ignore-gpu-blocklist`: Chrome blocks llvmpipe as a software renderer. Without this flag, WebGL2 context creation fails.
- `--disable-gpu-compositing`: Chrome's llvmpipe compositing path fails. Disabling it keeps rendering on the working GL path.
- `--disable-features=Vulkan`: Chrome's Vulkan path fails on this display. Disabling it forces the GL path.

macOS uses the native GPU and does not need these flags.

To build and test Jupyter Lite with this kernel locally you can execute the following
```bash
micromamba create -n xeus-lite-host jupyter_server jupyterlite-xeus -c conda-forge
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ emmake make check-xeus-cpp
emmake make install
```

It is possible to run the Emscripten tests in a headless browser. We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this for Chrome and Firefox on MacOS execute the following from the build folder
The Emscripten tests can be run in a browser. We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this for Chrome and Firefox on MacOS execute the following from the build folder

```bash
cd test
Expand All @@ -130,9 +130,9 @@ export PATH="$PWD:$PATH"
cd -

echo "Running test_xeus_cpp in Firefox"
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python python $BUILD_PREFIX/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--no-sandbox" test_xeus_cpp.html
```

To run tests in Safari you can make use of safaridriver. How to enable this will depend on
Expand All @@ -141,7 +141,7 @@ python package. This only needs to be enable once, and then you can execute the

```bash
echo "Running test_xeus_cpp in Safari"
python $BUILD_PREFIX/bin/emrun.py --no_browser --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html &
python $BUILD_PREFIX/bin/emrun.py --no_browser --kill_exit --timeout 60 test_xeus_cpp.html &
python ../../scripts/browser_tests_safari.py test_xeus_cpp.html
```

Expand All @@ -162,11 +162,19 @@ export PATH="$PWD:$PATH"
cd -

echo "Running test_xeus_cpp in Firefox"
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python $BUILD_PREFIX/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--no-sandbox --ignore-gpu-blocklist --disable-gpu-compositing --disable-features=Vulkan" test_xeus_cpp.html
```

When Chrome runs on a Linux CI display backed by Mesa llvmpipe, these flags are required:

- `--ignore-gpu-blocklist`: Chrome blocks llvmpipe as a software renderer. Without this flag, WebGL2 context creation fails.
- `--disable-gpu-compositing`: Chrome's llvmpipe compositing path fails. Disabling it keeps rendering on the working GL path.
- `--disable-features=Vulkan`: Chrome's Vulkan path fails on this display. Disabling it forces the GL path.

macOS uses the native GPU and does not need these flags.

To build and test Jupyter Lite with this kernel locally you can execute the following
```bash
micromamba create -n xeus-lite-host jupyter_server jupyterlite-xeus -c conda-forge
Expand Down
53 changes: 53 additions & 0 deletions cmake/XeusCppWasm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Append one method to the EXPORTED_RUNTIME_METHODS link option already present
# on a target. This preserves methods exported by xeus_wasm_link_options and
# avoids maintaining a duplicate copy of the baseline list.
#
# Sets XEUS_CPP_WASM_EXPORTED_RUNTIME_METHODS in the caller scope so other
# targets (for example tests) can reuse the rewritten option.
function(xeus_cpp_wasm_append_runtime_method target method)
get_target_property(link_options ${target} LINK_OPTIONS)
if(NOT link_options)
message(FATAL_ERROR
"xeus-cpp: ${target} has no LINK_OPTIONS; "
"xeus_wasm_link_options() must run first"
)
endif()

set(updated_options)
set(runtime_methods_option "")
foreach(option IN LISTS link_options)
if(option MATCHES "EXPORTED_RUNTIME_METHODS='\\[(.*)\\]'")
if(runtime_methods_option)
message(FATAL_ERROR
"xeus-cpp: ${target} has multiple EXPORTED_RUNTIME_METHODS options"
)
endif()

# CMAKE_MATCH_1 is the JSON array contents without the brackets.
string(REPLACE "\"" "" methods "${CMAKE_MATCH_1}")
string(REPLACE "," ";" methods "${methods}")
list(TRANSFORM methods STRIP)
list(APPEND methods "${method}")
list(REMOVE_DUPLICATES methods)
string(REPLACE ";" "\",\"" methods "${methods}")
set(runtime_methods_option
"SHELL: -s EXPORTED_RUNTIME_METHODS='[\"${methods}\"]'"
)
list(APPEND updated_options "${runtime_methods_option}")
else()
list(APPEND updated_options "${option}")
endif()
endforeach()

if(NOT runtime_methods_option)
message(FATAL_ERROR
"xeus-cpp: ${target} does not export EXPORTED_RUNTIME_METHODS, the xeus wasm link options changed"
)
endif()

set_target_properties(${target} PROPERTIES LINK_OPTIONS "${updated_options}")
set(XEUS_CPP_WASM_EXPORTED_RUNTIME_METHODS
"${runtime_methods_option}"
PARENT_SCOPE
)
endfunction()
20 changes: 14 additions & 6 deletions docs/source/InstallationAndUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ You are now in a position to build the xeus-cpp kernel. You build and test it in
emmake make check-xeus-cpp
emmake make install

It is possible to run the Emscripten tests in a headless browser. We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this for Chrome and Firefox on MacOS execute the following from the build folder
The Emscripten tests can be run in a browser. We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this for Chrome and Firefox on MacOS execute the following from the build folder

.. code-block:: bash

Expand All @@ -111,9 +111,9 @@ It is possible to run the Emscripten tests in a headless browser. We will run ou
cd -

echo "Running test_xeus_cpp in Firefox"
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python $BUILD_PREFIX/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--no-sandbox" test_xeus_cpp.html

To run tests in Safari you can make use of safaridriver. How to enable this will depend on
your MacOS operating system, and is best to consult `safaridriver <https://developer.apple.com/documentation/webkit/testing-with-webdriver-in-safari>`_. You will also need to install the Selenium
Expand All @@ -122,7 +122,7 @@ python package. This only needs to be enable once, and then you can execute the
.. code-block:: bash

echo "Running test_xeus_cpp in Safari"
python $BUILD_PREFIX/bin/emrun.py --no_browser --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html &
python $BUILD_PREFIX/bin/emrun.py --no_browser --kill_exit --timeout 60 test_xeus_cpp.html &
python ../../scripts/browser_tests_safari.py test_xeus_cpp.html

To run the browser tests on Ubuntu x86 execute the following from the build folder
Expand All @@ -143,9 +143,17 @@ To run the browser tests on Ubuntu x86 execute the following from the build fold
cd -

echo "Running test_xeus_cpp in Firefox"
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 test_xeus_cpp.html
echo "Running test_xeus_cpp in Google Chrome"
python $BUILD_PREFIX/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
python $BUILD_PREFIX/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--no-sandbox --ignore-gpu-blocklist --disable-gpu-compositing --disable-features=Vulkan" test_xeus_cpp.html

When Chrome runs on a Linux CI display backed by Mesa llvmpipe, these flags are required:

- ``--ignore-gpu-blocklist``: Chrome blocks llvmpipe as a software renderer. Without this flag, WebGL2 context creation fails.
- ``--disable-gpu-compositing``: Chrome's llvmpipe compositing path fails. Disabling it keeps rendering on the working GL path.
- ``--disable-features=Vulkan``: Chrome's Vulkan path fails on this display. Disabling it forces the GL path.

macOS uses the native GPU and does not need these flags.

To build and test Jupyter Lite with this kernel locally you can execute the following

Expand Down
9 changes: 9 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ set(XEUS_CPP_TESTS
test_interpreter.cpp
)

if(EMSCRIPTEN)
list(APPEND XEUS_CPP_TESTS test_webgl.cpp)
endif()

add_executable(test_xeus_cpp ${XEUS_CPP_TESTS})

if(EMSCRIPTEN)
Expand Down Expand Up @@ -78,6 +82,11 @@ if(EMSCRIPTEN)

target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})

target_link_options(test_xeus_cpp PUBLIC
${XEUS_CPP_WASM_WEBGL_LINK_OPTIONS}
"${XEUS_CPP_WASM_EXPORTED_RUNTIME_METHODS}"
)

add_custom_command(TARGET test_xeus_cpp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_INSTALL_PREFIX}/lib/libclangCppInterOp.so
Expand Down
Loading
Loading