Skip to content

Commit 6ed5bc8

Browse files
committed
Add automated tests for Emscripten builds
1 parent b797dbb commit 6ed5bc8

20 files changed

+339
-97
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 to 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: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,49 @@ if(WIN32)
1313
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL:PATH=${_gtest_byproduct_binary_dir}/lib/
1414
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=${_gtest_byproduct_binary_dir}/lib/
1515
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO:PATH=${_gtest_byproduct_binary_dir}/lib/
16-
-Dgtest_force_shared_crt=ON
17-
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG>)
16+
-Dgtest_force_shared_crt=ON)
1817
elseif(APPLE)
1918
set(EXTRA_GTEST_OPTS -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT})
2019
endif()
2120

2221
include(ExternalProject)
23-
ExternalProject_Add(
24-
googletest
25-
GIT_REPOSITORY https://github.com/google/googletest.git
26-
GIT_SHALLOW 1
27-
GIT_TAG v1.15.2
28-
UPDATE_COMMAND ""
29-
# # Force separate output paths for debug and release builds to allow easy
30-
# # identification of correct lib in subsequent TARGET_LINK_LIBRARIES commands
31-
# CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
32-
# -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
33-
# -Dgtest_force_shared_crt=ON
34-
CMAKE_ARGS -G ${CMAKE_GENERATOR}
22+
if (EMSCRIPTEN)
23+
set(CONFIGURE_COMMAND emcmake cmake -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
24+
-S ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest/
25+
-B ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest-build/)
26+
set(BUILD_COMMAND emmake make)
27+
else()
28+
set(CONFIGURE_COMMAND ${CMAKE_COMMAND}
29+
-S ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest/
30+
-B ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest-build/
31+
-G ${CMAKE_GENERATOR}
3532
-DCMAKE_BUILD_TYPE=$<CONFIG>
3633
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
3734
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
3835
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
3936
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
4037
-DCMAKE_AR=${CMAKE_AR}
4138
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
42-
${EXTRA_GTEST_OPTS}
43-
# Disable install step
44-
INSTALL_COMMAND ""
45-
BUILD_BYPRODUCTS ${_gtest_byproducts}
46-
# Wrap download, configure and build steps in a script to log output
47-
LOG_DOWNLOAD ON
48-
LOG_CONFIGURE ON
49-
LOG_BUILD ON
50-
TIMEOUT 600
39+
${EXTRA_GTEST_OPTS})
40+
set(BUILD_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/unittests/googletest-prefix/src/googletest-build/ --config $<CONFIG>)
41+
endif()
42+
43+
ExternalProject_Add(
44+
googletest
45+
GIT_REPOSITORY https://github.com/google/googletest.git
46+
GIT_SHALLOW 1
47+
GIT_TAG v1.15.2
48+
UPDATE_COMMAND ""
49+
CONFIGURE_COMMAND ${CONFIGURE_COMMAND}
50+
BUILD_COMMAND ${BUILD_COMMAND}
51+
# Disable install step
52+
INSTALL_COMMAND ""
53+
BUILD_BYPRODUCTS ${_gtest_byproducts}
54+
# Wrap download, configure and build steps in a script to log output
55+
LOG_DOWNLOAD ON
56+
LOG_CONFIGURE ON
57+
LOG_BUILD ON
58+
TIMEOUT 600
5159
)
5260

5361
# Specify include dirs for gtest and gmock

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)