Skip to content

Enable C++ tests for the Emscripten build #277

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

Merged
merged 8 commits into from
Apr 2, 2025
Merged
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
11 changes: 10 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,19 @@ jobs:
..
emmake make -j ${{ env.ncpus }} install

- name: Jupyter Lite integration
- name: Test xeus-cpp C++ Emscripten
shell: bash -l {0}
run: |
set -e
micromamba create -n xeus-lite-host jupyterlite-core
micromamba activate xeus-lite-host
cd build/test
node test_xeus_cpp.js
timeout-minutes: 4

- name: Jupyter Lite integration
shell: bash -l {0}
run: |
micromamba activate xeus-lite-host
python -m pip install jupyterlite-xeus
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }}
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ if(EMSCRIPTEN)
set(XEUS_CPP_BUILD_EXECUTABLE OFF)
set(XEUS_CPP_USE_SHARED_XEUS OFF)
set(XEUS_CPP_USE_SHARED_XEUS_CPP OFF)
set(XEUS_CPP_BUILD_TESTS OFF)
# ENV (https://github.com/emscripten-core/emscripten/commit/6d9681ad04f60b41ef6345ab06c29bbc9eeb84e0)
set(EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \"EXPORTED_RUNTIME_METHODS=[ENV']\"")
endif()
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ Once the Jupyter Lite site has built you can test the website locally by executi
```bash
jupyter lite serve --XeusAddon.prefix=$PREFIX
```

To test the lite build you can execute the following to run the C++ tests built against emscripten
```bash
cd test
node test_xeus_cpp.js
```
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ Once the Jupyter Lite site has built you can test the website locally by executi
jupyter lite serve --XeusAddon.prefix=$PREFIX
```

To test the lite build you can execute the following to run the C++ tests built against emscripten
```bash
cd test
node test_xeus_cpp.js
```

## Trying it online

To try out xeus-cpp interactively in your web browser, just click on the binder link:
Expand Down
1 change: 1 addition & 0 deletions environment-wasm-host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dependencies:
- CppInterOp
- cpp-argparse
- pugixml
- doctest
65 changes: 50 additions & 15 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ include(CheckCXXCompilerFlag)
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)

if(CMAKE_CXX_COMPILER_ID MATCHES Clang OR CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Intel)
add_compile_options(-Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion)

if(NOT EMSCRIPTEN)
add_compile_options(-Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion)
endif()

CHECK_CXX_COMPILER_FLAG(-march=native HAS_MARCH_NATIVE)
if (HAS_MARCH_NATIVE)
Expand All @@ -39,7 +42,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
endif()

find_package(doctest)
find_package(Threads)

set(XEUS_CPP_TESTS
main.cpp
Expand All @@ -48,22 +50,55 @@ set(XEUS_CPP_TESTS

add_executable(test_xeus_cpp ${XEUS_CPP_TESTS})

if (APPLE)
set_target_properties(test_xeus_cpp PROPERTIES
MACOSX_RPATH ON
if(EMSCRIPTEN)
target_link_libraries(test_xeus_cpp PRIVATE xeus-cpp-static doctest::doctest)

target_compile_options(test_xeus_cpp
PUBLIC "SHELL: -fexceptions"
)

target_link_options(test_xeus_cpp
PUBLIC "SHELL: -fexceptions"
PUBLIC "SHELL: -s MAIN_MODULE=1"
PUBLIC "SHELL: -s WASM_BIGINT"
PUBLIC "SHELL: -s ASSERTIONS=0"
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
PUBLIC "SHELL: -s EXIT_RUNTIME=1"
PUBLIC "SHELL: -s STACK_SIZE=32mb"
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_DATA_DIR}@/share/xeus-cpp"
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_CONF_DIR}@/etc/xeus-cpp"
)

target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})

add_custom_command(TARGET test_xeus_cpp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_INSTALL_PREFIX}/lib/libclangCppInterOp.so
${CMAKE_CURRENT_BINARY_DIR}/libclangCppInterOp.so
COMMENT "Copying libclangCppInterOp.so to the test directory"
)
else()
find_package(Threads)

if (APPLE)
set_target_properties(test_xeus_cpp PROPERTIES
MACOSX_RPATH ON
)
else()
set_target_properties(test_xeus_cpp PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
SKIP_BUILD_RPATH FALSE
)
endif()

set_target_properties(test_xeus_cpp PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
SKIP_BUILD_RPATH FALSE
INSTALL_RPATH_USE_LINK_PATH TRUE
)
endif()

set_target_properties(test_xeus_cpp PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
)

target_link_libraries(test_xeus_cpp xeus-cpp doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})
target_link_libraries(test_xeus_cpp xeus-cpp doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})

add_custom_target(xtest COMMAND test_xeus_cpp DEPENDS test_xeus_cpp)
add_custom_target(xtest COMMAND test_xeus_cpp DEPENDS test_xeus_cpp)
endif()
14 changes: 14 additions & 0 deletions test/test_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ TEST_SUITE("execute_request")

TEST_SUITE("inspect_request")
{
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
TEST_CASE("good_status"
* doctest::should_fail(true)
* doctest::description("TODO: Currently fails for the Emscripten build"))
#else
TEST_CASE("good_status")
#endif
{
std::vector<const char*> Args = {/*"-v", "resource-dir", "....."*/};
xcpp::interpreter interpreter((int)Args.size(), Args.data());
Expand Down Expand Up @@ -613,7 +619,13 @@ TEST_SUITE("xsystem_clone")

TEST_SUITE("xsystem_apply")
{
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
TEST_CASE("apply_xsystem"
* doctest::should_fail(true)
* doctest::description("TODO: Currently fails for the Emscripten build"))
#else
TEST_CASE("apply_xsystem")
#endif
{
xcpp::xsystem system;
std::string code = "!echo Hello, World!";
Expand Down Expand Up @@ -842,6 +854,7 @@ TEST_SUITE("xinspect"){
}
}

#if !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
TEST_SUITE("xassist"){

TEST_CASE("model_not_found"){
Expand Down Expand Up @@ -980,6 +993,7 @@ TEST_SUITE("xassist"){
}

}
#endif


TEST_SUITE("file") {
Expand Down
Loading