From 90dc294e59a7898e62960ec2d5ff13092b53fa5a Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Wed, 22 Dec 2021 09:14:44 +0000 Subject: [PATCH 01/12] Fix CPU detection for Emscripten For https://github.com/biojppm/c4core/issues/50 --- src/c4/cpu.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/c4/cpu.hpp b/src/c4/cpu.hpp index 5bcf3a2e..32d7ba04 100644 --- a/src/c4/cpu.hpp +++ b/src/c4/cpu.hpp @@ -103,6 +103,10 @@ # define C4_WORDSIZE 8 # define C4_BYTE_ORDER _C4EB +#elif defined(__EMSCRIPTEN__) +# define C4_BYTE_ORDER _C4EL +# define C4_WORDSIZE 4 + #elif defined(SWIG) #error "please define CPU architecture macros when compiling with swig" From 273b65bb58aac6a345ca6052ae80c87a34b5c1ee Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Wed, 22 Dec 2021 09:15:00 +0000 Subject: [PATCH 02/12] Fixed std namespace for Emscripten For https://github.com/biojppm/c4core/issues/51 --- src/c4/std/vector_fwd.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/c4/std/vector_fwd.hpp b/src/c4/std/vector_fwd.hpp index bb0191bb..f61995a5 100644 --- a/src/c4/std/vector_fwd.hpp +++ b/src/c4/std/vector_fwd.hpp @@ -14,7 +14,11 @@ template class vector; #elif defined(_LIBCPP_VERSION) namespace std { template class allocator; +#if defined(__EMSCRIPTEN__) +inline namespace __2 { +#else inline namespace __1 { +#endif template class vector; } // namespace __1 } // namespace std From 4ff5050dc75086d079b515fcd42bc71b243de98b Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Thu, 23 Dec 2021 17:29:16 +0000 Subject: [PATCH 03/12] Added Emscripten to test CI --- .github/setenv.sh | 8 ++++++-- .github/workflows/test.yml | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.github/setenv.sh b/.github/setenv.sh index 6736fb22..7a9fe09e 100644 --- a/.github/setenv.sh +++ b/.github/setenv.sh @@ -298,6 +298,10 @@ function c4_cfg_test() -DCMAKE_C_FLAGS="-std=c99 -m$bits" -DCMAKE_CXX_FLAGS="-m$bits" cmake --build $build_dir --target help | sed 1d | sort ;; + em++) + emcmake cmake -S $PROJ_DIR -B $build_dir -DCMAKE_INSTALL_PREFIX="$install_dir" \ + -DCMAKE_BUILD_TYPE=$BT $CMFLAGS + ;; *) echo "unknown compiler" exit 1 @@ -367,7 +371,7 @@ function _c4_parallel_build_flags() echo "-IDEBuildOperationMaxNumberOfConcurrentCompileTasks=$NUM_JOBS_BUILD" fi ;; - *g++*|*gcc*|*clang*) + *g++*|*gcc*|*clang*|em++) if [ -z "$NUM_JOBS_BUILD" ] ; then echo "-j $(nproc)" else @@ -394,7 +398,7 @@ function _c4_generator_build_flags() # https://stackoverflow.com/questions/51153525/xcode-10-unable-to-attach-db-error echo "-UseModernBuildSystem=NO" ;; - *g++*|*gcc*|*clang*) + *g++*|*gcc*|*clang*|em++) ;; "") # allow empty compiler ;; diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7eb722d8..efc098a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,6 +22,8 @@ env: PROJ_PFX_CMAKE: C4CORE_ CMAKE_FLAGS: NUM_JOBS_BUILD: # 4 + EMSCRIPTEN_VERSION: 2.0.34 + EMSCRIPTEN_CACHE_FOLDER: 'emsdk-cache' # ubuntu-20.04: @@ -581,6 +583,36 @@ jobs: - {name: pack, run: source .github/setenv.sh && c4_package arm} #---------------------------------------------------------------------------- + emscripten: + name: emscripten/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}} + continue-on-error: true + if: always() # https://stackoverflow.com/questions/62045967/github-actions-is-there-a-way-to-continue-on-error-while-still-getting-correct + runs-on: ${{matrix.os}} + strategy: + fail-fast: false + matrix: + include: + - {std: 11, cxx: em++, bt: Debug , os: ubuntu-latest, bitlinks: static32} + - {std: 11, cxx: em++, bt: Release, os: ubuntu-latest, bitlinks: static32} + - {std: 20, cxx: em++, bt: Debug , os: ubuntu-latest, bitlinks: static32} + - {std: 20, cxx: em++, bt: Release, os: ubuntu-latest, bitlinks: static32} + env: {STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}", BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"} + steps: + - {name: checkout, uses: actions/checkout@v2, with: {submodules: recursive}} + - name: setup emscripten cache + id: cache-system-libraries + uses: actions/cache@v2 + with: {path: "${{env.EMSCRIPTEN_CACHE_FOLDER}}", key: "${{env.EMSCRIPTEN_VERSION}}-${{runner.os}}"} + - name: setup emscripten + uses: mymindstorm/setup-emsdk@v11 + with: {version: "${{env.EMSCRIPTEN_VERSION}}", actions-cache-folder: "${{env.EMSCRIPTEN_CACHE_FOLDER}}"} + - {name: show info, run: source .github/setenv.sh && c4_show_info} + - name: static32-configure--------------------------------------------------- + run: source .github/setenv.sh && c4_cfg_test static32 + - {name: static32-build, run: source .github/setenv.sh && c4_build_test static32} + - {name: static32-run, run: source .github/setenv.sh && c4_run_test static32} + + #---------------------------------------------------------------------------- # # https://blog.kitware.com/static-checks-with-cmake-cdash-iwyu-clang-tidy-lwyu-cpplint-and-cppcheck/ # static_analysis: # continue-on-error: true From b22f8b3a7c2375764c5aa1129f49b4a1936b4d1a Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Thu, 23 Dec 2021 17:55:47 +0000 Subject: [PATCH 04/12] Force exceptions to be enabled in Emscripten (disabled by default). --- .github/setenv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/setenv.sh b/.github/setenv.sh index 7a9fe09e..e173da42 100644 --- a/.github/setenv.sh +++ b/.github/setenv.sh @@ -300,7 +300,7 @@ function c4_cfg_test() ;; em++) emcmake cmake -S $PROJ_DIR -B $build_dir -DCMAKE_INSTALL_PREFIX="$install_dir" \ - -DCMAKE_BUILD_TYPE=$BT $CMFLAGS + -DCMAKE_BUILD_TYPE=$BT $CMFLAGS -DCMAKE_CXX_FLAGS="-s DISABLE_EXCEPTION_CATCHING=0" ;; *) echo "unknown compiler" From 568250aefb10079d06d2f8c5d0d1c6bc54f86403 Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Thu, 23 Dec 2021 19:27:23 +0000 Subject: [PATCH 05/12] [ci] try ci with emscripten 3.0.0 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index efc098a6..d6a8c767 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ env: PROJ_PFX_CMAKE: C4CORE_ CMAKE_FLAGS: NUM_JOBS_BUILD: # 4 - EMSCRIPTEN_VERSION: 2.0.34 + EMSCRIPTEN_VERSION: 3.0.0 EMSCRIPTEN_CACHE_FOLDER: 'emsdk-cache' From a3c8d6c1549fd5df112d77060962d77da1215438 Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Thu, 23 Dec 2021 19:44:38 +0000 Subject: [PATCH 06/12] [chore] update changelog/README [ci skip] --- README.md | 13 +++++++++++++ changelog/current.md | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 2dab43e5..fe7e77f5 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,19 @@ I've been using these utilities in this or similar forms for some years now, and I've found them incredibly useful in my projects. I'm packing these as a separate library, as all of my projects use it. +c4core is [extensively unit-tested in Linux, Windows and +MacOS](https://github.com/biojppm/c4core/actions). The tests cover +x64, x86, arm, wasm (emscripten), aarch64, ppc64le and s390x +architectures, and include analysing c4core with: + * valgrind + * clang-tidy + * clang sanitizers: + * memory + * address + * undefined behavior + * thread + * [LGTM.com](https://lgtm.com/projects/g/biojppm/c4core) + ## Obtaining c4core diff --git a/changelog/current.md b/changelog/current.md index 6c231713..974ddb7a 100644 --- a/changelog/current.md +++ b/changelog/current.md @@ -22,6 +22,7 @@ ``` - Add `csubstr::is_unsigned_integer()` and `csubstr::is_real()` ([PR #49](https://github.com/biojppm/c4core/pull/49)). - CMake: add alias target c4core::c4core, guaranteeing that the same code can be used with `add_subdirectory()` and `find_package()`. (see [rapidyaml #173](https://github.com/biojppm/rapidyaml/issues/173)) +- Add support for compilation with emscripten (WebAssembly+javascript) ` ([PR #52](https://github.com/biojppm/c4core/pull/52)). ### Fixes @@ -37,3 +38,6 @@ - In `c4/charconv.hpp`: do not use C4_ASSERT in `to_c_fmt()`, which is `constexpr`. +### Thanks + +- @cschreiber From 44724c50e8101fef48bf1f3d5363a758b24ac777 Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Thu, 23 Dec 2021 19:45:03 +0000 Subject: [PATCH 07/12] [ci] move emscripten to different file --- .github/workflows/emscripten.yml | 84 ++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 32 ------------ 2 files changed, 84 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/emscripten.yml diff --git a/.github/workflows/emscripten.yml b/.github/workflows/emscripten.yml new file mode 100644 index 00000000..eb4013fc --- /dev/null +++ b/.github/workflows/emscripten.yml @@ -0,0 +1,84 @@ +name: emscripten + +defaults: + #if: "!contains(github.event.head_commit.message, 'skip ci')" # SKIP + run: + # Use a bash shell so we can use the same syntax for environment variable + # access regardless of the host operating system + shell: bash -e -x {0} + +on: + # https://github.community/t/how-to-trigger-an-action-on-push-or-pull-request-but-not-both/16662 + workflow_dispatch: + push: + branches: + - master + pull_request: + branches: + - master + +env: + PROJ_PFX_TARGET: c4core- + PROJ_PFX_CMAKE: C4CORE_ + CMAKE_FLAGS: + NUM_JOBS_BUILD: # 4 + EMSCRIPTEN_VERSION: 3.0.0 + EMSCRIPTEN_CACHE_FOLDER: 'emsdk-cache' + + +# ubuntu-20.04: +# # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md +# gcc: 7.5.0, 8.4.0, 9.3.0, 10.2.0 +# clang: 8.0.1, 9.0.1, 10.0.0 +# ubuntu-18.04: +# # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md +# gcc: 7.5.0, 8.4.0, 9.3.0, 10.1.0 +# clang: 6.0.0, 8.0.0, 9.0.0 +# macos-11.0: macOS Big Sur 11.0 +# # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11.0-Readme.md +# Xcode 12.1 11.7 +# clang/LLVM 10.0.1 +# gcc-8 gcc-9 +# macos-10.15: macOS Catalina 10.15 +# # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md +# Xcode 12.1 11.7 +# clang/LLVM 11.0.0 +# gcc-8 gcc-9 +# windows-2019: +# # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md +# vs2019 +# windows-2016: +# # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2016-Readme.md +# vs2017 + +jobs: + + #---------------------------------------------------------------------------- + emscripten: + name: emscripten/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}} + continue-on-error: true + if: always() # https://stackoverflow.com/questions/62045967/github-actions-is-there-a-way-to-continue-on-error-while-still-getting-correct + runs-on: ${{matrix.os}} + strategy: + fail-fast: false + matrix: + include: + - {std: 11, cxx: em++, bt: Debug , os: ubuntu-latest, bitlinks: static32} + - {std: 11, cxx: em++, bt: Release, os: ubuntu-latest, bitlinks: static32} + - {std: 20, cxx: em++, bt: Debug , os: ubuntu-latest, bitlinks: static32} + - {std: 20, cxx: em++, bt: Release, os: ubuntu-latest, bitlinks: static32} + env: {STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}", BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"} + steps: + - {name: checkout, uses: actions/checkout@v2, with: {submodules: recursive}} + - name: setup emscripten cache + id: cache-system-libraries + uses: actions/cache@v2 + with: {path: "${{env.EMSCRIPTEN_CACHE_FOLDER}}", key: "${{env.EMSCRIPTEN_VERSION}}-${{runner.os}}"} + - name: setup emscripten + uses: mymindstorm/setup-emsdk@v11 + with: {version: "${{env.EMSCRIPTEN_VERSION}}", actions-cache-folder: "${{env.EMSCRIPTEN_CACHE_FOLDER}}"} + - {name: show info, run: source .github/setenv.sh && c4_show_info} + - name: static32-configure--------------------------------------------------- + run: source .github/setenv.sh && c4_cfg_test static32 + - {name: static32-build, run: source .github/setenv.sh && c4_build_test static32} + - {name: static32-run, run: source .github/setenv.sh && c4_run_test static32} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d6a8c767..7eb722d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,8 +22,6 @@ env: PROJ_PFX_CMAKE: C4CORE_ CMAKE_FLAGS: NUM_JOBS_BUILD: # 4 - EMSCRIPTEN_VERSION: 3.0.0 - EMSCRIPTEN_CACHE_FOLDER: 'emsdk-cache' # ubuntu-20.04: @@ -583,36 +581,6 @@ jobs: - {name: pack, run: source .github/setenv.sh && c4_package arm} #---------------------------------------------------------------------------- - emscripten: - name: emscripten/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}} - continue-on-error: true - if: always() # https://stackoverflow.com/questions/62045967/github-actions-is-there-a-way-to-continue-on-error-while-still-getting-correct - runs-on: ${{matrix.os}} - strategy: - fail-fast: false - matrix: - include: - - {std: 11, cxx: em++, bt: Debug , os: ubuntu-latest, bitlinks: static32} - - {std: 11, cxx: em++, bt: Release, os: ubuntu-latest, bitlinks: static32} - - {std: 20, cxx: em++, bt: Debug , os: ubuntu-latest, bitlinks: static32} - - {std: 20, cxx: em++, bt: Release, os: ubuntu-latest, bitlinks: static32} - env: {STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}", BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"} - steps: - - {name: checkout, uses: actions/checkout@v2, with: {submodules: recursive}} - - name: setup emscripten cache - id: cache-system-libraries - uses: actions/cache@v2 - with: {path: "${{env.EMSCRIPTEN_CACHE_FOLDER}}", key: "${{env.EMSCRIPTEN_VERSION}}-${{runner.os}}"} - - name: setup emscripten - uses: mymindstorm/setup-emsdk@v11 - with: {version: "${{env.EMSCRIPTEN_VERSION}}", actions-cache-folder: "${{env.EMSCRIPTEN_CACHE_FOLDER}}"} - - {name: show info, run: source .github/setenv.sh && c4_show_info} - - name: static32-configure--------------------------------------------------- - run: source .github/setenv.sh && c4_cfg_test static32 - - {name: static32-build, run: source .github/setenv.sh && c4_build_test static32} - - {name: static32-run, run: source .github/setenv.sh && c4_run_test static32} - - #---------------------------------------------------------------------------- # # https://blog.kitware.com/static-checks-with-cmake-cdash-iwyu-clang-tidy-lwyu-cpplint-and-cppcheck/ # static_analysis: # continue-on-error: true From 334ad16789aa4657daacf2f5a51ba20c1469ddbd Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Thu, 23 Dec 2021 23:47:56 +0000 Subject: [PATCH 08/12] [test] fix printing of atof test failures --- test/test_charconv.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_charconv.cpp b/test/test_charconv.cpp index 366a1a0e..d3223f01 100644 --- a/test/test_charconv.cpp +++ b/test/test_charconv.cpp @@ -1162,7 +1162,7 @@ void test_rtoa(substr buf, Real f, rtoa_fn_t rtoa_fn, int precision, const size_t ret; INFO("num=" << f << " precision=" << precision - << "' hexa='" << hexa << "' hexa_alternative='" << hexa_alternative << "'"); + << " hexa='" << hexa << "' hexa_alternative='" << hexa_alternative << "'"); memset(buf.str, 0, buf.len); ret = rtoa_fn(buf, f, precision, FTOA_SCIENT); @@ -1186,7 +1186,7 @@ void test_rtoa(substr buf, Real f, rtoa_fn_t rtoa_fn, int precision, const std::string report; from_chars(buf.left_of(ret), &report); bool ok = buf.left_of(ret) == to_csubstr(hexa) || buf.left_of(ret) == to_csubstr(hexa_alternative); - CHECK_MESSAGE(ok, "ret='" << report); + CHECK_MESSAGE(ok, "ret='" << report << "'"); } From 9cc90469749956212967344d474a98289ace8e9a Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Thu, 23 Dec 2021 23:45:53 +0000 Subject: [PATCH 09/12] [fix] bitmask: bug revealed by emscripten: was reading from dangling pointer --- src/c4/bitmask.hpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/c4/bitmask.hpp b/src/c4/bitmask.hpp index 1e9a61f9..8c239da3 100644 --- a/src/c4/bitmask.hpp +++ b/src/c4/bitmask.hpp @@ -88,10 +88,11 @@ bm2stream(Stream &s, Enum value, EnumOffsetType offst=EOFFS_PFX) // some utility macros, undefed below +/// @cond dev -/** Execute @p code if the @p num of characters is available in the str +/* Execute `code` if the `num` of characters is available in the str * buffer. This macro simplifies the code for bm2str(). - * @todo improve this by writing from the end and moving only once. */ + * @todo improve performance by writing from the end and moving only once. */ #define _c4prependchars(code, num) \ if(str && (pos + num <= sz)) \ { \ @@ -100,19 +101,29 @@ bm2stream(Stream &s, Enum value, EnumOffsetType offst=EOFFS_PFX) /* now write in the beginning of the string */ \ code; \ } \ - else if(str && sz) { C4_ERROR("cannot write to string pos=%d num=%d sz=%d", (int)pos, (int)num, (int)sz); } \ + else if(str && sz) \ + { \ + C4_ERROR("cannot write to string pos=%d num=%d sz=%d", \ + (int)pos, (int)num, (int)sz); \ + } \ pos += num -/** Execute @p code if the @p num of characters is available in the str +/* Execute `code` if the `num` of characters is available in the str * buffer. This macro simplifies the code for bm2str(). */ #define _c4appendchars(code, num) \ if(str && (pos + num <= sz)) \ { \ code; \ } \ - else if(str && sz) { C4_ERROR("cannot write to string pos=%d num=%d sz=%d", (int)pos, (int)num, (int)sz); } \ + else if(str && sz) \ + { \ + C4_ERROR("cannot write to string pos=%d num=%d sz=%d", \ + (int)pos, (int)num, (int)sz); \ + } \ pos += num +/// @endcond + /** convert a bitmask to string. * return the number of characters written. To find the needed size, @@ -131,13 +142,13 @@ size_t bm2str auto syms = esyms(); size_t pos = 0; - typename EnumSymbols::Sym const* zero = nullptr; + typename EnumSymbols::Sym const* C4_RESTRICT zero = nullptr; // do reverse iteration to give preference to composite enum symbols, // which are likely to appear later in the enum sequence for(size_t i = syms.size()-1; i != size_t(-1); --i) { - auto const p = syms[i]; + auto const &C4_RESTRICT p = syms[i]; // do not copy, we are assigning to `zero` I b = static_cast(p.value); if(b == 0) { From 0daf2ee99552c11894064a65c54e17ff934ec2fc Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Fri, 24 Dec 2021 00:16:53 +0000 Subject: [PATCH 10/12] [ci] emscripten: reinstate tests with 2.0.34 --- .github/workflows/emscripten.yml | 29 ++++++++++++++++++++--------- changelog/current.md | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.github/workflows/emscripten.yml b/.github/workflows/emscripten.yml index eb4013fc..996ecfbd 100644 --- a/.github/workflows/emscripten.yml +++ b/.github/workflows/emscripten.yml @@ -22,7 +22,6 @@ env: PROJ_PFX_CMAKE: C4CORE_ CMAKE_FLAGS: NUM_JOBS_BUILD: # 4 - EMSCRIPTEN_VERSION: 3.0.0 EMSCRIPTEN_CACHE_FOLDER: 'emsdk-cache' @@ -55,7 +54,7 @@ jobs: #---------------------------------------------------------------------------- emscripten: - name: emscripten/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}} + name: emscripten/${{matrix.emver}}/c++${{matrix.std}}/${{matrix.bt}} continue-on-error: true if: always() # https://stackoverflow.com/questions/62045967/github-actions-is-there-a-way-to-continue-on-error-while-still-getting-correct runs-on: ${{matrix.os}} @@ -63,20 +62,32 @@ jobs: fail-fast: false matrix: include: - - {std: 11, cxx: em++, bt: Debug , os: ubuntu-latest, bitlinks: static32} - - {std: 11, cxx: em++, bt: Release, os: ubuntu-latest, bitlinks: static32} - - {std: 20, cxx: em++, bt: Debug , os: ubuntu-latest, bitlinks: static32} - - {std: 20, cxx: em++, bt: Release, os: ubuntu-latest, bitlinks: static32} - env: {STD: "${{matrix.std}}", CXX_: "${{matrix.cxx}}", BT: "${{matrix.bt}}", BITLINKS: "${{matrix.bitlinks}}", VG: "${{matrix.vg}}", SAN: "${{matrix.san}}", LINT: "${{matrix.lint}}", OS: "${{matrix.os}}"} + - {std: 11, cxx: em++, emver: 2.0.34, bt: Debug , os: ubuntu-latest, bitlinks: static32} + - {std: 11, cxx: em++, emver: 2.0.34, bt: Release, os: ubuntu-latest, bitlinks: static32} + - {std: 20, cxx: em++, emver: 2.0.34, bt: Debug , os: ubuntu-latest, bitlinks: static32} + - {std: 20, cxx: em++, emver: 2.0.34, bt: Release, os: ubuntu-latest, bitlinks: static32} + - {std: 11, cxx: em++, emver: 3.0.0 , bt: Debug , os: ubuntu-latest, bitlinks: static32} + - {std: 11, cxx: em++, emver: 3.0.0 , bt: Release, os: ubuntu-latest, bitlinks: static32} + - {std: 20, cxx: em++, emver: 3.0.0 , bt: Debug , os: ubuntu-latest, bitlinks: static32} + - {std: 20, cxx: em++, emver: 3.0.0 , bt: Release, os: ubuntu-latest, bitlinks: static32} + env: + STD: "${{matrix.std}}" + CXX_: "${{matrix.cxx}}" + BT: "${{matrix.bt}}" + BITLINKS: "${{matrix.bitlinks}}" + VG: "${{matrix.vg}}" + SAN: "${{matrix.san}}" + LINT: "${{matrix.lint}}" + OS: "${{matrix.os}}" steps: - {name: checkout, uses: actions/checkout@v2, with: {submodules: recursive}} - name: setup emscripten cache id: cache-system-libraries uses: actions/cache@v2 - with: {path: "${{env.EMSCRIPTEN_CACHE_FOLDER}}", key: "${{env.EMSCRIPTEN_VERSION}}-${{runner.os}}"} + with: {path: "${{env.EMSCRIPTEN_CACHE_FOLDER}}", key: "${{matrix.emver}}-${{runner.os}}"} - name: setup emscripten uses: mymindstorm/setup-emsdk@v11 - with: {version: "${{env.EMSCRIPTEN_VERSION}}", actions-cache-folder: "${{env.EMSCRIPTEN_CACHE_FOLDER}}"} + with: {version: "${{matrix.emver}}", actions-cache-folder: "${{env.EMSCRIPTEN_CACHE_FOLDER}}"} - {name: show info, run: source .github/setenv.sh && c4_show_info} - name: static32-configure--------------------------------------------------- run: source .github/setenv.sh && c4_cfg_test static32 diff --git a/changelog/current.md b/changelog/current.md index 974ddb7a..5a1db2ed 100644 --- a/changelog/current.md +++ b/changelog/current.md @@ -40,4 +40,4 @@ ### Thanks -- @cschreiber +- @cschreib From c820d5787d9e1e3d5f086e0a4ea02ef26b48f230 Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Fri, 24 Dec 2021 00:22:32 +0000 Subject: [PATCH 11/12] [tidy] expose coverage misses --- src/c4/charconv.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/c4/charconv.hpp b/src/c4/charconv.hpp index 0d0deff1..9b57e764 100644 --- a/src/c4/charconv.hpp +++ b/src/c4/charconv.hpp @@ -1209,8 +1209,10 @@ inline bool atod(csubstr str, double * C4_RESTRICT v) inline size_t atof_first(csubstr str, float * C4_RESTRICT v) { csubstr trimmed = str.first_real_span(); - if(trimmed.len == 0) return csubstr::npos; - if(atof(trimmed, v)) return static_cast(trimmed.end() - str.begin()); + if(trimmed.len == 0) + return csubstr::npos; + if(atof(trimmed, v)) + return static_cast(trimmed.end() - str.begin()); return csubstr::npos; } @@ -1222,8 +1224,10 @@ inline size_t atof_first(csubstr str, float * C4_RESTRICT v) inline size_t atod_first(csubstr str, double * C4_RESTRICT v) { csubstr trimmed = str.first_real_span(); - if(trimmed.len == 0) return csubstr::npos; - if(atod(trimmed, v)) return static_cast(trimmed.end() - str.begin()); + if(trimmed.len == 0) + return csubstr::npos; + if(atod(trimmed, v)) + return static_cast(trimmed.end() - str.begin()); return csubstr::npos; } From 9275c7362de41a947156c9b7b66f6718c548d0b0 Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Fri, 24 Dec 2021 00:34:07 +0000 Subject: [PATCH 12/12] [fix] add workaround for emscripten hexadecimal sprintf of floats see the problem at https://github.com/biojppm/c4core/pull/52 --- test/test_charconv.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/test/test_charconv.cpp b/test/test_charconv.cpp index d3223f01..e676baec 100644 --- a/test/test_charconv.cpp +++ b/test/test_charconv.cpp @@ -1196,6 +1196,18 @@ TEST_CASE("ftoa.basic") substr buf(bufc); C4_ASSERT(buf.len == sizeof(bufc)-1); + // earlier versions of emscripten's sprintf() do not respect some + // precision values when printing in hexadecimal format. + // + // @see https://github.com/biojppm/c4core/pull/52 + #if defined(__EMSCRIPTEN__) && __EMSCRIPTEN_major__ < 3 + #define _c4emscripten_alt(alt) , alt + #define _c4emscripten_alt2(alt1, alt2) , alt2 + #else + #define _c4emscripten_alt(alt) + #define _c4emscripten_alt2(alt1, alt2) , alt1 + #endif + float f = 1.1234123f; double d = 1.1234123; @@ -1205,11 +1217,11 @@ TEST_CASE("ftoa.basic") test_rtoa(buf, f, &ftoa, 1, /*scient*/"1.1e+00", /*flt*/"1.1", /*flex*/"1.1", /*hexa*/"0x1.2p+0"); test_rtoa(buf, d, &dtoa, 1, /*scient*/"1.1e+00", /*flt*/"1.1", /*flex*/"1.1", /*hexa*/"0x1.2p+0"); - test_rtoa(buf, f, &ftoa, 2, /*scient*/"1.12e+00", /*flt*/"1.12", /*flex*/"1.12", /*hexa*/"0x1.20p+0"); - test_rtoa(buf, d, &dtoa, 2, /*scient*/"1.12e+00", /*flt*/"1.12", /*flex*/"1.12", /*hexa*/"0x1.20p+0"); + test_rtoa(buf, f, &ftoa, 2, /*scient*/"1.12e+00", /*flt*/"1.12", /*flex*/"1.12", /*hexa*/"0x1.20p+0" _c4emscripten_alt("0x1.1f8p+0")); + test_rtoa(buf, d, &dtoa, 2, /*scient*/"1.12e+00", /*flt*/"1.12", /*flex*/"1.12", /*hexa*/"0x1.20p+0" _c4emscripten_alt("0x1.1f8p+0")); - test_rtoa(buf, f, &ftoa, 3, /*scient*/"1.123e+00", /*flt*/"1.123", /*flex*/"1.123", /*hexa*/"0x1.1f9p+0"); - test_rtoa(buf, d, &dtoa, 3, /*scient*/"1.123e+00", /*flt*/"1.123", /*flex*/"1.123", /*hexa*/"0x1.1f9p+0"); + test_rtoa(buf, f, &ftoa, 3, /*scient*/"1.123e+00", /*flt*/"1.123", /*flex*/"1.123", /*hexa*/"0x1.1f9p+0" _c4emscripten_alt("0x1.1f98p+0")); + test_rtoa(buf, d, &dtoa, 3, /*scient*/"1.123e+00", /*flt*/"1.123", /*flex*/"1.123", /*hexa*/"0x1.1f9p+0" _c4emscripten_alt("0x1.1f98p+0")); test_rtoa(buf, f, &ftoa, 4, /*scient*/"1.1234e+00", /*flt*/"1.1234", /*flex*/"1.1234", /*hexa*/"0x1.1f98p+0"); test_rtoa(buf, d, &dtoa, 4, /*scient*/"1.1234e+00", /*flt*/"1.1234", /*flex*/"1.1234", /*hexa*/"0x1.1f98p+0"); @@ -1226,8 +1238,8 @@ TEST_CASE("ftoa.basic") test_rtoa(buf, f, &ftoa, 2, /*scient*/"1.01e+00", /*flt*/"1.01", /*flex*/"1.01", /*hexa*/"0x1.03p+0"); test_rtoa(buf, d, &dtoa, 2, /*scient*/"1.01e+00", /*flt*/"1.01", /*flex*/"1.01", /*hexa*/"0x1.03p+0"); - test_rtoa(buf, f, &ftoa, 3, /*scient*/"1.012e+00", /*flt*/"1.012", /*flex*/"1.012", /*hexa*/"0x1.033p+0", /*hexa*/"0x1.032p+0"); - test_rtoa(buf, d, &dtoa, 3, /*scient*/"1.012e+00", /*flt*/"1.012", /*flex*/"1.012", /*hexa*/"0x1.033p+0", /*hexa*/"0x1.032p+0"); + test_rtoa(buf, f, &ftoa, 3, /*scient*/"1.012e+00", /*flt*/"1.012", /*flex*/"1.012", /*hexa*/"0x1.033p+0" _c4emscripten_alt2("0x1.032p+0", "0x1.0328p+0")); + test_rtoa(buf, d, &dtoa, 3, /*scient*/"1.012e+00", /*flt*/"1.012", /*flex*/"1.012", /*hexa*/"0x1.033p+0" _c4emscripten_alt2("0x1.032p+0", "0x1.0328p+0")); test_rtoa(buf, f, &ftoa, 4, /*scient*/"1.0123e+00", /*flt*/"1.0123", /*flex*/"1.0123", /*hexa*/"0x1.0329p+0"); test_rtoa(buf, d, &dtoa, 4, /*scient*/"1.0123e+00", /*flt*/"1.0123", /*flex*/"1.0123", /*hexa*/"0x1.0329p+0");