From 1548fa4404932a098b08d04f11cb7b930157bb45 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Mon, 12 Aug 2024 19:05:14 -0700 Subject: [PATCH] Enable emscripten in CI (#8) --- .github/workflows/ci.yml | 17 ++++++++++++++++- test/CMakeLists.txt | 6 ++++++ test/precondition_tests.cpp | 8 ++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab7e991..26263cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,7 @@ jobs: name: - Linux GCC - Linux Clang + - Linux Emscripten - MacOS Clang - MacOS GCC - Windows MSVC @@ -35,6 +36,8 @@ jobs: include: - compiler: clang++ + - cmake-launcher: '' + - name: 'Linux GCC' compiler: g++ os: ubuntu-latest @@ -53,6 +56,14 @@ jobs: compiler: cl os: windows-latest + - name: 'Linux Emscripten' + compiler: '' + os: ubuntu-latest + cmake-launcher: emcmake + + env: + compiler: ${{ matrix.compiler && format('-DCMAKE_CXX_COMPILER={0}', matrix.compiler) || '' }} + steps: - name: Install cppcheck run: ${{ runner.os == 'Windows' && 'choco install cppcheck -y' || runner.os == 'macOS' && 'brew install cppcheck' || runner.os == 'Linux' && 'sudo apt-get install cppcheck' }} @@ -72,6 +83,10 @@ jobs: exit 1 fi + - name: Set up Emscripten + uses: mymindstorm/setup-emsdk@v14 + if: ${{ contains(matrix.name, 'Emscripten') }} + - name: Set up MSVC (Windows) uses: compnerd/gha-setup-vsdevenv@main @@ -85,7 +100,7 @@ jobs: - name: Configure run: | - cmake -Wno-dev -S . -B ./build -GNinja -DCMAKE_CXX_COMPILER=${{matrix.compiler}} -DCMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} -DCMAKE_CXX_STANDARD=17 + ${{ matrix.cmake-launcher }} cmake -Wno-dev -S . -B ./build -GNinja ${{env.compiler}} -DCMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} -DCMAKE_CXX_STANDARD=17 - name: Build run: | diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6a1b550..d96600d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,6 +15,12 @@ if(PROJECT_IS_TOP_LEVEL OR TEST_INSTALLED_VERSION) endif() endif() + +if(EMSCRIPTEN) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fexceptions") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions") +endif() + # ---- Dependencies ---- include(GoogleTest) diff --git a/test/precondition_tests.cpp b/test/precondition_tests.cpp index c2eebd0..bd64648 100644 --- a/test/precondition_tests.cpp +++ b/test/precondition_tests.cpp @@ -1,15 +1,15 @@ #include "adobe/contract_checks.hpp" -#ifndef _WIN32 +#include +#if !defined(GTEST_OS_WINDOWS) && !defined(__EMSCRIPTEN__) #include #endif -#include ADOBE_DEFAULT_CONTRACT_VIOLATION_HANDLER() -#ifdef _WIN32 +#if defined(GTEST_OS_WINDOWS) || defined(__EMSCRIPTEN__) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define EXPECT_ABORT(code, expected_output_regex) \ - EXPECT_DEATH(code, expected_output_regex ".*\n*##ABORTED##"); + EXPECT_DEATH_IF_SUPPORTED(code, expected_output_regex ".*\n*##ABORTED##"); #else // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define EXPECT_ABORT(code, expected_output_regex) \