Skip to content

Commit 3b1b82a

Browse files
authored
Enable C++ tests for the Emscripten build (#277)
* Enable C++ tests for the Emscripten tests
1 parent 4ee2748 commit 3b1b82a

File tree

7 files changed

+87
-17
lines changed

7 files changed

+87
-17
lines changed

.github/workflows/main.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,19 @@ jobs:
247247
..
248248
emmake make -j ${{ env.ncpus }} install
249249
250-
- name: Jupyter Lite integration
250+
- name: Test xeus-cpp C++ Emscripten
251251
shell: bash -l {0}
252252
run: |
253+
set -e
253254
micromamba create -n xeus-lite-host jupyterlite-core
255+
micromamba activate xeus-lite-host
256+
cd build/test
257+
node test_xeus_cpp.js
258+
timeout-minutes: 4
259+
260+
- name: Jupyter Lite integration
261+
shell: bash -l {0}
262+
run: |
254263
micromamba activate xeus-lite-host
255264
python -m pip install jupyterlite-xeus
256265
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }}

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ if(EMSCRIPTEN)
8282
set(XEUS_CPP_BUILD_EXECUTABLE OFF)
8383
set(XEUS_CPP_USE_SHARED_XEUS OFF)
8484
set(XEUS_CPP_USE_SHARED_XEUS_CPP OFF)
85-
set(XEUS_CPP_BUILD_TESTS OFF)
8685
# ENV (https://github.com/emscripten-core/emscripten/commit/6d9681ad04f60b41ef6345ab06c29bbc9eeb84e0)
8786
set(EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \"EXPORTED_RUNTIME_METHODS=[ENV']\"")
8887
endif()

CONTRIBUTING.md

+6
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,9 @@ Once the Jupyter Lite site has built you can test the website locally by executi
106106
```bash
107107
jupyter lite serve --XeusAddon.prefix=$PREFIX
108108
```
109+
110+
To test the lite build you can execute the following to run the C++ tests built against emscripten
111+
```bash
112+
cd test
113+
node test_xeus_cpp.js
114+
```

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ Once the Jupyter Lite site has built you can test the website locally by executi
108108
jupyter lite serve --XeusAddon.prefix=$PREFIX
109109
```
110110

111+
To test the lite build you can execute the following to run the C++ tests built against emscripten
112+
```bash
113+
cd test
114+
node test_xeus_cpp.js
115+
```
116+
111117
## Trying it online
112118

113119
To try out xeus-cpp interactively in your web browser, just click on the binder link:

environment-wasm-host.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ dependencies:
99
- CppInterOp
1010
- cpp-argparse
1111
- pugixml
12+
- doctest

test/CMakeLists.txt

+50-15
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ include(CheckCXXCompilerFlag)
2525
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
2626

2727
if(CMAKE_CXX_COMPILER_ID MATCHES Clang OR CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Intel)
28-
add_compile_options(-Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion)
28+
29+
if(NOT EMSCRIPTEN)
30+
add_compile_options(-Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion)
31+
endif()
2932

3033
CHECK_CXX_COMPILER_FLAG(-march=native HAS_MARCH_NATIVE)
3134
if (HAS_MARCH_NATIVE)
@@ -39,7 +42,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
3942
endif()
4043

4144
find_package(doctest)
42-
find_package(Threads)
4345

4446
set(XEUS_CPP_TESTS
4547
main.cpp
@@ -48,22 +50,55 @@ set(XEUS_CPP_TESTS
4850

4951
add_executable(test_xeus_cpp ${XEUS_CPP_TESTS})
5052

51-
if (APPLE)
52-
set_target_properties(test_xeus_cpp PROPERTIES
53-
MACOSX_RPATH ON
53+
if(EMSCRIPTEN)
54+
target_link_libraries(test_xeus_cpp PRIVATE xeus-cpp-static doctest::doctest)
55+
56+
target_compile_options(test_xeus_cpp
57+
PUBLIC "SHELL: -fexceptions"
58+
)
59+
60+
target_link_options(test_xeus_cpp
61+
PUBLIC "SHELL: -fexceptions"
62+
PUBLIC "SHELL: -s MAIN_MODULE=1"
63+
PUBLIC "SHELL: -s WASM_BIGINT"
64+
PUBLIC "SHELL: -s ASSERTIONS=0"
65+
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
66+
PUBLIC "SHELL: -s EXIT_RUNTIME=1"
67+
PUBLIC "SHELL: -s STACK_SIZE=32mb"
68+
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
69+
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
70+
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_DATA_DIR}@/share/xeus-cpp"
71+
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_CONF_DIR}@/etc/xeus-cpp"
72+
)
73+
74+
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})
75+
76+
add_custom_command(TARGET test_xeus_cpp POST_BUILD
77+
COMMAND ${CMAKE_COMMAND} -E copy
78+
${CMAKE_INSTALL_PREFIX}/lib/libclangCppInterOp.so
79+
${CMAKE_CURRENT_BINARY_DIR}/libclangCppInterOp.so
80+
COMMENT "Copying libclangCppInterOp.so to the test directory"
5481
)
5582
else()
83+
find_package(Threads)
84+
85+
if (APPLE)
86+
set_target_properties(test_xeus_cpp PROPERTIES
87+
MACOSX_RPATH ON
88+
)
89+
else()
90+
set_target_properties(test_xeus_cpp PROPERTIES
91+
BUILD_WITH_INSTALL_RPATH 1
92+
SKIP_BUILD_RPATH FALSE
93+
)
94+
endif()
95+
5696
set_target_properties(test_xeus_cpp PROPERTIES
57-
BUILD_WITH_INSTALL_RPATH 1
58-
SKIP_BUILD_RPATH FALSE
97+
INSTALL_RPATH_USE_LINK_PATH TRUE
5998
)
60-
endif()
6199

62-
set_target_properties(test_xeus_cpp PROPERTIES
63-
INSTALL_RPATH_USE_LINK_PATH TRUE
64-
)
65-
66-
target_link_libraries(test_xeus_cpp xeus-cpp doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
67-
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})
100+
target_link_libraries(test_xeus_cpp xeus-cpp doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
101+
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})
68102

69-
add_custom_target(xtest COMMAND test_xeus_cpp DEPENDS test_xeus_cpp)
103+
add_custom_target(xtest COMMAND test_xeus_cpp DEPENDS test_xeus_cpp)
104+
endif()

test/test_interpreter.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ TEST_SUITE("execute_request")
169169

170170
TEST_SUITE("inspect_request")
171171
{
172+
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
173+
TEST_CASE("good_status"
174+
* doctest::should_fail(true)
175+
* doctest::description("TODO: Currently fails for the Emscripten build"))
176+
#else
172177
TEST_CASE("good_status")
178+
#endif
173179
{
174180
std::vector<const char*> Args = {/*"-v", "resource-dir", "....."*/};
175181
xcpp::interpreter interpreter((int)Args.size(), Args.data());
@@ -613,7 +619,13 @@ TEST_SUITE("xsystem_clone")
613619

614620
TEST_SUITE("xsystem_apply")
615621
{
622+
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
623+
TEST_CASE("apply_xsystem"
624+
* doctest::should_fail(true)
625+
* doctest::description("TODO: Currently fails for the Emscripten build"))
626+
#else
616627
TEST_CASE("apply_xsystem")
628+
#endif
617629
{
618630
xcpp::xsystem system;
619631
std::string code = "!echo Hello, World!";
@@ -842,6 +854,7 @@ TEST_SUITE("xinspect"){
842854
}
843855
}
844856

857+
#if !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
845858
TEST_SUITE("xassist"){
846859

847860
TEST_CASE("model_not_found"){
@@ -980,6 +993,7 @@ TEST_SUITE("xassist"){
980993
}
981994

982995
}
996+
#endif
983997

984998

985999
TEST_SUITE("file") {

0 commit comments

Comments
 (0)