Skip to content

Commit

Permalink
Unify wasm kernels (#137)
Browse files Browse the repository at this point in the history
* unify-wasm kernels
  • Loading branch information
DerThorsten committed Nov 29, 2023
1 parent fc128ab commit bc00168
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
35 changes: 24 additions & 11 deletions CMakeLists.txt
Expand Up @@ -60,9 +60,8 @@ OPTION(XSQL_USE_SHARED_XEUS_SQLITE "Link xsqlite with the xeus-sqlite shared lib

OPTION(XSQL_DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
OPTION(XSQL_BUILD_TESTS "xeus-sqlite test suite" OFF)
OPTION(XSQL_EMSCRIPTEN_WASM_BUILD "Build for wasm with emscripten" OFF)

if(XSQL_EMSCRIPTEN_WASM_BUILD)
if(EMSCRIPTEN)
# for the emscripten build we need a FindSQLite3.cmake since
# we install sqlite in a non-standart way
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_emscripten;${CMAKE_MODULE_PATH}")
Expand Down Expand Up @@ -114,7 +113,7 @@ string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE)

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib; ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")

if(XSQL_EMSCRIPTEN_WASM_BUILD)
if(EMSCRIPTEN)
add_compile_definitions(XSQL_EMSCRIPTEN_WASM_BUILD)
endif()

Expand Down Expand Up @@ -218,10 +217,9 @@ macro(xsql_create_target target_name linkage output_name)
${XSQL_XEUS_TARGET}
xvega
SQLiteCpp
SQLite::SQLite3
)

if(NOT XSQL_EMSCRIPTEN_WASM_BUILD)
if(NOT EMSCRIPTEN)
# find_package(Threads) # TODO: add Threads as a dependence of xeus-static?
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
endif()
Expand Down Expand Up @@ -284,18 +282,23 @@ if(XSQL_BUILD_TESTS)
add_subdirectory(test)
endif()

if(XSQL_EMSCRIPTEN_WASM_BUILD)
if(EMSCRIPTEN)
find_package(xeus-lite REQUIRED)
add_executable(xeus_kernel src/main_emscripten_kernel.cpp )
target_link_libraries(xeus_kernel PRIVATE xeus-sqlite-static xeus-lite)
target_compile_features(xeus_kernel PRIVATE cxx_std_17)
target_link_options(xeus_kernel
include(WasmBuildOptions)
add_executable(xsqlite src/main_emscripten_kernel.cpp )
target_link_libraries(xsqlite PRIVATE xeus-sqlite-static xeus-lite)
target_compile_features(xsqlite PRIVATE cxx_std_17)

xeus_wasm_compile_options(xsqlite)
xeus_wasm_link_options(xsqlite "web,worker")

target_link_options(xsqlite
PUBLIC "SHELL: -s FETCH=1"
PUBLIC "SHELL: -s NO_EXIT_RUNTIME=1"
PUBLIC "SHELL: -s 'ASYNCIFY_IMPORTS=[\"async_ems_init_idbfs\", \"async_ems_sync_db\"]'"
PUBLIC "SHELL: -s FORCE_FILESYSTEM=1"
)
target_link_libraries(xeus_kernel idbfs.js)
# target_link_libraries(xsqlite idbfs.js)
endif()

# Installation
Expand Down Expand Up @@ -323,7 +326,9 @@ endif ()
if (XSQL_BUILD_XSQLITE_EXECUTABLE)
install(TARGETS xsqlite
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

if (XSQL_BUILD_XSQLITE_EXECUTABLE OR EMSCRIPTEN)
# Configuration and data directories for jupyter and xeus_sqlite
set(XJUPYTER_DATA_DIR "share/jupyter" CACHE STRING "Jupyter data directory")

Expand Down Expand Up @@ -368,3 +373,11 @@ if (XSQL_BUILD_SHARED)
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${XEUS_SQLITE_CMAKECONFIG_INSTALL_DIR})
endif ()

if(EMSCRIPTEN)
install(FILES
"$<TARGET_FILE_DIR:xsqlite>/xsqlite.js"
"$<TARGET_FILE_DIR:xsqlite>/xsqlite.wasm"
DESTINATION ${XJUPYTER_DATA_DIR}/kernels/xsqlite)

endif()
5 changes: 4 additions & 1 deletion share/jupyter/kernels/xsqlite/kernel.json.in
Expand Up @@ -5,5 +5,8 @@
"-f",
"{connection_file}"
],
"language": "sqlite"
"language": "sqlite",
"metadata":{
"wasm_name" : "xsqlite"
}
}

0 comments on commit bc00168

Please sign in to comment.