Skip to content

Commit bc00168

Browse files
authored
Unify wasm kernels (#137)
* unify-wasm kernels
1 parent fc128ab commit bc00168

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

CMakeLists.txt

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ OPTION(XSQL_USE_SHARED_XEUS_SQLITE "Link xsqlite with the xeus-sqlite shared lib
6060

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

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

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

117-
if(XSQL_EMSCRIPTEN_WASM_BUILD)
116+
if(EMSCRIPTEN)
118117
add_compile_definitions(XSQL_EMSCRIPTEN_WASM_BUILD)
119118
endif()
120119

@@ -218,10 +217,9 @@ macro(xsql_create_target target_name linkage output_name)
218217
${XSQL_XEUS_TARGET}
219218
xvega
220219
SQLiteCpp
221-
SQLite::SQLite3
222220
)
223221

224-
if(NOT XSQL_EMSCRIPTEN_WASM_BUILD)
222+
if(NOT EMSCRIPTEN)
225223
# find_package(Threads) # TODO: add Threads as a dependence of xeus-static?
226224
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
227225
endif()
@@ -284,18 +282,23 @@ if(XSQL_BUILD_TESTS)
284282
add_subdirectory(test)
285283
endif()
286284

287-
if(XSQL_EMSCRIPTEN_WASM_BUILD)
285+
if(EMSCRIPTEN)
288286
find_package(xeus-lite REQUIRED)
289-
add_executable(xeus_kernel src/main_emscripten_kernel.cpp )
290-
target_link_libraries(xeus_kernel PRIVATE xeus-sqlite-static xeus-lite)
291-
target_compile_features(xeus_kernel PRIVATE cxx_std_17)
292-
target_link_options(xeus_kernel
287+
include(WasmBuildOptions)
288+
add_executable(xsqlite src/main_emscripten_kernel.cpp )
289+
target_link_libraries(xsqlite PRIVATE xeus-sqlite-static xeus-lite)
290+
target_compile_features(xsqlite PRIVATE cxx_std_17)
291+
292+
xeus_wasm_compile_options(xsqlite)
293+
xeus_wasm_link_options(xsqlite "web,worker")
294+
295+
target_link_options(xsqlite
293296
PUBLIC "SHELL: -s FETCH=1"
294297
PUBLIC "SHELL: -s NO_EXIT_RUNTIME=1"
295298
PUBLIC "SHELL: -s 'ASYNCIFY_IMPORTS=[\"async_ems_init_idbfs\", \"async_ems_sync_db\"]'"
296299
PUBLIC "SHELL: -s FORCE_FILESYSTEM=1"
297300
)
298-
target_link_libraries(xeus_kernel idbfs.js)
301+
# target_link_libraries(xsqlite idbfs.js)
299302
endif()
300303

301304
# Installation
@@ -323,7 +326,9 @@ endif ()
323326
if (XSQL_BUILD_XSQLITE_EXECUTABLE)
324327
install(TARGETS xsqlite
325328
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
329+
endif()
326330

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

@@ -368,3 +373,11 @@ if (XSQL_BUILD_SHARED)
368373
FILE ${PROJECT_NAME}Targets.cmake
369374
DESTINATION ${XEUS_SQLITE_CMAKECONFIG_INSTALL_DIR})
370375
endif ()
376+
377+
if(EMSCRIPTEN)
378+
install(FILES
379+
"$<TARGET_FILE_DIR:xsqlite>/xsqlite.js"
380+
"$<TARGET_FILE_DIR:xsqlite>/xsqlite.wasm"
381+
DESTINATION ${XJUPYTER_DATA_DIR}/kernels/xsqlite)
382+
383+
endif()

share/jupyter/kernels/xsqlite/kernel.json.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"-f",
66
"{connection_file}"
77
],
8-
"language": "sqlite"
8+
"language": "sqlite",
9+
"metadata":{
10+
"wasm_name" : "xsqlite"
11+
}
912
}

0 commit comments

Comments
 (0)