Skip to content

Commit 123e15c

Browse files
committed
Add automated tests for Emscripten builds
1 parent b797dbb commit 123e15c

20 files changed

+335
-82
lines changed

.github/workflows/deploy-pages.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ jobs:
9393
if: ${{ runner.os != 'windows' }}
9494
shell: bash -l {0}
9595
run: |
96+
set -e
9697
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
9798
source ./emsdk/emsdk_env.sh
9899
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
99-
100+
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
100101
export PREFIX=$MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm
101102
export CMAKE_PREFIX_PATH=$PREFIX
102103
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
@@ -130,6 +131,7 @@ jobs:
130131
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
131132
-DCMAKE_INSTALL_PREFIX=$PREFIX \
132133
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
134+
-DSYSROOT_PATH=$SYSROOT_PATH \
133135
../
134136
else
135137
emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
@@ -141,13 +143,15 @@ jobs:
141143
-DCODE_COVERAGE=${{ env.CODE_COVERAGE }} \
142144
-DCMAKE_INSTALL_PREFIX=$PREFIX \
143145
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
146+
-DSYSROOT_PATH=$SYSROOT_PATH \
144147
../
145148
fi
146-
149+
emmake make -j ${{ env.ncpus }} check-cppinterop
147150
emmake make -j ${{ env.ncpus }} install
148151
149152
cd ..
150-
153+
154+
echo "SYSROOT_PATH=$SYSROOT_PATH" >> $GITHUB_ENV
151155
echo "CB_PYTHON_DIR=$CB_PYTHON_DIR" >> $GITHUB_ENV
152156
echo "CPPINTEROP_BUILD_DIR=$CPPINTEROP_BUILD_DIR" >> $GITHUB_ENV
153157
echo "CPPINTEROP_DIR=$CPPINTEROP_DIR" >> $GITHUB_ENV
@@ -160,7 +164,6 @@ jobs:
160164
run: |
161165
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
162166
source ./emsdk/emsdk_env.sh
163-
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
164167
micromamba activate CppInterOp-wasm
165168
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
166169
cd ./xeus-cpp
@@ -175,7 +178,7 @@ jobs:
175178
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
176179
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
177180
-DCppInterOp_DIR="${{ env.CPPINTEROP_BUILD_DIR }}/lib/cmake/CppInterOp" \
178-
-DSYSROOT_PATH=$SYSROOT_PATH \
181+
-DSYSROOT_PATH=${{ env.SYSROOT_PATH }} \
179182
..
180183
emmake make -j ${{ env.ncpus }} install
181184

.github/workflows/emscripten.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,11 @@ jobs:
550550
if: ${{ runner.os != 'windows' }}
551551
shell: bash -l {0}
552552
run: |
553+
set -e
553554
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
554555
source ./emsdk/emsdk_env.sh
555556
micromamba create -f environment-wasm.yml --platform=emscripten-wasm32
556-
557+
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
557558
export PREFIX=$MAMBA_ROOT_PREFIX/envs/CppInterOp-wasm
558559
export CMAKE_PREFIX_PATH=$PREFIX
559560
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
@@ -587,6 +588,7 @@ jobs:
587588
-DCMAKE_INSTALL_PREFIX=$PREFIX \
588589
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
589590
-DLLVM_ENABLE_WERROR=On \
591+
-DSYSROOT_PATH=$SYSROOT_PATH \
590592
../
591593
else
592594
emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
@@ -599,13 +601,15 @@ jobs:
599601
-DCMAKE_INSTALL_PREFIX=$PREFIX \
600602
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
601603
-DLLVM_ENABLE_WERROR=On \
604+
-DSYSROOT_PATH=$SYSROOT_PATH \
602605
../
603606
fi
604-
605-
emmake make -j ${{ env.ncpus }} install
606607
608+
emmake make -j ${{ env.ncpus }} check-cppinterop
609+
emmake make -j ${{ env.ncpus }} install
607610
cd ..
608-
611+
612+
echo "SYSROOT_PATH=$SYSROOT_PATH" >> $GITHUB_ENV
609613
echo "CB_PYTHON_DIR=$CB_PYTHON_DIR" >> $GITHUB_ENV
610614
echo "CPPINTEROP_BUILD_DIR=$CPPINTEROP_BUILD_DIR" >> $GITHUB_ENV
611615
echo "CPPINTEROP_DIR=$CPPINTEROP_DIR" >> $GITHUB_ENV
@@ -618,7 +622,6 @@ jobs:
618622
run: |
619623
./emsdk/emsdk activate ${{matrix.emsdk_ver}}
620624
source ./emsdk/emsdk_env.sh
621-
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
622625
micromamba activate CppInterOp-wasm
623626
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
624627
cd ./xeus-cpp
@@ -633,6 +636,6 @@ jobs:
633636
-DXEUS_CPP_EMSCRIPTEN_WASM_BUILD=ON \
634637
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
635638
-DCppInterOp_DIR="${{ env.CPPINTEROP_BUILD_DIR }}/lib/cmake/CppInterOp" \
636-
-DSYSROOT_PATH=$SYSROOT_PATH \
639+
-DSYSROOT_PATH=${{ env.SYSROOT_PATH }} \
637640
..
638641
emmake make -j ${{ env.ncpus }} install

CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,15 @@ endif()
361361

362362
# Add appropriate flags for GCC
363363
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
364-
if (APPLE)
364+
if (APPLE OR EMSCRIPTEN)
365365
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")
366366
else()
367367
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")
368368
endif ()
369+
# Needed due an error which occurs when you compile gtest on emscripten
370+
if (EMSCRIPTEN)
371+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
372+
endif()
369373
endif ()
370374

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

453457

454-
if(EMSCRIPTEN)
455-
message("Build with emscripten")
456-
option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." OFF)
457-
else()
458-
message("Build with cmake")
459-
option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." ON)
460-
endif()
458+
option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." ON)
461459

462460
if(MSVC)
463461

Emscripten-build-instructions.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ git clone https://github.com/emscripten-core/emsdk.git
2525
./emsdk/emsdk install 3.1.73
2626
```
2727

28-
and activate the emsdk environment
28+
and activate the emsdk environment (we are defining SYSROOT_PATH for use later)
2929

3030
```bash
3131
./emsdk/emsdk activate 3.1.73
3232
source ./emsdk/emsdk_env.sh
33+
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
3334
```
3435

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

100-
Now to build CppInterOp execute the following
101+
Now to build and test your Emscripten build of CppInterOp by executing the following
101102

102103
```bash
103104
mkdir build
@@ -109,7 +110,14 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
109110
-DBUILD_SHARED_LIBS=ON \
110111
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
111112
-DCMAKE_INSTALL_PREFIX=$PREFIX \
113+
-DSYSROOT_PATH=$SYSROOT_PATH \
112114
../
115+
emmake make -j $(nproc --all) check-cppinterop
116+
```
117+
118+
Assuming it passes all test you can install by executing the following
119+
120+
```bash
113121
emmake make -j $(nproc --all) install
114122
```
115123

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

127135
```bash
128136
cd ../..
129-
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
130137
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
131138
cd ./xeus-cpp
132139
mkdir build

cmake/CppInterOp/CppInterOpConfig.cmake.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ endif()
1717

1818
### build/install workaround
1919
if (@BUILD_SHARED_LIBS@)
20-
set(_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX})
20+
if(EMSCRIPTEN)
21+
set(_lib_suffix ".wasm")
22+
else()
23+
set(_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX})
24+
endif()
2125
set(_lib_prefix ${CMAKE_SHARED_LIBRARY_PREFIX})
2226
else()
2327
set(_lib_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX})

cmake/modules/GoogleTest.cmake

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ elseif(APPLE)
2020
endif()
2121

2222
include(ExternalProject)
23+
if(EMSCRIPTEN)
24+
2325
ExternalProject_Add(
2426
googletest
2527
GIT_REPOSITORY https://github.com/google/googletest.git
@@ -31,15 +33,10 @@ ExternalProject_Add(
3133
# CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
3234
# -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
3335
# -Dgtest_force_shared_crt=ON
34-
CMAKE_ARGS -G ${CMAKE_GENERATOR}
35-
-DCMAKE_BUILD_TYPE=$<CONFIG>
36-
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
37-
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
38-
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
39-
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
40-
-DCMAKE_AR=${CMAKE_AR}
41-
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
42-
${EXTRA_GTEST_OPTS}
36+
CONFIGURE_COMMAND emcmake cmake -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
37+
-S ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest/
38+
-B ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest-build/
39+
BUILD_COMMAND emmake make
4340
# Disable install step
4441
INSTALL_COMMAND ""
4542
BUILD_BYPRODUCTS ${_gtest_byproducts}
@@ -50,6 +47,40 @@ ExternalProject_Add(
5047
TIMEOUT 600
5148
)
5249

50+
else()
51+
52+
ExternalProject_Add(
53+
googletest
54+
GIT_REPOSITORY https://github.com/google/googletest.git
55+
GIT_SHALLOW 1
56+
GIT_TAG v1.15.2
57+
UPDATE_COMMAND ""
58+
# # Force separate output paths for debug and release builds to allow easy
59+
# # identification of correct lib in subsequent TARGET_LINK_LIBRARIES commands
60+
# CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
61+
# -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
62+
# -Dgtest_force_shared_crt=ON
63+
CMAKE_ARGS -G ${CMAKE_GENERATOR}
64+
-DCMAKE_BUILD_TYPE=$<CONFIG>
65+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
66+
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
67+
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
68+
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
69+
-DCMAKE_AR=${CMAKE_AR}
70+
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
71+
${EXTRA_GTEST_OPTS}
72+
# Disable install step
73+
INSTALL_COMMAND ""
74+
BUILD_BYPRODUCTS ${_gtest_byproducts}
75+
# Wrap download, configure and build steps in a script to log output
76+
LOG_DOWNLOAD ON
77+
LOG_CONFIGURE ON
78+
LOG_BUILD ON
79+
TIMEOUT 600
80+
)
81+
82+
endif()
83+
5384
# Specify include dirs for gtest and gmock
5485
ExternalProject_Get_Property(googletest source_dir)
5586
set(GTEST_INCLUDE_DIR ${source_dir}/googletest/include)

docs/Emscripten-build-instructions.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ This can be installed by executing (we only currently support version
3535
git clone https://github.com/emscripten-core/emsdk.git
3636
./emsdk/emsdk install 3.1.73
3737
38-
and activate the emsdk environment
38+
and activate the emsdk environment (we are defining SYSROOT_PATH for use later)
3939

4040
.. code:: bash
4141
4242
./emsdk/emsdk activate 3.1.73
4343
source ./emsdk/emsdk_env.sh
44+
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
4445
4546
Now clone the 19.x release of the LLVM project repository and CppInterOp
4647
(the building of the emscripten version of llvm can be avoided by
@@ -115,7 +116,7 @@ You will also want to set a few environment variables
115116
export CMAKE_PREFIX_PATH=$PREFIX
116117
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
117118
118-
Now to build CppInterOp execute the following
119+
Now to build and test your Emscripten build of CppInterOp by executing the following
119120

120121
.. code:: bash
121122
@@ -128,7 +129,14 @@ Now to build CppInterOp execute the following
128129
-DBUILD_SHARED_LIBS=ON \
129130
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
130131
-DCMAKE_INSTALL_PREFIX=$PREFIX \
132+
-DSYSROOT_PATH=$SYSROOT_PATH \
131133
../
134+
emmake make -j $(nproc --all) check-cppinterop
135+
136+
Assuming it passes all test you can install by executing the following.
137+
138+
.. code:: bash
139+
132140
emmake make -j $(nproc --all) install
133141
134142
Once this finishes building we need to take note of where we built
@@ -147,7 +155,6 @@ build folder, you can build the wasm version of xeus-cpp by executing
147155
.. code:: bash
148156
149157
cd ../..
150-
export SYSROOT_PATH=$PWD/emsdk/upstream/emscripten/cache/sysroot
151158
git clone --depth=1 https://github.com/compiler-research/xeus-cpp.git
152159
cd ./xeus-cpp
153160
mkdir build

0 commit comments

Comments
 (0)