Skip to content

Commit 44c0064

Browse files
authored
build as main module (#151)
* wasm ci * main module * main module * main module * wip * wip * adding postjs * wip * wip
1 parent f1052f4 commit 44c0064

File tree

6 files changed

+222
-7
lines changed

6 files changed

+222
-7
lines changed

.github/workflows/main.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,117 @@ jobs:
7171
- name: Test xeus-sqlite (C++)
7272
run: ./test_xeus_sqlite
7373
working-directory: build/test
74+
75+
76+
emscripten_wasm_build:
77+
78+
runs-on: ubuntu-latest
79+
80+
strategy:
81+
fail-fast: false
82+
83+
84+
steps:
85+
- uses: actions/checkout@v4
86+
87+
- name: Get number of CPU cores
88+
uses: SimenB/github-actions-cpu-cores@v2
89+
90+
- name: Install micromamba
91+
uses: mamba-org/setup-micromamba@v1
92+
with:
93+
environment-file: environment-wasm-build.yml
94+
environment-name: xeus-sqlite-wasm-build
95+
96+
################################################################
97+
# C++ build
98+
################################################################
99+
- name: Build
100+
shell: bash -l {0}
101+
run: |
102+
103+
104+
105+
micromamba create -f environment-wasm-host.yml --platform=emscripten-wasm32 --yes
106+
107+
mkdir build
108+
pushd build
109+
110+
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-sqlite-wasm-host
111+
export CMAKE_PREFIX_PATH=$PREFIX
112+
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
113+
114+
emcmake cmake \
115+
-DCMAKE_BUILD_TYPE=Release \
116+
-DCMAKE_PREFIX_PATH=$PREFIX \
117+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
118+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
119+
-Dtabulate_DIR=$PREFIX/lib/cmake/tabulate \
120+
-DXSQL_BUILD_XSQLITE_EXECUTABLE=OFF \
121+
-DXSQL_BUILD_SHARED=OFF \
122+
-DXSQL_BUILD_STATIC=ON \
123+
-DXSQL_USE_SHARED_XEUS=ON \
124+
-DXSQL_USE_SHARED_XEUS_SQLITE=OFF \
125+
-DXVEGA_STATIC_LIBRARY=$PREFIX/lib/libxvega.a \
126+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
127+
..
128+
129+
make -j${{ steps.cpu-cores.outputs.count }} install
130+
131+
################################################################
132+
# jupyterlite page
133+
################################################################
134+
- name: Build jupyterlite page
135+
shell: bash -l {0}
136+
run: |
137+
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-sqlite-wasm-host
138+
# build jupyterlite
139+
jupyter lite build \
140+
--contents=examples \
141+
--XeusAddon.prefix=$PREFIX
142+
143+
144+
145+
################################################################
146+
# fix permissions
147+
################################################################
148+
- name: Fix permissions
149+
run: |
150+
chmod -c -R +rX "build_wasm/_output/" | while read line; do
151+
echo "::warning title=Invalid file permissions automatically fixed::$line"
152+
done
153+
154+
################################################################
155+
# upload to github pages
156+
################################################################
157+
- name: Upload Pages artifact
158+
uses: actions/upload-pages-artifact@v3
159+
with:
160+
path: _output
161+
162+
# Deploy job (only for the repo and **not** for forks)
163+
164+
deploy:
165+
# only run on main branch
166+
if: github.ref == 'refs/heads/main' && github.repository == 'jupyter-xeus/xeus-sqlite'
167+
168+
# Add a dependency to the build job
169+
needs: emscripten_wasm_build
170+
171+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
172+
permissions:
173+
contents: read # to read the Pages artifact
174+
pages: write # to deploy to Pages
175+
id-token: write # to verify the deployment originates from an appropriate source
176+
177+
# Deploy to the github-pages environment
178+
environment:
179+
name: github-pages
180+
url: ${{ steps.deployment.outputs.page_url }}
181+
182+
# Specify runner + deployment step
183+
runs-on: ubuntu-latest
184+
steps:
185+
- name: Deploy to GitHub Pages
186+
id: deployment
187+
uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action

CMakeLists.txt

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ if(EMSCRIPTEN)
6565
# for the emscripten build we need a FindSQLite3.cmake since
6666
# we install sqlite in a non-standart way
6767
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_emscripten;${CMAKE_MODULE_PATH}")
68+
69+
# overwriteProp.cmake
70+
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) # does not need to be global :)
71+
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-s SIDE_MODULE=1")
72+
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1")
73+
6874
endif()
6975

7076
# Dependencies
@@ -76,7 +82,9 @@ set(tabulate_REQUIRED_VERSION 1.5)
7682

7783
find_package(SQLite3 REQUIRED)
7884
find_package(SQLiteCpp REQUIRED)
79-
find_package(Threads REQUIRED)
85+
if(NOT EMSCRIPTEN)
86+
find_package(Threads REQUIRED)
87+
endif()
8088
find_package(xvega-bindings ${xvega_bindings_REQUIRED_VERSION} REQUIRED)
8189
find_package(tabulate ${tabulate_REQUIRED_VERSION} REQUIRED)
8290

@@ -213,11 +221,22 @@ macro(xsql_create_target target_name linkage output_name)
213221
set(XSQL_XEUS_TARGET xeus-static)
214222
endif ()
215223

216-
target_link_libraries(${target_name} PUBLIC
217-
${XSQL_XEUS_TARGET}
218-
xvega
219-
SQLiteCpp
220-
)
224+
if(EMSCRIPTEN)
225+
target_link_libraries(${target_name} PUBLIC
226+
${XSQL_XEUS_TARGET}
227+
${XVEGA_STATIC_LIBRARY}
228+
SQLiteCpp
229+
)
230+
231+
# fpic
232+
target_compile_options(${target_name} PUBLIC -fPIC)
233+
else()
234+
target_link_libraries(${target_name} PUBLIC
235+
${XSQL_XEUS_TARGET}
236+
xvega
237+
SQLiteCpp
238+
)
239+
endif()
221240

222241
if(NOT EMSCRIPTEN)
223242
# find_package(Threads) # TODO: add Threads as a dependence of xeus-static?
@@ -250,7 +269,7 @@ endif ()
250269
# xsqlite
251270
# =======
252271

253-
if (XSQL_BUILD_XSQLITE_EXECUTABLE)
272+
if (XSQL_BUILD_XSQLITE_EXECUTABLE AND NOT EMSCRIPTEN)
254273
find_package(xeus-zmq 1.1.1 REQUIRED)
255274
add_executable(xsqlite ${XSQLITE_SRC})
256275
set_target_properties(xsqlite PROPERTIES ENABLE_EXPORTS 1)
@@ -293,6 +312,9 @@ if(EMSCRIPTEN)
293312
xeus_wasm_link_options(xsqlite "web,worker")
294313

295314
target_link_options(xsqlite
315+
PUBLIC "SHELL: -s MAIN_MODULE=1"
316+
PUBLIC "SHELL: -s WASM_BIGINT=1"
317+
PUBLIC "SHELL: --post-js ${CMAKE_CURRENT_SOURCE_DIR}/src/post.js"
296318
PUBLIC "SHELL: -s FETCH=1"
297319
PUBLIC "SHELL: -s NO_EXIT_RUNTIME=1"
298320
PUBLIC "SHELL: -s 'ASYNCIFY_IMPORTS=[\"async_ems_init_idbfs\", \"async_ems_sync_db\"]'"

build.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
4+
# this is a helper script for local wasm builds.
5+
# we assume that script is run in the
6+
# env defined in environment-wasm-build.yml
7+
8+
set -e
9+
10+
# flip this to true to create the environments
11+
if false; then
12+
micromamba create -f environment-wasm-host.yml --platform=emscripten-wasm32 --yes
13+
14+
else
15+
echo "Skipping environment creation"
16+
fi
17+
18+
mkdir -p build
19+
pushd build
20+
21+
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-sqlite-wasm-host
22+
export CMAKE_PREFIX_PATH=$PREFIX
23+
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
24+
25+
emcmake cmake \
26+
-DCMAKE_BUILD_TYPE=Release \
27+
-DCMAKE_PREFIX_PATH=$PREFIX \
28+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
29+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
30+
-Dtabulate_DIR=$PREFIX/lib/cmake/tabulate \
31+
-DXSQL_BUILD_XSQLITE_EXECUTABLE=OFF \
32+
-DXSQL_BUILD_SHARED=OFF \
33+
-DXSQL_BUILD_STATIC=ON \
34+
-DXSQL_USE_SHARED_XEUS=ON \
35+
-DXSQL_USE_SHARED_XEUS_SQLITE=OFF \
36+
-DXVEGA_STATIC_LIBRARY=$PREFIX/lib/libxvega.a \
37+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
38+
..
39+
40+
make -j2 install

environment-wasm-build.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: xeus-sqlite-wasm-build
2+
channels:
3+
- https://repo.prefix.dev/emscripten-forge-dev
4+
- conda-forge
5+
dependencies:
6+
- cmake
7+
- pkg-config
8+
- emscripten_emscripten-wasm32==3.1.73
9+
- anywidget
10+
- cmake
11+
- jupyter_server # to enable contents
12+
- jupyterlite-core
13+
- jupyterlite-xeus
14+
- notebook >=7,<8 # to include the extension to switch between JupyterLab and Notebook

environment-wasm-host.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: xeus-sqlite-wasm-host
2+
channels:
3+
- https://repo.prefix.dev/emscripten-forge-dev
4+
- https://repo.mamba.pm/conda-forge
5+
dependencies:
6+
- nlohmann_json >= 3.12
7+
- nlohmann_json-abi
8+
- xproperty
9+
- cpp-tabulate
10+
- xvega
11+
- xvega-bindings
12+
- xeus-lite
13+
- xeus
14+
- xtl
15+
- sqlitecpp

src/post.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
if (!('wasmTable' in Module)) {
3+
Module['wasmTable'] = wasmTable
4+
}
5+
6+
Module['FS'] = FS
7+
Module['PATH'] = PATH
8+
Module['LDSO'] = LDSO
9+
Module['getDylinkMetadata'] = getDylinkMetadata
10+
Module['loadDynamicLibrary'] = loadDynamicLibrary

0 commit comments

Comments
 (0)