!yamlscript/v0:

:use common: :all
:: workflow-setup()

jobs:

  #----------------------------------------------------------------------------
  canary:
    :: setup-job('gcc' 'canary')
    name: canary/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}}
    :: runs-on-docker-c4core('${{matrix.img}}')
    strategy:
      fail-fast: false
      matrix:
        item =: \({:std %1, :cxx "g++-$a(%2)", :bt %3, :bitlinks 'shared64 static32', :img "$a(%4)"})
        include: &include1
        # use gcc13 because it's a lot faster than gcc14
        - ! item(11  13 'Debug'   '22.04')
        - ! item(11  13 'Release' '22.04')
        - ! item(20  13 'Debug'   '22.04')
        - ! item(20  13 'Release' '22.04')
        - ! item(11   5 'Debug'   '18.04')
        - ! item(11   5 'Release' '18.04')
        - ! item(11 4.8 'Debug'   '18.04')
        - ! item(11 4.8 'Release' '18.04')
    env:: load('share/env.yaml')
    steps:: checkout-manual + install-cxx + run-steps

  #----------------------------------------------------------------------------
  tabtokens:
    :: setup-job('gcc' 'tabtokens')
    name: tabtokens/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}}
    :: runs-on-docker-c4core('${{matrix.img}}')
    needs: canary
    strategy:
      fail-fast: false
      matrix:
        include: *include1
    env:: load('share/env.yaml') + {'CMAKE_FLAGS' '-DRYML_WITH_TAB_TOKENS=ON'}
    steps:: checkout-manual + install-cxx + run-steps

  #----------------------------------------------------------------------------
  noexceptions:
    :: setup-job('gcc' 'noexceptions')
    name: noexceptions/${{matrix.cxx}}/c++${{matrix.std}}/${{matrix.bt}}
    :: runs-on-docker-c4core('${{matrix.img}}')
    needs: canary
    strategy:
      fail-fast: false
      matrix:
        include: *include1
    env:: load('share/env.yaml') + {'CXXFLAGS' '-fno-exceptions -fno-rtti'}
    steps:: checkout-manual + install-cxx + run-steps

  #----------------------------------------------------------------------------
  misbuild:
    :: setup-job('gcc' 'misbuild')
    name: misbuild#${{matrix.issue}}/gcc${{matrix.gcc}}/c++${{matrix.std}}
    :: runs-on-docker-c4core('${{matrix.img}}')
    needs: canary
    strategy:
      fail-fast: false
      matrix:
        include:
        - {issue: 440, std: 11, gcc: 12 , bt: Release, img: 22.04, cxxflags: -O2 -DNDEBUG -g}
        - {issue: 486, std: 11, gcc: 11 , bt: Release, img: 22.04, cxxflags: -O3 -DNDEBUG}
    env:: load('share/env.yaml') + {'CXX_' '${{matrix.gcc}}'}
    steps:
    - :: checkout-action-docker
    - run: c4core-install g++-${{matrix.gcc}}
    - name: show info
      run: source .github/setenv.sh && c4_show_info
    - name: configure (issue \#${{matrix.issue}})
      run: |
        cmake -S . -B build \
          -DCMAKE_CXX_COMPILER=g++-${{matrix.gcc}} \
          -DCMAKE_C_COMPILER=gcc-${{matrix.gcc}} \
          -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_CXX_FLAGS_RELEASE="${{matrix.cxxflags}}" \
          -DRYML_BUILD_TESTS=ON \
          -DRYML_DBG=OFF
    - name: build (issue \#${{matrix.issue}})
      run: cmake --build build --target ryml-test-build --parallel --verbose
    - name: run (issue \#${{matrix.issue}})
      run: |
        source .github/setenv.sh
        export CTEST_PARALLEL_LEVEL=`_c4getnumcores`
        cmake --build build --target ryml-test-run

  #----------------------------------------------------------------------------
  # with valgrind too slow: only latest gcc

  strategy-latest-gcc =::
      fail-fast: false
      matrix:
        include:
          - {std: 20, cxx: 14, bits: 64, vg: ON , img: 22.04}
          - {std: 20, cxx: 14, bits: 32, vg: ON , img: 22.04}
          - {std: 17, cxx: 14, bits: 64, vg: ON , img: 22.04}
          - {std: 17, cxx: 14, bits: 32, vg: ON , img: 22.04}
          - {std: 14, cxx: 14, bits: 64, vg: ON , img: 22.04}
          - {std: 14, cxx: 14, bits: 32, vg: ON , img: 22.04}
          - {std: 11, cxx: 14, bits: 64, vg: ON , img: 22.04}
          - {std: 11, cxx: 14, bits: 32, vg: ON , img: 22.04}

  vg1:
    :: setup-job('gcc' 'vg1')
    name: extended/${{matrix.cxx}}/${{matrix.bits}}bit/c++${{matrix.std}}/vg/D_O1_O2
    :: runs-on-docker-c4core('${{matrix.img}}')
    needs: canary
    strategy:: strategy-latest-gcc
    env:: load('share/env.yaml')
    steps:
    - :: checkout-manual
    - name: install
      run: c4core-install g++-${{matrix.cxx}}
    - :: run-gcc-manual-with-flags('Debug'                '-m${{matrix.bits}}')
    - :: run-gcc-manual-with-flags('Release' '-O1 -DNDEBUG -m${{matrix.bits}}')
    - :: run-gcc-manual-with-flags('Release' '-O2 -DNDEBUG -m${{matrix.bits}}')

  vg2:
    :: setup-job('gcc' 'vg2')
    name: extended/${{matrix.cxx}}/${{matrix.bits}}bit/c++${{matrix.std}}/vg/O3_Os
    :: runs-on-docker-c4core('${{matrix.img}}')
    needs: canary
    strategy:: strategy-latest-gcc
    env:: load('share/env.yaml')
    steps:
    - :: checkout-manual
    - name: install
      run: c4core-install g++-${{matrix.cxx}}
    - :: run-gcc-manual-with-flags('Release' '-O3 -DNDEBUG -m${{matrix.bits}}')
    - :: run-gcc-manual-with-flags('Release' '-Os -DNDEBUG -m${{matrix.bits}}')

  #----------------------------------------------------------------------------
  # without valgrind: older versions
  extended:
    :: setup-job('gcc' 'extended')
    name: extended/${{matrix.cxx}}/${{matrix.bits}}bit/c++${{matrix.std}}
    :: runs-on-docker-c4core('${{matrix.img}}')
    needs: canary
    strategy:
      fail-fast: false
      matrix:
        include:
        - {std: 11, cxx: 13  , bits: 64, vg: OFF, img: 22.04}
        - {std: 11, cxx: 13  , bits: 32, vg: OFF, img: 22.04}
        - {std: 11, cxx: 12  , bits: 64, vg: OFF, img: 22.04}
        - {std: 11, cxx: 12  , bits: 32, vg: OFF, img: 22.04}
        - {std: 11, cxx: 11  , bits: 64, vg: OFF, img: 22.04}
        - {std: 11, cxx: 11  , bits: 32, vg: OFF, img: 22.04}
        - {std: 11, cxx: 10  , bits: 64, vg: OFF, img: 22.04}
        - {std: 11, cxx: 10  , bits: 32, vg: OFF, img: 22.04}
        - {std: 11, cxx:  9  , bits: 64, vg: OFF, img: 22.04}
        - {std: 11, cxx:  9  , bits: 32, vg: OFF, img: 22.04}
        - {std: 11, cxx:  8  , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx:  8  , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx:  7  , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx:  7  , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx:  6  , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx:  6  , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx:  5  , bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx:  5  , bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx:  4.9, bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx:  4.9, bits: 32, vg: OFF, img: 18.04}
        - {std: 11, cxx:  4.8, bits: 64, vg: OFF, img: 18.04}
        - {std: 11, cxx:  4.8, bits: 32, vg: OFF, img: 18.04}
    env:: load('share/env.yaml')
    steps:
    - :: checkout-manual
    - name: install
      run: c4core-install g++-${{matrix.cxx}}
    - :: run-gcc-manual-with-flags('Debug'                '-m${{matrix.bits}}')
    - :: run-gcc-manual-with-flags('Release' '-O1 -DNDEBUG -m${{matrix.bits}}')
    - :: run-gcc-manual-with-flags('Release' '-O2 -DNDEBUG -m${{matrix.bits}}')
    - :: run-gcc-manual-with-flags('Release' '-O3 -DNDEBUG -m${{matrix.bits}}')
    - :: run-gcc-manual-with-flags('Release' '-Os -DNDEBUG -m${{matrix.bits}}')

  #----------------------------------------------------------------------------
  gccsan:
    :: setup-job('gcc' 'gccsan')
    name: gccsan/${{matrix.bt}}/${{matrix.cxx}}/c++${{matrix.std}}
    :: runs-on-docker-c4core('22.04')
    needs: canary
    strategy:
      fail-fast: false
      matrix:
        include::
          ? for
              san qw(asan lsan tsan ubsan)
              std [11 14 17 20]
          : ! { std:: std, cxx: g++-14, bt:: san, bitlinks: static64 }
    env:: load('share/env.yaml')
    steps:: checkout-action-docker + install-cxx + run-steps

  #----------------------------------------------------------------------------
  arm:
    :: setup-job('gcc' 'arm') + runs-on-docker-c4core('18.04')
    name: arm/c++${{matrix.std}}/${{matrix.bt}}
    needs: canary
    strategy:
      fail-fast: false
      matrix:
        item =:
          \({:std %1, :bt %2, :cxx 'arm-linux-gnueabihf-gcc',
             :toolchain 'ext/c4core/cmake/Toolchain-Arm-ubuntu.cmake'})
        include:
        # these jobs take much longer, so run only one bitlink pair per job to
        # profit from parallelism
        - ! item(11 'Debug')
        - ! item(11 'Release')
        - ! item(14 'Debug')
        - ! item(14 'Release')
        - ! item(17 'Debug')
        - ! item(17 'Release')
    env:: -{'TOOLCHAIN' '${{matrix.toolchain}}'} + load('share/env.yaml')
    steps:
    - :: checkout-manual
    - name: install gcc-arm-linux-gnueabihf
      run:
        c4core-install arm-linux-gnueabihf;
        c4core-install qemu
    - name: show info
      run: source .github/setenv.sh && c4_show_info
    - name: configure---------------------------------------------------
      run: source .github/setenv.sh && c4_cfg_test arm
    - name: build
      run: source .github/setenv.sh && c4_build_test arm
    - name: run
      run: source .github/setenv.sh && c4_run_test arm
    - name: pack
      run: source .github/setenv.sh && c4_package arm

  #----------------------------------------------------------------------------
  #analyzer:
  #  :: setup-job('gcc' 'analyzer')
  #  name: analyzer/${{matrix.bits}}bit/${{matrix.bt}}
  #  :: runs-on-docker-c4core('${{matrix.img}}')
  #  strategy:
  #    fail-fast: false
  #    matrix:
  #      include:
  #      - {std: 11, gcc: 14, bits: 64, bt: Debug  , img: 22.04}
  #      - {std: 11, gcc: 14, bits: 64, bt: Release, img: 22.04}
  #      - {std: 11, gcc: 14, bits: 32, bt: Debug  , img: 22.04}
  #      - {std: 11, gcc: 14, bits: 32, bt: Release, img: 22.04}
  #  steps:
  #    - :: checkout-action-docker
  #    - name: install
  #      run: c4core-install g++-${{matrix.gcc}}
  #    - name: configure
  #      run: |
  #        cmake -S . -B build \
  #           -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
  #           -DCMAKE_GCC_COMPILER=g++-${{matrix.gcc}} \
  #           -DCMAKE_C_COMPILER=gcc-${{matrix.gcc}} \
  #           -DCMAKE_BUILD_TYPE=${{matrix.bt}} \
  #           -DRYML_DEV=ON \
  #           -DRYML_VALGRIND=OFF \
  #           -DRYML_BUILD_TESTS=ON \
  #           -DRYML_BUILD_BENCHMARKS=OFF \
  #           -DRYML_DBG=OFF \
  #           -DRYML_FANALYZER=ON
  #    - name: build
  #      run: cmake --build build --target ryml-test-build --parallel --verbose
  #    - name: run
  #      run: cmake --build build --target ryml-test-run --verbose
