Skip to content
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

unify wasm kernels #604

Merged
merged 1 commit into from
Nov 29, 2023
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
23 changes: 12 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function(cat IN_FILE OUT_FILE)
endfunction()


if(XPYT_EMSCRIPTEN_WASM_BUILD)
if(EMSCRIPTEN)
# Prepare a temporary file to "post.js.in" to
# merge xeus custom post js and the pyjs post js
file(WRITE post.js.in "")
Expand Down Expand Up @@ -113,7 +113,7 @@ if (NOT TARGET pybind11_json)
find_package(pybind11_json ${pybind11_json_REQUIRED_VERSION} REQUIRED)
endif ()

if(XPYT_EMSCRIPTEN_WASM_BUILD)
if(EMSCRIPTEN)
if (NOT TARGET xeus-lite)
find_package(xeus-lite ${xeus-lite_REQUIRED_VERSION} REQUIRED)
endif ()
Expand Down Expand Up @@ -318,7 +318,7 @@ macro(xpyt_create_target target_name src headers linkage output_name)
$<BUILD_INTERFACE:${XEUS_PYTHON_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)

if (XPYT_EMSCRIPTEN_WASM_BUILD)
if (EMSCRIPTEN)
set(XPY_XEUS_TARGET xeus)
elseif (XPYT_USE_SHARED_XEUS)
set(XPYT_XEUS_TARGET xeus-zmq)
Expand Down Expand Up @@ -366,7 +366,7 @@ if (XPYT_BUILD_STATIC)
list(APPEND XEUS_PYTHON_TARGETS xeus-python-static)
endif ()

if (XPYT_EMSCRIPTEN_WASM_BUILD)
if (EMSCRIPTEN)
xpyt_create_target(xeus-python-wasm "${XEUS_PYTHON_WASM_SRC}" "${XEUS_PYTHON_WASM_HEADERS}" STATIC xeus-python-wasm)
target_compile_options(xeus-python-wasm PRIVATE -fPIC)
list(APPEND XEUS_PYTHON_TARGETS xeus-python-wasm)
Expand Down Expand Up @@ -401,7 +401,7 @@ endif()
# xpython_wasm
# ============

if (XPYT_EMSCRIPTEN_WASM_BUILD)
if (EMSCRIPTEN)
# TODO MAKE BETTER
SET(PYTHON_UTIL_LIBS
$ENV{PREFIX}/lib/libbz2.a
Expand All @@ -422,10 +422,9 @@ if (XPYT_EMSCRIPTEN_WASM_BUILD)
include(WasmBuildOptions)
xeus_wasm_compile_options(xpython_wasm)
xeus_wasm_link_options(xpython_wasm "web,worker")
xeus_wasm_fs_options(xpython_wasm)
target_link_options(xpython_wasm
PUBLIC "SHELL: -s LZ4=1"
PUBLIC "SHELL: --post-js post.js"
PUBLIC "SHELL: --post-js ${CMAKE_CURRENT_BINARY_DIR}/post.js"
PUBLIC "SHELL: --pre-js pre.js"
PUBLIC "SHELL: -s MAIN_MODULE=1"
PUBLIC "SHELL: -s WASM_BIGINT"
Expand Down Expand Up @@ -465,7 +464,9 @@ endif ()
if (XPYT_BUILD_XPYTHON_EXECUTABLE)
install(TARGETS xpython
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

if(XPYT_BUILD_XPYTHON_EXECUTABLE OR EMSCRIPTEN)
# Configuration and data directories for jupyter and xeus-python
set(XJUPYTER_DATA_DIR "share/jupyter" CACHE STRING "Jupyter data directory")

Expand Down Expand Up @@ -509,11 +510,11 @@ if (XPYT_BUILD_SHARED)
DESTINATION ${XEUS_PYTHON_CMAKECONFIG_INSTALL_DIR})
endif ()

if (XPYT_EMSCRIPTEN_WASM_BUILD)
install(TARGETS xpython_wasm
ARCHIVE DESTINATION ${CMAKE_INSTALL_BINDIR})
if (EMSCRIPTEN)

install(FILES
"$<TARGET_FILE_DIR:xpython_wasm>/xpython_wasm.js"
"$<TARGET_FILE_DIR:xpython_wasm>/xpython_wasm.wasm"
DESTINATION ${CMAKE_INSTALL_BINDIR})
DESTINATION ${XJUPYTER_DATA_DIR}/kernels/xpython/
)
endif ()
2 changes: 1 addition & 1 deletion share/jupyter/kernels/xpython/kernel.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"{connection_file}"
],
"language": "python",
"metadata": { "debugger": true }
"metadata": { "debugger": true, "wasm_name" : "xpython_wasm"}
}
14 changes: 14 additions & 0 deletions wasm_patches/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ Module.UTF8ToString = UTF8ToString;
Module.wasmTable = wasmTable;
// Emscripten has a bug where it accidentally exposes an empty object as Module.ERRNO_CODES
Module.ERRNO_CODES = ERRNO_CODES;



Module['async_init'] = async function(
kernel_root_url,
pkg_root_url,
verbose) {
Module['bootstrap_from_empack_packed_environment']
return Module['bootstrap_from_empack_packed_environment'](
`${kernel_root_url}/empack_env_meta.json`, /* packages_json_url */
pkg_root_url, /* package_tarballs_root_url */
verbose /* verbose */
);
}
Loading