# Copyright 2020 Evan Miller
# Copyright 2020 Matt Borland
# Copyright 2021 John Maddock
# Copyright 2021 Christopher Kormanyos
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)

name: multiprecision
on:
  push:
    branches:
      - master
      - develop
  pull_request:
  release:
    types: [published, created, edited]

concurrency:
   group: ${{ github.head_ref || github.run_id }}
   cancel-in-progress: true

jobs:
  ubuntu-jammy:
    runs-on: ubuntu-22.04
    defaults:
      run:
        shell: bash
    strategy:
      fail-fast: false
      matrix:
        compiler: [ g++-12, clang++-14 ]
        standard: [ c++14, c++17, c++20, c++2b ]
        suite: [ github_ci_block_1, github_ci_block_2 ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Set TOOLSET
        run: echo ${{ matrix.compiler }} | awk '/^g/ { print "TOOLSET=gcc" } /^clang/ { print "TOOLSET=clang" }' >> $GITHUB_ENV
      - name: Add repository
        continue-on-error: true
        id: addrepo
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo
        continue-on-error: true
        id: retry1
        if: steps.addrepo.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo 2
        continue-on-error: true
        id: retry2
        if: steps.retry1.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Install packages
        run: sudo apt install g++-12 clang-14 libgmp-dev libmpfr-dev libtommath-dev libeigen3-dev libmpfi-dev libmpc-dev
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: cp -r $GITHUB_WORKSPACE/* libs/multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: ./bootstrap.sh
        working-directory: ../boost-root
      - name: Generate headers
        run: ./b2 headers
        working-directory: ../boost-root
      - name: Generate user config
        run: 'echo "using $TOOLSET : : ${{ matrix.compiler }} : <cxxflags>-std=${{ matrix.standard }} ;" > ~/user-config.jam'
        working-directory: ../boost-root
      - name: Config Info
        run: ../../../b2 print_config_info print_math_info toolset=$TOOLSET
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ../../../b2 -j2 toolset=$TOOLSET ${{ matrix.suite }} define=CI_SUPPRESS_KNOWN_ISSUES include=/usr/include/eigen3
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
  ubuntu-focal:
    runs-on: ubuntu-20.04
    defaults:
      run:
        shell: bash
    strategy:
      fail-fast: false
      matrix:
        compiler: [ g++-10, g++-11, clang++-10, clang++-11 ]
        standard: [ c++14, c++17, c++2a ]
        suite: [ github_ci_block_1, github_ci_block_2 ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Set TOOLSET
        run: echo ${{ matrix.compiler }} | awk '/^g/ { print "TOOLSET=gcc" } /^clang/ { print "TOOLSET=clang" }' >> $GITHUB_ENV
      - name: Add repository
        continue-on-error: true
        id: addrepo
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo
        continue-on-error: true
        id: retry1
        if: steps.addrepo.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo 2
        continue-on-error: true
        id: retry2
        if: steps.retry1.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Install packages
        run: sudo apt install g++-9 g++-10 g++-11 clang-10 clang-11 libgmp-dev libmpfr-dev libtommath-dev libeigen3-dev libmpfi-dev libmpc-dev
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: cp -r $GITHUB_WORKSPACE/* libs/multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: ./bootstrap.sh
        working-directory: ../boost-root
      - name: Generate headers
        run: ./b2 headers
        working-directory: ../boost-root
      - name: Generate user config
        run: 'echo "using $TOOLSET : : ${{ matrix.compiler }} : <cxxflags>-std=${{ matrix.standard }} ;" > ~/user-config.jam'
        working-directory: ../boost-root
      - name: Config Info
        run: ../../../b2 print_config_info print_math_info toolset=$TOOLSET
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ../../../b2 -j2 toolset=$TOOLSET ${{ matrix.suite }} define=CI_SUPPRESS_KNOWN_ISSUES include=/usr/include/eigen3
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
  ubuntu-focal-slow-tests:
    runs-on: ubuntu-20.04
    defaults:
      run:
        shell: bash
    strategy:
      fail-fast: false
      matrix:
        compiler: [ g++-10 ]
        standard: [ c++17, c++2a ]
        suite: [ specfun_mpfr, specfun_gmp, specfun_cpp_dec_float, specfun_cpp_bin_float, specfun_float128 ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Set TOOLSET
        run: echo ${{ matrix.compiler }} | awk '/^g/ { print "TOOLSET=gcc" } /^clang/ { print "TOOLSET=clang" }' >> $GITHUB_ENV
      - name: Add repository
        continue-on-error: true
        id: addrepo
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo
        continue-on-error: true
        id: retry1
        if: steps.addrepo.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo 2
        continue-on-error: true
        id: retry2
        if: steps.retry1.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Install packages
        run: sudo apt install g++-10 libgmp-dev libmpfr-dev libtommath-dev libeigen3-dev libmpfi-dev libmpc-dev
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: cp -r $GITHUB_WORKSPACE/* libs/multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: ./bootstrap.sh
        working-directory: ../boost-root
      - name: Generate headers
        run: ./b2 headers
        working-directory: ../boost-root
      - name: Generate user config
        run: 'echo "using $TOOLSET : : ${{ matrix.compiler }} : <cxxflags>-std=${{ matrix.standard }} ;" > ~/user-config.jam'
        working-directory: ../boost-root
      - name: Config Info
        run: ../../../b2 print_config_info print_math_info toolset=$TOOLSET
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ../../../b2 -j2 toolset=$TOOLSET ${{ matrix.suite }} define=CI_SUPPRESS_KNOWN_ISSUES include=/usr/include/eigen3
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
  ubuntu-focal-standalone-tests:
    runs-on: ubuntu-20.04
    defaults:
      run:
        shell: bash
    strategy:
      fail-fast: false
      matrix:
        compiler: [ g++-11 ]
        standard: [ c++14, c++17, c++20 ]
        suite: [ standalone ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Set TOOLSET
        run: echo ${{ matrix.compiler }} | awk '/^g/ { print "TOOLSET=gcc" } /^clang/ { print "TOOLSET=clang" }' >> $GITHUB_ENV
      - name: Add repository
        continue-on-error: true
        id: addrepo
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo
        continue-on-error: true
        id: retry1
        if: steps.addrepo.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo 2
        continue-on-error: true
        id: retry2
        if: steps.retry1.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Install packages
        run: sudo apt install g++-11 libgmp-dev libmpfr-dev libtommath-dev
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: cp -r $GITHUB_WORKSPACE/* libs/multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: ./bootstrap.sh
        working-directory: ../boost-root
      - name: Generate headers
        run: ./b2 headers
        working-directory: ../boost-root
      - name: Generate user config
        run: 'echo "using $TOOLSET : : ${{ matrix.compiler }} : <cxxflags>-std=${{ matrix.standard }} ;" > ~/user-config.jam'
        working-directory: ../boost-root
      - name: Config Info
        run: ../../../b2 print_config_info print_math_info toolset=$TOOLSET
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ../../../b2 -j2 toolset=$TOOLSET ${{ matrix.suite }} define=CI_SUPPRESS_KNOWN_ISSUES
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
  ubuntu-focal-ASAN:
    runs-on: ubuntu-20.04
    defaults:
      run:
        shell: bash
    strategy:
      fail-fast: false
      matrix:
        compiler: [ g++-10 ]
        standard: [ c++17 ]
        suite: [ arithmetic_tests, functions_and_limits, conversions, cpp_int_tests, misc ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Set TOOLSET
        run: echo ${{ matrix.compiler }} | awk '/^g/ { print "TOOLSET=gcc" } /^clang/ { print "TOOLSET=clang" }' >> $GITHUB_ENV
      - name: Add repository
        continue-on-error: true
        id: addrepo
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo
        continue-on-error: true
        id: retry1
        if: steps.addrepo.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo 2
        continue-on-error: true
        id: retry2
        if: steps.retry1.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Install packages
        run: sudo apt install g++-10 libgmp-dev libmpfr-dev libtommath-dev libeigen3-dev
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: cp -r $GITHUB_WORKSPACE/* libs/multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: ./bootstrap.sh
        working-directory: ../boost-root
      - name: Generate headers
        run: ./b2 headers
        working-directory: ../boost-root
      - name: Generate user config
        run: 'echo "using $TOOLSET : : ${{ matrix.compiler }} : <cxxflags>-std=${{ matrix.standard }} ;" > ~/user-config.jam'
        working-directory: ../boost-root
      - name: Config Info
        run: ../../../b2 print_config_info print_math_info toolset=$TOOLSET
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ../../../b2 define=BOOST_CI_ASAN_BUILD define=BOOST_CI_SANITIZER_BUILD cxxflags=-fsanitize=address linkflags=-fsanitize=address toolset=$TOOLSET ${{ matrix.suite }} define=CI_SUPPRESS_KNOWN_ISSUES
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
  ubuntu-focal-UBSAN:
    runs-on: ubuntu-20.04
    defaults:
      run:
        shell: bash
    strategy:
      fail-fast: false
      matrix:
        compiler: [ g++-10 ]
        standard: [ c++17 ]
        suite: [ arithmetic_tests, functions_and_limits, misc ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Set TOOLSET
        run: echo ${{ matrix.compiler }} | awk '/^g/ { print "TOOLSET=gcc" } /^clang/ { print "TOOLSET=clang" }' >> $GITHUB_ENV
      - name: Add repository
        continue-on-error: true
        id: addrepo
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo
        continue-on-error: true
        id: retry1
        if: steps.addrepo.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Retry Add Repo 2
        continue-on-error: true
        id: retry2
        if: steps.retry1.outcome=='failure'
        run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
      - name: Install packages
        run: sudo apt install g++-10 libgmp-dev libeigen3-dev
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: cp -r $GITHUB_WORKSPACE/* libs/multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: ./bootstrap.sh
        working-directory: ../boost-root
      - name: Generate headers
        run: ./b2 headers
        working-directory: ../boost-root
      - name: Generate user config
        run: 'echo "using $TOOLSET : : ${{ matrix.compiler }} : <cxxflags>-std=${{ matrix.standard }} ;" > ~/user-config.jam'
        working-directory: ../boost-root
      - name: Config Info
        run: ../../../b2 print_config_info print_math_info toolset=$TOOLSET
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ../../../b2 define=BOOST_CI_UBSAN_BUILD define=BOOST_CI_SANITIZER_BUILD cxxflags=-fsanitize=undefined linkflags=-fsanitize=undefined toolset=$TOOLSET ${{ matrix.suite }} define=CI_SUPPRESS_KNOWN_ISSUES
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
  windows_gcc:
    runs-on: windows-2019
    defaults:
      run:
        shell: cmd
    env:
      ARGS: toolset=${{ matrix.toolset }} address-model=64 cxxstd=${{ matrix.standard }}
    strategy:
      fail-fast: false
      matrix:
        toolset: [ gcc ]
        standard: [ 14, 17 ]
        suite: [ github_ci_block_1, github_ci_block_2 ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: xcopy /s /e /q %GITHUB_WORKSPACE% libs\multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: bootstrap
        working-directory: ../boost-root
      - name: Generate headers
        run: b2 headers
        working-directory: ../boost-root
      - name: Config Info
        run: ..\..\..\b2 print_config_info print_math_info %ARGS%
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ..\..\..\b2 -j2 --hash %ARGS% define=CI_SUPPRESS_KNOWN_ISSUES ${{ matrix.suite }}
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
  windows_msvc_14_0:
    runs-on: windows-2019
    defaults:
      run:
        shell: cmd
    env:
      ARGS: toolset=${{ matrix.toolset }} address-model=64 cxxstd=${{ matrix.standard }}
    strategy:
      fail-fast: false
      matrix:
        toolset: [ msvc-14.0 ]
        standard: [ 14, 17 ]
        suite: [ github_ci_block_1, github_ci_block_2 ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: xcopy /s /e /q %GITHUB_WORKSPACE% libs\multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: bootstrap
        working-directory: ../boost-root
      - name: Generate headers
        run: b2 headers
        working-directory: ../boost-root
      - name: Config Info
        run: ..\..\..\b2 print_config_info print_math_info %ARGS%
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ..\..\..\b2 -j2 --hash %ARGS% define=CI_SUPPRESS_KNOWN_ISSUES ${{ matrix.suite }}
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
  windows_msvc_14_2:
    runs-on: windows-2019
    defaults:
      run:
        shell: cmd
    env:
      ARGS: toolset=${{ matrix.toolset }} address-model=64 cxxstd=${{ matrix.standard }}
    strategy:
      fail-fast: false
      matrix:
        toolset: [ msvc-14.2 ]
        standard: [ 14, 17, 20 ]
        suite: [ github_ci_block_1, github_ci_block_2 ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: xcopy /s /e /q %GITHUB_WORKSPACE% libs\multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: bootstrap
        working-directory: ../boost-root
      - name: Generate headers
        run: b2 headers
        working-directory: ../boost-root
      - name: Config Info
        run: ..\..\..\b2 print_config_info print_math_info %ARGS%
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ..\..\..\b2 -j2 --hash %ARGS% define=CI_SUPPRESS_KNOWN_ISSUES ${{ matrix.suite }}
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
  macos:
    runs-on: macos-latest
    strategy:
      fail-fast: false
      matrix:
        toolset: [ clang ]
        standard: [ 14, 17, 2a ]
        suite: [ github_ci_block_1, github_ci_block_2 ]
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: '0'
      - name: Checkout main boost
        run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
      - name: Update tools/boostdep
        run: git submodule update --init tools/boostdep
        working-directory: ../boost-root
      - name: Copy files
        run: cp -r $GITHUB_WORKSPACE/* libs/multiprecision
        working-directory: ../boost-root
      - name: Install deps
        run: python tools/boostdep/depinst/depinst.py multiprecision
        working-directory: ../boost-root
      - name: Bootstrap
        run: ./bootstrap.sh
        working-directory: ../boost-root
      - name: Generate headers
        run: ./b2 headers
        working-directory: ../boost-root
      - name: Config Info
        run: ../../../b2 print_config_info print_math_info toolset=${{ matrix.toolset }} cxxstd=${{ matrix.standard }}
        working-directory: ../boost-root/libs/config/test
      - name: Test
        run: ../../../b2 -j2 toolset=${{ matrix.toolset }} cxxstd=${{ matrix.standard }} ${{ matrix.suite }} define=CI_SUPPRESS_KNOWN_ISSUES
        working-directory: ../boost-root/libs/multiprecision/test
      - name: b2 config
        run: cat bin.v2/config.log
        working-directory: ../boost-root/
