Skip to content

Commit

Permalink
Fix emscripten build (#36)
Browse files Browse the repository at this point in the history
* Fix duplicate symbols error

* Add -fPIC option

* Simplify emscripten build in CI

* Remove unused var

* Update emsdk version

* Set emsdk to v3.1.45
  • Loading branch information
IsabelParedes authored Jan 8, 2024
1 parent f0b3eac commit 62a3692
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 114 deletions.
141 changes: 35 additions & 106 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,14 @@ jobs:
strategy:
fail-fast: false
matrix:
emsdk_ver: ["2.0.34", "3.1.3", "latest"]
emsdk_ver: ["3.1.45"]
# os: [ubuntu-latest, "macos-latest"]

steps:
- uses: actions/checkout@v4

- name: Make install dir
shell: bash -l {0}
run: |
mkdir -p $GITHUB_WORKSPACE/custom_sysroot
- name: Install emsdk
shell: bash -l {0}
run: |
git clone https://github.com/emscripten-core/emsdk.git /opt/emsdk
cd /opt/emsdk
./emsdk install ${{matrix.emsdk_ver}}
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2

- name: Install micromamba
uses: mamba-org/setup-micromamba@v1
Expand All @@ -149,107 +140,45 @@ jobs:

- name: Create project with cookiecutter
shell: bash -l {0}
run:
run: |
cookiecutter . --config-file .github/ci_context_wasm.yml --no-input -f
- name: Install xtl
run: |
cd /opt/emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source "/opt/emsdk/emsdk_env.sh"
mkdir -p /opt/xtl/build
git clone https://github.com/xtensor-stack/xtl.git /opt/xtl/src
cd /opt/xtl/src
git checkout 0.7.2
cd /opt/xtl/build
emcmake cmake ../src/ -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot
emmake make -j2 install
- name: Install nlohmann-json
run: |
cd /opt/emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source "/opt/emsdk/emsdk_env.sh"
mkdir -p /opt/nlohmannjson/build
git clone https://github.com/nlohmann/json.git /opt/nlohmannjson/src
cd /opt/nlohmannjson/src
git checkout v3.9.0
cd /opt/nlohmannjson/build
emcmake cmake ../src/ -DJSON_BuildTests=OFF -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot
emmake make -j2 install
- name: Install xeus
run: |
cd /opt/emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source "/opt/emsdk/emsdk_env.sh"
mkdir -p /opt/xeus/build
git clone https://github.com/jupyter-xeus/xeus.git /opt/xeus/src
cd /opt/xeus/src
git checkout 3.0.5
cd /opt/xeus/build
emcmake cmake ../src \
-DXEUS_EMSCRIPTEN_WASM_BUILD=ON \
-DXEUS_BUILD_TESTS=OFF \
-Dxtl_DIR=$GITHUB_WORKSPACE/custom_sysroot/share/cmake/xtl \
-Dnlohmann_json_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/nlohmann_json \
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot
emmake make -j2
emmake make -j2 install
- name: Install xeus-lite
run: |
cd /opt/emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source "/opt/emsdk/emsdk_env.sh"
mkdir -p /opt/xeus-lite/build
git clone https://github.com/jupyter-xeus/xeus-lite.git /opt/xeus-lite/src
cd /opt/xeus-lite/src
git checkout 1.0.1
cd /opt/xeus-lite/build
emcmake cmake ../src \
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot \
-Dnlohmann_json_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/nlohmann_json \
-Dxtl_DIR=$GITHUB_WORKSPACE/custom_sysroot/share/cmake/xtl \
-Dxeus_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/xeus
emmake make -j2
emmake make -j2 install
- name: Configure cmake rendered project
- name: Create build environment
shell: bash -l {0}
run: micromamba create -f xeus-mylang/environment-wasm-build.yml -y

- name: Setup emsdk
shell: bash -l {0}
run: |
cd /opt/emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source "/opt/emsdk/emsdk_env.sh"
cd $GITHUB_WORKSPACE/xeus-mylang
mkdir -p bld
cd bld
emcmake cmake .. \
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/custom_sysroot \
-DXEUS_MYLANG_EMSCRIPTEN_WASM_BUILD=ON \
-Dxtl_DIR=$GITHUB_WORKSPACE/custom_sysroot/share/cmake/xtl \
-Dnlohmann_json_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/nlohmann_json \
-Dxeus_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/xeus \
-Dxeus-lite_DIR=$GITHUB_WORKSPACE/custom_sysroot/lib/cmake/xeus-lite
- name: Build rendered project
shell: bash
run: |
cd /opt/emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source "/opt/emsdk/emsdk_env.sh"
cd $GITHUB_WORKSPACE/xeus-mylang/bld
emmake make -j8
micromamba activate xeus-mylang-wasm-build
emsdk install ${{ matrix.emsdk_ver }}
- name: Install rendered project
- name: Build
shell: bash -l {0}
working-directory: xeus-mylang
run: |
cd /opt/emsdk
./emsdk activate ${{matrix.emsdk_ver}}
source "/opt/emsdk/emsdk_env.sh"
cd $GITHUB_WORKSPACE/xeus-mylang/bld
make install
micromamba activate xeus-mylang-wasm-build
emsdk activate ${{ matrix.emsdk_ver }}
source $CONDA_EMSDK_DIR/emsdk_env.sh
micromamba create -f environment-wasm-host.yml --platform=emscripten-wasm32
mkdir build
pushd build
export EMPACK_PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-mylang-wasm-build
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-mylang-wasm-host
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
emcmake cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$PREFIX \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
..
make -j${{ steps.cpu-cores.outputs.count }}
push:
needs: [unix, win, emscripten_wasm]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ jobs:
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$PREFIX \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-D{{cookiecutter.cmake_var_prefix}}_EMSCRIPTEN_WASM_BUILD=ON \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
..
{% raw %}
Expand Down
18 changes: 11 additions & 7 deletions {{cookiecutter.github_project_name}}/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#############################################################################
#Copyright (c) {% now 'utc', '%Y' %},
#
#Distributed under the terms of the {{cookiecutter.open_source_license}}.
#
#The full license is in the file LICENSE, distributed with this software.
#Copyright (c) {% now 'utc', '%Y' %},
#
#Distributed under the terms of the {{cookiecutter.open_source_license}}.
#
#The full license is in the file LICENSE, distributed with this software.
#############################################################################

cmake_minimum_required(VERSION 3.4.3)
Expand Down Expand Up @@ -190,7 +190,7 @@ macro({{cookiecutter.cmake_var_prefix|lower}}_set_kernel_options target_name)
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
endif()
{% else -%}
find_package(Threads)
find_package(Threads)
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
{% endif %}
endmacro()
Expand Down Expand Up @@ -264,6 +264,9 @@ if ({{cookiecutter.cmake_var_prefix}}_BUILD_STATIC)
else ()
{{cookiecutter.cmake_var_prefix|lower}}_create_target({{cookiecutter.library_name}}-static STATIC {{cookiecutter.library_name}})
endif ()
if(EMSCRIPTEN)
target_compile_options({{cookiecutter.library_name}}-static PRIVATE -fPIC)
endif()
list(APPEND {{cookiecutter.cmake_var_prefix}}_TARGETS {{cookiecutter.library_name}}-static)
endif ()

Expand All @@ -283,7 +286,8 @@ if(EMSCRIPTEN)
include(WasmBuildOptions)
find_package(xeus-lite REQUIRED)
add_executable({{cookiecutter.binary_name}} src/main_emscripten_kernel.cpp )
target_link_libraries({{cookiecutter.binary_name}} PRIVATE {{cookiecutter.library_name}}-static xeus-lite)
target_link_libraries({{cookiecutter.binary_name}} PRIVATE xeus-lite)
target_compile_options({{cookiecutter.binary_name}} PRIVATE -fPIC)
{{cookiecutter.cmake_var_prefix}}_set_kernel_options({{cookiecutter.binary_name}})
xeus_wasm_compile_options({{cookiecutter.binary_name}})
xeus_wasm_link_options({{cookiecutter.binary_name}} "web,worker")
Expand Down

0 comments on commit 62a3692

Please sign in to comment.