Skip to content

Commit 62a3692

Browse files
Fix emscripten build (#36)
* Fix duplicate symbols error * Add -fPIC option * Simplify emscripten build in CI * Remove unused var * Update emsdk version * Set emsdk to v3.1.45
1 parent f0b3eac commit 62a3692

File tree

3 files changed

+46
-114
lines changed

3 files changed

+46
-114
lines changed

.github/workflows/main.yml

Lines changed: 35 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,14 @@ jobs:
124124
strategy:
125125
fail-fast: false
126126
matrix:
127-
emsdk_ver: ["2.0.34", "3.1.3", "latest"]
127+
emsdk_ver: ["3.1.45"]
128128
# os: [ubuntu-latest, "macos-latest"]
129129

130130
steps:
131131
- uses: actions/checkout@v4
132132

133-
- name: Make install dir
134-
shell: bash -l {0}
135-
run: |
136-
mkdir -p $GITHUB_WORKSPACE/custom_sysroot
137-
138-
- name: Install emsdk
139-
shell: bash -l {0}
140-
run: |
141-
git clone https://github.com/emscripten-core/emsdk.git /opt/emsdk
142-
cd /opt/emsdk
143-
./emsdk install ${{matrix.emsdk_ver}}
133+
- name: Get number of CPU cores
134+
uses: SimenB/github-actions-cpu-cores@v2
144135

145136
- name: Install micromamba
146137
uses: mamba-org/setup-micromamba@v1
@@ -149,107 +140,45 @@ jobs:
149140

150141
- name: Create project with cookiecutter
151142
shell: bash -l {0}
152-
run:
143+
run: |
153144
cookiecutter . --config-file .github/ci_context_wasm.yml --no-input -f
154145
155-
- name: Install xtl
156-
run: |
157-
cd /opt/emsdk
158-
./emsdk activate ${{matrix.emsdk_ver}}
159-
source "/opt/emsdk/emsdk_env.sh"
160-
mkdir -p /opt/xtl/build
161-
git clone https://github.com/xtensor-stack/xtl.git /opt/xtl/src
162-
cd /opt/xtl/src
163-
git checkout 0.7.2
164-
cd /opt/xtl/build
165-
emcmake cmake ../src/ -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot
166-
emmake make -j2 install
167-
168-
- name: Install nlohmann-json
169-
run: |
170-
cd /opt/emsdk
171-
./emsdk activate ${{matrix.emsdk_ver}}
172-
source "/opt/emsdk/emsdk_env.sh"
173-
mkdir -p /opt/nlohmannjson/build
174-
git clone https://github.com/nlohmann/json.git /opt/nlohmannjson/src
175-
cd /opt/nlohmannjson/src
176-
git checkout v3.9.0
177-
cd /opt/nlohmannjson/build
178-
emcmake cmake ../src/ -DJSON_BuildTests=OFF -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot
179-
emmake make -j2 install
180-
181-
- name: Install xeus
182-
run: |
183-
cd /opt/emsdk
184-
./emsdk activate ${{matrix.emsdk_ver}}
185-
source "/opt/emsdk/emsdk_env.sh"
186-
mkdir -p /opt/xeus/build
187-
git clone https://github.com/jupyter-xeus/xeus.git /opt/xeus/src
188-
cd /opt/xeus/src
189-
git checkout 3.0.5
190-
cd /opt/xeus/build
191-
emcmake cmake ../src \
192-
-DXEUS_EMSCRIPTEN_WASM_BUILD=ON \
193-
-DXEUS_BUILD_TESTS=OFF \
194-
-Dxtl_DIR=$GITHUB_WORKSPACE/custom_sysroot/share/cmake/xtl \
195-
-Dnlohmann_json_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/nlohmann_json \
196-
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot
197-
emmake make -j2
198-
emmake make -j2 install
199-
200-
- name: Install xeus-lite
201-
run: |
202-
cd /opt/emsdk
203-
./emsdk activate ${{matrix.emsdk_ver}}
204-
source "/opt/emsdk/emsdk_env.sh"
205-
mkdir -p /opt/xeus-lite/build
206-
git clone https://github.com/jupyter-xeus/xeus-lite.git /opt/xeus-lite/src
207-
cd /opt/xeus-lite/src
208-
git checkout 1.0.1
209-
cd /opt/xeus-lite/build
210-
emcmake cmake ../src \
211-
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot \
212-
-Dnlohmann_json_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/nlohmann_json \
213-
-Dxtl_DIR=$GITHUB_WORKSPACE/custom_sysroot/share/cmake/xtl \
214-
-Dxeus_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/xeus
215-
216-
emmake make -j2
217-
emmake make -j2 install
218-
219-
- name: Configure cmake rendered project
146+
- name: Create build environment
147+
shell: bash -l {0}
148+
run: micromamba create -f xeus-mylang/environment-wasm-build.yml -y
149+
150+
- name: Setup emsdk
220151
shell: bash -l {0}
221152
run: |
222-
cd /opt/emsdk
223-
./emsdk activate ${{matrix.emsdk_ver}}
224-
source "/opt/emsdk/emsdk_env.sh"
225-
cd $GITHUB_WORKSPACE/xeus-mylang
226-
mkdir -p bld
227-
cd bld
228-
emcmake cmake .. \
229-
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot \
230-
-DXEUS_MYLANG_EMSCRIPTEN_WASM_BUILD=ON \
231-
-Dxtl_DIR=$GITHUB_WORKSPACE/custom_sysroot/share/cmake/xtl \
232-
-Dnlohmann_json_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/nlohmann_json \
233-
-Dxeus_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/xeus \
234-
-Dxeus-lite_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/xeus-lite
235-
236-
- name: Build rendered project
237-
shell: bash
238-
run: |
239-
cd /opt/emsdk
240-
./emsdk activate ${{matrix.emsdk_ver}}
241-
source "/opt/emsdk/emsdk_env.sh"
242-
cd $GITHUB_WORKSPACE/xeus-mylang/bld
243-
emmake make -j8
153+
micromamba activate xeus-mylang-wasm-build
154+
emsdk install ${{ matrix.emsdk_ver }}
244155
245-
- name: Install rendered project
156+
- name: Build
246157
shell: bash -l {0}
158+
working-directory: xeus-mylang
247159
run: |
248-
cd /opt/emsdk
249-
./emsdk activate ${{matrix.emsdk_ver}}
250-
source "/opt/emsdk/emsdk_env.sh"
251-
cd $GITHUB_WORKSPACE/xeus-mylang/bld
252-
make install
160+
micromamba activate xeus-mylang-wasm-build
161+
emsdk activate ${{ matrix.emsdk_ver }}
162+
163+
source $CONDA_EMSDK_DIR/emsdk_env.sh
164+
micromamba create -f environment-wasm-host.yml --platform=emscripten-wasm32
165+
166+
mkdir build
167+
pushd build
168+
169+
export EMPACK_PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-mylang-wasm-build
170+
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-mylang-wasm-host
171+
export CMAKE_PREFIX_PATH=$PREFIX
172+
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
173+
174+
emcmake cmake \
175+
-DCMAKE_BUILD_TYPE=Release \
176+
-DCMAKE_PREFIX_PATH=$PREFIX \
177+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
178+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
179+
..
180+
make -j${{ steps.cpu-cores.outputs.count }}
181+
253182
254183
push:
255184
needs: [unix, win, emscripten_wasm]

{{cookiecutter.github_project_name}}/.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ jobs:
261261
-DCMAKE_BUILD_TYPE=Release \
262262
-DCMAKE_PREFIX_PATH=$PREFIX \
263263
-DCMAKE_INSTALL_PREFIX=$PREFIX \
264-
-D{{cookiecutter.cmake_var_prefix}}_EMSCRIPTEN_WASM_BUILD=ON \
265264
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
266265
..
267266
{% raw %}

{{cookiecutter.github_project_name}}/CMakeLists.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#############################################################################
2-
#Copyright (c) {% now 'utc', '%Y' %},
3-
#
4-
#Distributed under the terms of the {{cookiecutter.open_source_license}}.
5-
#
6-
#The full license is in the file LICENSE, distributed with this software.
2+
#Copyright (c) {% now 'utc', '%Y' %},
3+
#
4+
#Distributed under the terms of the {{cookiecutter.open_source_license}}.
5+
#
6+
#The full license is in the file LICENSE, distributed with this software.
77
#############################################################################
88

99
cmake_minimum_required(VERSION 3.4.3)
@@ -190,7 +190,7 @@ macro({{cookiecutter.cmake_var_prefix|lower}}_set_kernel_options target_name)
190190
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
191191
endif()
192192
{% else -%}
193-
find_package(Threads)
193+
find_package(Threads)
194194
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
195195
{% endif %}
196196
endmacro()
@@ -264,6 +264,9 @@ if ({{cookiecutter.cmake_var_prefix}}_BUILD_STATIC)
264264
else ()
265265
{{cookiecutter.cmake_var_prefix|lower}}_create_target({{cookiecutter.library_name}}-static STATIC {{cookiecutter.library_name}})
266266
endif ()
267+
if(EMSCRIPTEN)
268+
target_compile_options({{cookiecutter.library_name}}-static PRIVATE -fPIC)
269+
endif()
267270
list(APPEND {{cookiecutter.cmake_var_prefix}}_TARGETS {{cookiecutter.library_name}}-static)
268271
endif ()
269272

@@ -283,7 +286,8 @@ if(EMSCRIPTEN)
283286
include(WasmBuildOptions)
284287
find_package(xeus-lite REQUIRED)
285288
add_executable({{cookiecutter.binary_name}} src/main_emscripten_kernel.cpp )
286-
target_link_libraries({{cookiecutter.binary_name}} PRIVATE {{cookiecutter.library_name}}-static xeus-lite)
289+
target_link_libraries({{cookiecutter.binary_name}} PRIVATE xeus-lite)
290+
target_compile_options({{cookiecutter.binary_name}} PRIVATE -fPIC)
287291
{{cookiecutter.cmake_var_prefix}}_set_kernel_options({{cookiecutter.binary_name}})
288292
xeus_wasm_compile_options({{cookiecutter.binary_name}})
289293
xeus_wasm_link_options({{cookiecutter.binary_name}} "web,worker")

0 commit comments

Comments
 (0)