Skip to content

Commit

Permalink
Add automated tests for Emscripten builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbarton committed Feb 9, 2025
1 parent b797dbb commit 123e15c
Show file tree
Hide file tree
Showing 20 changed files with 335 additions and 82 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ jobs:
if: ${{ runner.os != 'windows' }}
shell: bash -l {0}
run: |
set -e
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
source ./emsdk/emsdk_env.sh
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
export PREFIX=$MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
Expand Down Expand Up @@ -130,6 +131,7 @@ jobs:
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DSYSROOT_PATH=$SYSROOT_PATH \
../
else
emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
Expand All @@ -141,13 +143,15 @@ jobs:
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DSYSROOT_PATH=$SYSROOT_PATH \
../
fi
emmake make -j ${{ env.ncpus }} check-cppinterop
emmake make -j ${{ env.ncpus }} install
cd ..
echo "SYSROOT_PATH=$SYSROOT_PATH" >> $GITHUB_ENV
echo "CB_PYTHON_DIR=$CB_PYTHON_DIR" >> $GITHUB_ENV
echo "CPPINTEROP_BUILD_DIR=$CPPINTEROP_BUILD_DIR" >> $GITHUB_ENV
echo "CPPINTEROP_DIR=$CPPINTEROP_DIR" >> $GITHUB_ENV
Expand All @@ -160,7 +164,6 @@ jobs:
run: |
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
source ./emsdk/emsdk_env.sh
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
micromamba activate CppInterOp-wasm
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
cd ./xeus-cpp
Expand All @@ -175,7 +178,7 @@ jobs:
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCppInterOp_DIR="${{ env.CPPINTEROP_BUILD_DIR }}/lib/cmake/CppInterOp" \
-DSYSROOT_PATH=$SYSROOT_PATH \
-DSYSROOT_PATH=${{ env.SYSROOT_PATH }} \
..
emmake make -j ${{ env.ncpus }} install
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,11 @@ jobs:
if: ${{ runner.os != 'windows' }}
shell: bash -l {0}
run: |
set -e
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
source ./emsdk/emsdk_env.sh
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
export PREFIX=$MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
Expand Down Expand Up @@ -587,6 +588,7 @@ jobs:
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DLLVM_ENABLE_WERROR=On \
-DSYSROOT_PATH=$SYSROOT_PATH \
../
else
emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
Expand All @@ -599,13 +601,15 @@ jobs:
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DLLVM_ENABLE_WERROR=On \
-DSYSROOT_PATH=$SYSROOT_PATH \
../
fi
emmake make -j ${{ env.ncpus }} install
emmake make -j ${{ env.ncpus }} check-cppinterop
emmake make -j ${{ env.ncpus }} install
cd ..
echo "SYSROOT_PATH=$SYSROOT_PATH" >> $GITHUB_ENV
echo "CB_PYTHON_DIR=$CB_PYTHON_DIR" >> $GITHUB_ENV
echo "CPPINTEROP_BUILD_DIR=$CPPINTEROP_BUILD_DIR" >> $GITHUB_ENV
echo "CPPINTEROP_DIR=$CPPINTEROP_DIR" >> $GITHUB_ENV
Expand All @@ -618,7 +622,6 @@ jobs:
run: |
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
source ./emsdk/emsdk_env.sh
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
micromamba activate CppInterOp-wasm
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
cd ./xeus-cpp
Expand All @@ -633,6 +636,6 @@ jobs:
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCppInterOp_DIR="${{ env.CPPINTEROP_BUILD_DIR }}/lib/cmake/CppInterOp" \
-DSYSROOT_PATH=$SYSROOT_PATH \
-DSYSROOT_PATH=${{ env.SYSROOT_PATH }} \
..
emmake make -j ${{ env.ncpus }} install
14 changes: 6 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,15 @@ endif()

# Add appropriate flags for GCC
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
if (APPLE)
if (APPLE OR EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
endif ()
# Needed due an error which occurs when you compile gtest on emscripten
if (EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
endif()
endif ()

# Fixes "C++ exception handler used, but unwind semantics are not enabled" warning Windows
Expand Down Expand Up @@ -451,13 +455,7 @@ option(CPPINTEROP_ENABLE_DOXYGEN "Use doxygen to generate CppInterOp interal API
option(CPPINTEROP_ENABLE_SPHINX "Use sphinx to generage CppInterOp user documentation")


if(EMSCRIPTEN)
message("Build with emscripten")
option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." OFF)
else()
message("Build with cmake")
option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." ON)
endif()
option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." ON)

if(MSVC)

Expand Down
13 changes: 10 additions & 3 deletions Emscripten-build-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ git clone https://github.com/emscripten-core/emsdk.git
./emsdk/emsdk install 3.1.73
```

and activate the emsdk environment
and activate the emsdk environment (we are defining SYSROOT_PATH for use later)

```bash
./emsdk/emsdk activate 3.1.73
source ./emsdk/emsdk_env.sh
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
```

Now clone the 19.x release of the LLVM project repository and CppInterOp (the building of the emscripten version of llvm can be
Expand Down Expand Up @@ -97,7 +98,7 @@ export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
```

Now to build CppInterOp execute the following
Now to build and test your Emscripten build of CppInterOp by executing the following

```bash
mkdir build
Expand All @@ -109,7 +110,14 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DSYSROOT_PATH=$SYSROOT_PATH \
../
emmake make -j $(nproc --all) check-cppinterop
```

Assuming it passes all test you can install by executing the following

```bash
emmake make -j $(nproc --all) install
```

Expand All @@ -126,7 +134,6 @@ the CppInterOp build folder, you can build the wasm version of xeus-cpp by execu

```bash
cd ../..
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
cd ./xeus-cpp
mkdir build
Expand Down
6 changes: 5 additions & 1 deletion cmake/CppInterOp/CppInterOpConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ endif()

### build/install workaround
if (@BUILD_SHARED_LIBS@)
set(_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX})
if(EMSCRIPTEN)
set(_lib_suffix ".wasm")
else()
set(_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
set(_lib_prefix ${CMAKE_SHARED_LIBRARY_PREFIX})
else()
set(_lib_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX})
Expand Down
49 changes: 40 additions & 9 deletions cmake/modules/GoogleTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ elseif(APPLE)
endif()

include(ExternalProject)
if(EMSCRIPTEN)

ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
Expand All @@ -31,15 +33,10 @@ ExternalProject_Add(
# CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
# -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
# -Dgtest_force_shared_crt=ON
CMAKE_ARGS -G ${CMAKE_GENERATOR}
-DCMAKE_BUILD_TYPE=$<CONFIG>
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_AR=${CMAKE_AR}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
${EXTRA_GTEST_OPTS}
CONFIGURE_COMMAND emcmake cmake -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-S ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest/
-B ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest-build/
BUILD_COMMAND emmake make
# Disable install step
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${_gtest_byproducts}
Expand All @@ -50,6 +47,40 @@ ExternalProject_Add(
TIMEOUT 600
)

else()

ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_SHALLOW 1
GIT_TAG v1.15.2
UPDATE_COMMAND ""
# # Force separate output paths for debug and release builds to allow easy
# # identification of correct lib in subsequent TARGET_LINK_LIBRARIES commands
# CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
# -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
# -Dgtest_force_shared_crt=ON
CMAKE_ARGS -G ${CMAKE_GENERATOR}
-DCMAKE_BUILD_TYPE=$<CONFIG>
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_AR=${CMAKE_AR}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
${EXTRA_GTEST_OPTS}
# Disable install step
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${_gtest_byproducts}
# Wrap download, configure and build steps in a script to log output
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
TIMEOUT 600
)

endif()

# Specify include dirs for gtest and gmock
ExternalProject_Get_Property(googletest source_dir)
set(GTEST_INCLUDE_DIR ${source_dir}/googletest/include)
Expand Down
13 changes: 10 additions & 3 deletions docs/Emscripten-build-instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ This can be installed by executing (we only currently support version
git clone https://github.com/emscripten-core/emsdk.git
./emsdk/emsdk install 3.1.73
and activate the emsdk environment
and activate the emsdk environment (we are defining SYSROOT_PATH for use later)

.. code:: bash
./emsdk/emsdk activate 3.1.73
source ./emsdk/emsdk_env.sh
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
Now clone the 19.x release of the LLVM project repository and CppInterOp
(the building of the emscripten version of llvm can be avoided by
Expand Down Expand Up @@ -115,7 +116,7 @@ You will also want to set a few environment variables
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
Now to build CppInterOp execute the following
Now to build and test your Emscripten build of CppInterOp by executing the following

.. code:: bash
Expand All @@ -128,7 +129,14 @@ Now to build CppInterOp execute the following
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DSYSROOT_PATH=$SYSROOT_PATH \
../
emmake make -j $(nproc --all) check-cppinterop
Assuming it passes all test you can install by executing the following.

.. code:: bash
emmake make -j $(nproc --all) install
Once this finishes building we need to take note of where we built
Expand All @@ -147,7 +155,6 @@ build folder, you can build the wasm version of xeus-cpp by executing
.. code:: bash
cd ../..
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
cd ./xeus-cpp
mkdir build
Expand Down
Loading

0 comments on commit 123e15c

Please sign in to comment.