name: MacOS

on:
   push:
      branches: [ RC_1_2 RC_2_0 master ]
   pull_request:

concurrency:
   group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}
   cancel-in-progress: true

jobs:

   test:
      name: Tests
      runs-on: macos-latest
      continue-on-error: true

      strategy:
         matrix:
            config: [ crypto=built-in, deprecated-functions=off ]

      steps:
      - name: checkout
        uses: actions/checkout@v2
        with:
           submodules: true

      - uses: Chocobo1/setup-ccache-action@v1
        with:
          override_cache_key: ccache-macos-test-${{ matrix.config }}-${{ github.base_ref }}
          ccache_options: |
            max_size=1G

      - name: install boost
        run: |
          brew install boost-build boost openssl@1.1
          echo "using darwin ;" >>~/user-config.jam

      - name: build and run tests
        run: (cd test; b2 ${{ matrix.config }} -l400 warnings-as-errors=on debug-iterators=on invariant-checks=full asserts=on deterministic-tests)

      - name: run tests (flaky)
        uses: nick-invision/retry@v2
        with:
          timeout_minutes: 30
          retry_wait_seconds: 1
          max_attempts: 3
          command: (cd test; b2 ${{ matrix.config }} -l400 warnings-as-errors=on debug-iterators=on invariant-checks=full asserts=on)


   sim:
      name: Simulations
      runs-on: macos-latest

      steps:
      - name: checkout
        uses: actions/checkout@v2
        with:
           submodules: true

      - uses: Chocobo1/setup-ccache-action@v1
        with:
          override_cache_key: ccache-macos-sim-${{ github.base_ref }}
          ccache_options: |
            max_size=1G

      - name: install boost
        run: |
          brew install boost-build boost openssl@1.1
          echo "using darwin ;" >>~/user-config.jam

      - name: build and run simulations
        run: |
          cd simulation
          b2 -l400 debug-iterators=on invariant-checks=full asserts=on


   build:
      name: Build
      runs-on: macos-latest
      continue-on-error: true

      strategy:
         matrix:
            config: [ crypto=built-in, release ]

      steps:
      - name: checkout
        uses: actions/checkout@v2
        with:
           submodules: true

      - uses: Chocobo1/setup-ccache-action@v1
        with:
          override_cache_key: ccache-macos-build-${{ matrix.config }}-${{ github.base_ref }}
          ccache_options: |
            max_size=1G

      - name: install boost
        run: |
          brew install boost-build boost openssl@1.1
          echo "using darwin ;" >>~/user-config.jam

      - name: build library
        run: |
          b2 ${{ matrix.config }} -l400 warnings-as-errors=on cxxstd=14


   ios_build:
      name: Build iOS
      runs-on: macos-latest
      continue-on-error: true

      steps:
      - name: checkout
        uses: actions/checkout@v2.3.3
        with:
           submodules: true

      - name: install boost
        run: |
          brew install boost-build boost
          echo "using darwin : ios_sim : clang++ : <compileflags>-Wno-deprecated-declarations
          <compileflags>\"-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk\"
          <compileflags>-mios-simulator-version-min=7
          <compileflags>-fobjc-abi-version=2
          <linkflags>\"-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk\"
          <linkflags>-mios-simulator-version-min=7
          <linkflags>-fobjc-abi-version=2 ;" >>~/user-config.jam;

          echo "using darwin : ios : clang++ : <compileflags>-Wno-deprecated-declarations
          <compileflags>\"-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk\"
          <compileflags>-mios-version-min=7
          <compileflags>\"-arch armv7\"
          <compileflags>-fobjc-abi-version=2
          <linkflags>\"-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk\"
          <linkflags>-mios-version-min=7
          <linkflags>\"-arch armv7\"
          <linkflags>-fobjc-abi-version=2 ;" >>~/user-config.jam;

      - name: build library
        run: |
          b2 -l400 cxxstd=14 darwin-ios darwin-ios_sim address-model=64  link=static
