Skip to content

Commit

Permalink
[impl] update c4core: add support for compilation from emscripten
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Dec 25, 2021
1 parent 4a8f54a commit 78f3a6e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 6 deletions.
16 changes: 14 additions & 2 deletions .github/setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function c4_show_info()
echo "BM=$BM"
echo "STD=$STD"
echo "ARM=$ARM"
echo "LIBCXX=$LIBCXX"
echo "VERBOSE_MAKEFILES=$VERBOSE_MAKEFILES"
which cmake
cmake --version
case "$CXX_" in
Expand Down Expand Up @@ -194,6 +196,9 @@ function c4_cfg_test()
_addcmkflags -DC4_CXX_STANDARD=$STD
_addprojflags CXX_STANDARD=$STD
fi
if [ "$LIBCXX" != "" ] ; then
_addprojflags USE_LIBCXX=$LIBCXX
fi
#
if [ "$DEV" != "OFF" ] ; then
_addprojflags DEV=ON
Expand Down Expand Up @@ -231,6 +236,9 @@ function c4_cfg_test()
_addprojflags COVERAGE_CODECOV=ON COVERAGE_CODECOV_SILENT=ON
_addprojflags COVERAGE_COVERALLS=ON COVERAGE_COVERALLS_SILENT=ON
fi
if [ ! -z "$VERBOSE_MAKEFILES" ] ; then
_addcmkflags -DCMAKE_VERBOSE_MAKEFILES=$VERBOSE_MAKEFILES
fi
_addcmkflags -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
if [ ! -z "$CMAKE_FLAGS" ] ; then
_addcmkflags $CMAKE_FLAGS
Expand Down Expand Up @@ -290,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 -DCMAKE_CXX_FLAGS="-s DISABLE_EXCEPTION_CATCHING=0"
;;
*)
echo "unknown compiler"
exit 1
Expand Down Expand Up @@ -359,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
Expand All @@ -386,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
;;
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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: ryml-
PROJ_PFX_CMAKE: RYML_
CMAKE_FLAGS:
NUM_JOBS_BUILD: # 4
EMSCRIPTEN_CACHE_FOLDER: 'emsdk-cache'

jobs:

#----------------------------------------------------------------------------
emscripten:
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}}
strategy:
fail-fast: false
matrix:
include:
- {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: "${{matrix.emver}}-${{runner.os}}"}
- name: setup emscripten
uses: mymindstorm/setup-emsdk@v11
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
- {name: static32-build, run: source .github/setenv.sh && c4_build_test static32}
- {name: static32-run, run: source .github/setenv.sh && c4_run_test static32}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ ryml is written in C++11, and compiles cleanly with:
* Intel Compiler

ryml is [extensively unit-tested in Linux, Windows and
MacOS](https://github.com/biojppm/rapidyaml/actions). The
tests cover x64, x86, arm, aarch64, ppc64le and s390x architectures,
and include analysing ryml with:
MacOS](https://github.com/biojppm/rapidyaml/actions). The tests cover
x64, x86, arm, wasm (emscripten), aarch64, ppc64le and s390x
architectures, and include analysing ryml with:
* valgrind
* clang-tidy
* clang sanitizers:
Expand Down
1 change: 1 addition & 0 deletions changelog/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Tree expected = parse("{keyval0: val0, keyval1: {}, keyval2: []}");
assert(emitrs<std::string>(t) == emitrs<std::string>(expected));
```
- Add support for compilation with emscripten (WebAssembly+javascript) ([PR #173](https://github.com/biojppm/rapidyaml/pull/173)).
### Fixes
Expand Down
2 changes: 2 additions & 0 deletions samples/quickstart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2320,8 +2320,10 @@ void sample_formatting()
// AKA %a (hexadecimal formatting of floats)
CHECK("0x1.e8480p+19" == cat_sub(buf, fmt::real(1000000.000000000, 5, FTOA_HEXA))); // AKA %a
CHECK("0x1.2d53ap+20" == cat_sub(buf, fmt::real(1234234.234234234, 5, FTOA_HEXA))); // AKA %a
std::cout << cat_sub(buf, fmt::real(1234234.234234234, 4, FTOA_HEXA)) << "\n"; // AKA %a
CHECK("0x1.2d54p+20" == cat_sub(buf, fmt::real(1234234.234234234, 4, FTOA_HEXA))); // AKA %a
CHECK("0x1.2d5p+20" == cat_sub(buf, fmt::real(1234234.234234234, 3, FTOA_HEXA))); // AKA %a
std::cout << cat_sub(buf, fmt::real(1234234.234234234, 2, FTOA_HEXA)) << "\n"; // AKA %a
CHECK("0x1.2dp+20" == cat_sub(buf, fmt::real(1234234.234234234, 2, FTOA_HEXA))); // AKA %a

// --------------------------------------------------------------
Expand Down

0 comments on commit 78f3a6e

Please sign in to comment.