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 #137

Merged
merged 3 commits 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
35 changes: 24 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"-f",
"{connection_file}"
],
"language": "sqlite"
"language": "sqlite",
"metadata":{
"wasm_name" : "xsqlite"
}
}