version: 2.1
jobs:
  native-aliases-arm64:
    resource_class: arm.medium
    machine:
      image: ubuntu-2404:current
    environment:
      CFLAGS: -Wextra -Werror -march=native -DSIMDE_ENABLE_NATIVE_ALIASES -DSIMDE_NATIVE_ALIASES_TESTING
      CXXFLAGS: -Wextra -Werror -march=native -DSIMDE_ENABLE_NATIVE_ALIASES -DSIMDE_NATIVE_ALIASES_TESTING
      CC: gcc
      CXX: g++
    steps:
      - run: sudo apt-get update && sudo apt-get install -y git ninja-build pipx gcc-14 g++-14 libxml2-utils ccache
      - checkout
      - restore_cache:
         keys:
            - ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}
            - ccache-{{ .Environment.CIRCLE_JOB }}-master
            - ccache-{{ .Environment.CIRCLE_JOB }}
      - run: cat /proc/cpuinfo /proc/meminfo
      - run:
          command: |
            ccache --set-config=max_size='500M'
            ccache --set-config=compression=true
            ccache -p
            ccache -z
      - run: pipx install meson==1.3.2
      - run: ./test/native-aliases.sh
      - run: |
          export PATH=/usr/lib/ccache:${PATH}
          CC="ccache gcc-14" CXX="ccache g++-14" ${HOME}/.local/bin/meson setup build -Db_coverage=true
          ninja -C build -v -j $(nproc)
      - run: /usr/bin/ccache -s
      - save_cache:
          key: 'ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}-{{ epoch }}'
          paths: [ "/home/circleci/.cache/ccache" ]
          when: always
      - run: ninja -C build -v test

  gcc:
    resource_class: large
    docker:
      - image: debian:testing-slim
        auth:
          username: $DOCKERHUB_USERNAME
          password: $DOCKERHUB_PASSWORD
    environment:
      CFLAGS: -Wextra -Werror -march=native
      CXXFLAGS: -Wextra -Werror -march=native
      CC: gcc
      CXX: g++
    steps:
      - run: apt-get update && apt-get install -y git ssh ninja-build pipx python3-setuptools python3-wheel gcovr gcc g++ ccache
      - checkout
      - restore_cache:
         keys:
            - ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}
            - ccache-{{ .Environment.CIRCLE_JOB }}-master
            - ccache-{{ .Environment.CIRCLE_JOB }}
      - run: cat /proc/cpuinfo /proc/meminfo
      - run:
          command: |
            ccache --set-config=max_size='500M'
            ccache --set-config=compression=true
            ccache -p
            ccache -z
      - run: pipx install meson==1.3.2
      - run: |
          export PATH=/usr/lib/ccache:${PATH}
          CC="ccache gcc" CXX="ccache g++" /root/.local/bin/meson setup build
          ninja -C build -v -j 5
      - run: /usr/bin/ccache -s
      - save_cache:
          key: 'ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}-{{ epoch }}'
          paths: [ "/root/.cache/ccache" ]
          when: always
      - run: ninja -C build -v test

  portable-memfunctions:
    resource_class: large
    docker:
      - image: debian:testing-slim
        auth:
          username: $DOCKERHUB_USERNAME
          password: $DOCKERHUB_PASSWORD
    environment:
      CFLAGS: -Wextra -Werror -march=native -DSIMDE_NO_STDLIB
      CXXFLAGS: -Wextra -Werror -march=native -DSIMDE_NO_STDLIB
      CC: gcc
      CXX: g++
    steps:
      - run: apt-get update && apt-get install -y git ssh ninja-build pipx python3-setuptools python3-wheel gcovr gcc g++ ccache
      - checkout
      - restore_cache:
         keys:
            - ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}
            - ccache-{{ .Environment.CIRCLE_JOB }}-master
            - ccache-{{ .Environment.CIRCLE_JOB }}
      - run: cat /proc/cpuinfo /proc/meminfo
      - run:
          command: |
            ccache --set-config=max_size='500M'
            ccache --set-config=compression=true
            ccache -p
            ccache -z
      - run: pipx install meson==1.3.2
      - run: |
          export PATH=/usr/lib/ccache:${PATH}
          CC="ccache gcc" CXX="ccache g++" /root/.local/bin/meson setup build
          ninja -C build -v -j 5
      - run: /usr/bin/ccache -s
      - save_cache:
          key: 'ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}-{{ epoch }}'
          paths: [ "/root/.cache/ccache" ]
          when: always
      - run: ninja -C build -v test

  clang:
    resource_class: large
    docker:
      - image: debian:testing-slim
        auth:
          username: $DOCKERHUB_USERNAME
          password: $DOCKERHUB_PASSWORD
    environment:
      CFLAGS: -Weverything -Werror -march=native
      CXXFLAGS: -Weverything -Werror -march=native
    steps:
      - run: apt-get update && apt-get install -y git ssh ninja-build pipx python3-setuptools python3-wheel gcovr clang ccache
      - checkout
      - restore_cache:
         keys:
            - ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}
            - ccache-{{ .Environment.CIRCLE_JOB }}-master
            - ccache-{{ .Environment.CIRCLE_JOB }}
      - run: cat /proc/cpuinfo /proc/meminfo
      - run:
          command: |
            ccache --set-config=max_size='500M'
            ccache --set-config=compression=true
            ccache -p
            ccache -z
      - run: pipx install meson==1.3.2
      - run: |
          export PATH=/usr/lib/ccache:${PATH}
          CFLAGS="-Wno-unsafe-buffer-usage" CXXFLAGS="-Wno-unsafe-buffer-usage" CC="ccache clang" CXX="ccache clang++" /root/.local/bin/meson setup build
          ninja -C build -v -j 5
      - run: /usr/bin/ccache -s
      - save_cache:
          key: 'ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}-{{ epoch }}'
          paths: [ "/root/.cache/ccache" ]
          when: always
      - run: ninja -C build -v test

  i686:
    resource_class: large
    docker:
      - image: debian:testing-slim
        auth:
          username: $DOCKERHUB_USERNAME
          password: $DOCKERHUB_PASSWORD
    steps:
      - run: apt-get update && apt-get install -y git ssh ninja-build pipx python3-setuptools python3-wheel gcovr {gcc,g++}-i686-linux-gnu libc6-i386-cross qemu-user-static ccache
      - checkout
      - restore_cache:
         keys:
            - ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}
            - ccache-{{ .Environment.CIRCLE_JOB }}-master
            - ccache-{{ .Environment.CIRCLE_JOB }}
      - run:
          name: System Information
          command: cat /proc/cpuinfo /proc/meminfo
      - run: dpkg --add-architecture i386
      - run: pipx install meson==1.3.2
      - run:
          command: |
            ccache --set-config=max_size='500M'
            ccache --set-config=compression=true
            ccache -p
            ccache -z
      - run: |
          export PATH=/usr/lib/ccache:${PATH}
          /root/.local/bin/meson setup build --cross-file docker/cross-files/i686-gcc-qemu-ccache.cross
          /root/.local/bin/meson compile -C build --verbose -j 5
      - run: /usr/bin/ccache -s
      - save_cache:
          key: 'ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}-{{ epoch }}'
          paths: [ "/root/.cache/ccache" ]
          when: always
      - run: /root/.local/bin/meson test -C build --num-processes 5 --print-errorlogs

  i686-gcc12-O2:
    resource_class: large
    docker:
      - image: debian:stable-slim
        auth:
          username: $DOCKERHUB_USERNAME
          password: $DOCKERHUB_PASSWORD
    steps:
      - run: apt-get update && apt-get install -y git ssh ninja-build pipx python3-setuptools python3-wheel gcovr {gcc,g++}-12-i686-linux-gnu libc6-i386-cross qemu-user-static ccache build-essential
      - checkout
      - restore_cache:
         keys:
            - ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}
            - ccache-{{ .Environment.CIRCLE_JOB }}-master
            - ccache-{{ .Environment.CIRCLE_JOB }}
      - run:
          name: System Information
          command: cat /proc/cpuinfo /proc/meminfo
      - run: dpkg --add-architecture i386
      - run: pipx install meson==1.3.2
      - run:
          command: |
            ccache --set-config=max_size='500M'
            ccache --set-config=compression=true
            ccache -p
            ccache -z
      - run: |
          export PATH=/usr/lib/ccache:${PATH}
          /root/.local/bin/meson setup build --cross-file docker/cross-files/i686-gcc-12-qemu-ccache.cross
          /root/.local/bin/meson compile -C build --verbose -j 5
      - run: /usr/bin/ccache -s
      - save_cache:
          key: 'ccache-{{ .Environment.CIRCLE_JOB }}-{{ .Branch }}-{{ epoch }}'
          paths: [ "/root/.cache/ccache" ]
          when: always
      - run: /root/.local/bin/meson test -C build --num-processes 5 --print-errorlogs


workflows:
  version: 2
  test:
    jobs:
      - native-aliases-arm64:
          filters:
            branches:
              ignore:
              - /^ci/(?!circleci).*$/
      - portable-memfunctions:
          filters:
            branches:
              ignore:
              - /^ci/(?!circleci).*$/
      - gcc:
          filters:
            branches:
              ignore:
              - /^ci/(?!circleci).*$/
      - clang:
          filters:
            branches:
              ignore:
              - /^ci/(?!circleci).*$/
      # - i686:
      #     filters:
      #       branches:
      #         ignore:
      #         - /^ci/(?!circleci).*$/
      - i686-gcc12-O2:
          filters:
            branches:
              ignore:
              - /^ci/(?!circleci).*$/
