@@ -84,15 +84,15 @@ if(EMSCRIPTEN)
8484 set (XEUS_CPP_USE_SHARED_XEUS_CPP OFF )
8585 set (XEUS_CPP_BUILD_TESTS OFF )
8686 # ENV (https://github.com/emscripten-core/emscripten/commit/6d9681ad04f60b41ef6345ab06c29bbc9eeb84e0)
87- set (EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \" EXTRA_EXPORTED_RUNTIME_METHODS =[ENV']\" " )
87+ set (EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \" EXPORTED_RUNTIME_METHODS =[ENV']\" " )
8888endif ()
8989
9090# Dependencies
9191# ============
9292
9393set (xeus_REQUIRED_VERSION 5.0.0)
9494set (xeus_zmq_REQUIRED_VERSION 3.0.0)
95- set (CppInterOp_REQUIRED_VERSION 1.4 .0)
95+ set (CppInterOp_REQUIRED_VERSION 1.5 .0)
9696
9797if (NOT TARGET xeus AND NOT TARGET xeus-static )
9898 find_package (xeus ${xeus_REQUIRED_VERSION} REQUIRED)
@@ -103,10 +103,7 @@ endif ()
103103
104104find_package (CppInterOp ${CppInterOp_REQUIRED_VERSION} REQUIRED)
105105if (CppInterOp_FOUND)
106- message (STATUS "Found CppInterOp: compatible with Clang ${CPPINTEROP_LLVM_VERSION_MAJOR} .x" )
107- # TODO : Fix after variables are set correctly
108- # Check https://github.com/compiler-research/CppInterOp/pull/336
109- # message(STATUS "Found CppInterOp: config=${CPPINTEROP_CONFIG} dir=${CPPINTEROP_DIR} (found version=${CPPINTEROP_VERSION} compatible with Clang ${CPPINTEROP_LLVM_VERSION_MAJOR}.x)")
106+ message (STATUS "Found CppInterOp: config=${CPPINTEROP_CMAKE_DIR} dir=${CPPINTEROP_INSTALL_PREFIX} (found version=${CPPINTEROP_VERSION} compatible with Clang ${CPPINTEROP_LLVM_VERSION_MAJOR} .x)" )
110107endif ()
111108
112109find_package (argparse REQUIRED)
@@ -152,9 +149,23 @@ function(configure_kernel kernel)
152149endfunction ()
153150
154151message ("Configure kernels: ..." )
155- configure_kernel("/share/jupyter/kernels/xcpp17/" )
156- configure_kernel("/share/jupyter/kernels/xcpp20/" )
157- configure_kernel("/share/jupyter/kernels/xcpp23/" )
152+ if (EMSCRIPTEN)
153+ # TODO: Currently jupyterlite-xeus and xeus-lite do not provide
154+ # methods to fetch information from the arguments present in the
155+ # generated emscripten kernel.
156+ # The following needs to be done here :
157+ # 1) We need to configure the kernel properly
158+ # Check issue https://github.com/compiler-research/xeus-cpp/issues/185.
159+ # 2) Once the above is done we need to add support in jupyterlite-xeus & xeus-lite
160+ # to be able to deal with arguments present in kernel.json
161+ # 3) Finally we should fetch the C++ version from the kernel.json file and
162+ # be able to pass it to our wasm interpreter rather than forcing a version.
163+ configure_kernel("/share/jupyter/kernels/xcpp20/" )
164+ else ()
165+ configure_kernel("/share/jupyter/kernels/xcpp17/" )
166+ configure_kernel("/share/jupyter/kernels/xcpp20/" )
167+ configure_kernel("/share/jupyter/kernels/xcpp23/" )
168+ endif ()
158169
159170# Source files
160171# ============
@@ -402,8 +413,24 @@ if(EMSCRIPTEN)
402413 xeus_cpp_set_kernel_options(xcpp)
403414 xeus_wasm_compile_options(xcpp)
404415 xeus_wasm_link_options(xcpp "web,worker" )
416+ # TODO: Remove the exported runtime methods
417+ # after the next xeus release.
418+ target_link_options (xcpp PUBLIC
419+ -sEXPORTED_RUNTIME_METHODS=FS,PATH ,ERRNO_CODES
420+ # add sysroot location here
421+ --preload-file ${SYSROOT_PATH} /include @/include
422+ )
423+ # TODO: Emscripten supports preloading files just once before it generates
424+ # the xcpp.data file (containing the binary representation of the file(s) we
425+ # want to include in our application).
426+ # Hence although we are adding support for Standard Headers, Libraries etc
427+ # through emscripten's sysroot for now, we need to do the following:
428+ # 1) Enable CppInterOp to provide us with a resource dir.
429+ # 2) If the above cannot be done, we can use the resource dir provided
430+ # by llvm on emscripten-forge but would involve adding a dependency.
431+ # 3) Shift the resource dir and the sysroot to a common location.
432+ # 4) Preload everything required together.
405433endif ()
406-
407434# Tests
408435# =====
409436
@@ -493,6 +520,7 @@ if(EMSCRIPTEN)
493520 install (FILES
494521 "$<TARGET_FILE_DIR:xcpp>/xcpp.js"
495522 "$<TARGET_FILE_DIR:xcpp>/xcpp.wasm"
523+ "$<TARGET_FILE_DIR:xcpp>/xcpp.data"
496524 DESTINATION ${CMAKE_INSTALL_BINDIR} )
497525endif ()
498526
0 commit comments