diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5b032f0c..1217f323 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 25e22a5f..da8d5d76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9a9e4c39..5f2f1124 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 +``` \ No newline at end of file diff --git a/README.md b/README.md index 61880552..a3b88384 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/environment-wasm-host.yml b/environment-wasm-host.yml index 896ea48d..1ee5997c 100644 --- a/environment-wasm-host.yml +++ b/environment-wasm-host.yml @@ -9,3 +9,4 @@ dependencies: - CppInterOp - cpp-argparse - pugixml + - doctest diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8ef68992..88e8be76 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) @@ -39,7 +42,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC) endif() find_package(doctest) -find_package(Threads) set(XEUS_CPP_TESTS main.cpp @@ -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() diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index 6e7f90fd..fd18eb35 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -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 Args = {/*"-v", "resource-dir", "....."*/}; xcpp::interpreter interpreter((int)Args.size(), Args.data()); @@ -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!"; @@ -842,6 +854,7 @@ TEST_SUITE("xinspect"){ } } +#if !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD) TEST_SUITE("xassist"){ TEST_CASE("model_not_found"){ @@ -980,6 +993,7 @@ TEST_SUITE("xassist"){ } } +#endif TEST_SUITE("file") {