Skip to content

Commit 90238d0

Browse files
committed
Enable support for multiple kernels for xeus-cpp-lite
1 parent 1158ecd commit 90238d0

File tree

7 files changed

+44
-27
lines changed

7 files changed

+44
-27
lines changed

CMakeLists.txt

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ function(configure_native_kernel kernel)
148148
endfunction()
149149

150150
function(configure_wasm_kernel kernel)
151+
set(XEUS_CPP_RESOURCE_DIR "/lib/clang/${CPPINTEROP_LLVM_VERSION_MAJOR}")
151152

152153
configure_file (
153154
"${CMAKE_CURRENT_SOURCE_DIR}${kernel}wasm_kernel.json.in"
@@ -169,17 +170,9 @@ endfunction()
169170

170171
message("Configure kernels: ...")
171172
if(EMSCRIPTEN)
172-
# TODO: Currently jupyterlite-xeus and xeus-lite do not provide
173-
# methods to fetch information from the arguments present in the
174-
# generated emscripten kernel.
175-
# The following needs to be done here :
176-
# 1) We need to configure the kernel properly
177-
# Check issue https://github.com/compiler-research/xeus-cpp/issues/185.
178-
# 2) Once the above is done we need to add support in jupyterlite-xeus & xeus-lite
179-
# to be able to deal with arguments present in kernel.json
180-
# 3) Finally we should fetch the C++ version from the kernel.json file and
181-
# be able to pass it to our wasm interpreter rather than forcing a version.
173+
configure_wasm_kernel("/share/jupyter/kernels/xcpp17/")
182174
configure_wasm_kernel("/share/jupyter/kernels/xcpp20/")
175+
configure_wasm_kernel("/share/jupyter/kernels/xcpp23/")
183176
else()
184177
configure_native_kernel("/share/jupyter/kernels/xcpp17/")
185178
configure_native_kernel("/share/jupyter/kernels/xcpp20/")
@@ -444,20 +437,13 @@ if(EMSCRIPTEN)
444437
xeus_wasm_link_options(xcpp "web,worker")
445438
target_link_options(xcpp
446439
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
440+
# PUBLIC "SHELL: --preload-file ${CMAKE_INSTALL_PREFIX}${XEUS_CPP_RESOURCE_DIR}/include@${XEUS_CPP_RESOURCE_DIR}"
447441
PUBLIC "SHELL: --preload-file ${XEUS_CPP_DATA_DIR}@/share/xeus-cpp"
448442
PUBLIC "SHELL: --preload-file ${XEUS_CPP_CONF_DIR}@/etc/xeus-cpp"
449443
PUBLIC "SHELL: --post-js ${CMAKE_CURRENT_SOURCE_DIR}/wasm_patches/post.js"
450444
)
451-
# TODO: Emscripten supports preloading files just once before it generates
452-
# the xcpp.data file (containing the binary representation of the file(s) we
453-
# want to include in our application).
454-
# Hence although we are adding support for Standard Headers, Libraries etc
455-
# through emscripten's sysroot for now, we need to do the following:
456-
# 1) Enable CppInterOp to provide us with a resource dir.
457-
# 2) If the above cannot be done, we can use the resource dir provided
458-
# by llvm on emscripten-forge but would involve adding a dependency.
459-
# 3) Shift the resource dir and the sysroot to a common location.
460-
# 4) Preload everything required together.
445+
# TODO: Uncomment the above line regarding preloading clang's resource dir
446+
# once has been supported through cppinterop.
461447
endif()
462448
# Tests
463449
# =====

include/xeus-cpp/xinterpreter_wasm.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace xcpp
2020
public:
2121

2222
wasm_interpreter();
23+
wasm_interpreter(int argc, char** argv);
2324
virtual ~wasm_interpreter() = default;
2425

2526
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"display_name": "C++17",
3+
"argv": [
4+
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
5+
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
6+
"-std=c++17"
7+
],
8+
"language": "cpp",
9+
"metadata": {
10+
"debugger": false,
11+
"shared": {
12+
"libclangCppInterOp.so": "lib/libclangCppInterOp.so"
13+
}
14+
}
15+
}

share/jupyter/kernels/xcpp20/wasm_kernel.json.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"display_name": "C++20",
33
"argv": [
44
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
5-
"-f",
6-
"{connection_file}",
5+
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
76
"-std=c++20"
87
],
98
"language": "cpp",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"display_name": "C++23",
3+
"argv": [
4+
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
5+
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
6+
"-std=c++23"
7+
],
8+
"language": "cpp",
9+
"metadata": {
10+
"debugger": false,
11+
"shared": {
12+
"libclangCppInterOp.so": "lib/libclangCppInterOp.so"
13+
}
14+
}
15+
}

src/xinterpreter.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
using Args = std::vector<const char*>;
2828

2929
void* createInterpreter(const Args &ExtraArgs = {}) {
30-
Args ClangArgs = {/*"-xc++"*/"-v"}; // ? {"-Xclang", "-emit-llvm-only", "-Xclang", "-diagnostic-log-file", "-Xclang", "-", "-xc++"};
31-
#ifdef EMSCRIPTEN
32-
ClangArgs.push_back("-std=c++20");
33-
#else
30+
Args ClangArgs = {/*"-xc++"*/"-v"};
3431
if (std::find_if(ExtraArgs.begin(), ExtraArgs.end(), [](const std::string& s) {
3532
return s == "-resource-dir";}) == ExtraArgs.end()) {
3633
std::string resource_dir = Cpp::DetectResourceDir();
@@ -45,7 +42,6 @@ void* createInterpreter(const Args &ExtraArgs = {}) {
4542
ClangArgs.push_back("-isystem");
4643
ClangArgs.push_back(CxxInclude.c_str());
4744
}
48-
#endif
4945
ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
5046
// FIXME: We should process the kernel input options and conditionally pass
5147
// the gpu args here.

src/xinterpreter_wasm.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ namespace xcpp
2020
: interpreter(0, nullptr)
2121
{
2222
}
23+
24+
wasm_interpreter::wasm_interpreter(int argc, char** argv)
25+
: interpreter(argc, argv)
26+
{
27+
}
2328
}

0 commit comments

Comments
 (0)