os:
  - linux
  - osx
  - windows

dist: bionic
osx_image: xcode12

cache:
  apt: true
  directories:
    - $HOME/.cache/bazel/

addons:
  apt:
    sources:
      - sourceline: 'deb https://storage.googleapis.com/bazel-apt stable jdk1.8'
        key_url: 'https://bazel.build/bazel-release.pub.gpg'
    packages:
      - bazel
  homebrew:
    packages: bazel

language: c

before_install:
  - if [ "$TRAVIS_OS_NAME" = "windows" ]; then choco install bazel; fi

install:
  - echo "build --compilation_mode=opt" > $HOME/.bazelrc
  - if [ "$TRAVIS_OS_NAME" != "windows" ]; then echo "build --conlyopt=-std=c99" > $HOME/.bazelrc; fi
  - echo "build --disk_cache=$HOME/.cache/bazel/" >> $HOME/.bazelrc
  - echo "build --announce_rc" >> $HOME/.bazelrc
  - echo "build --keep_going" >> $HOME/.bazelrc
  - echo "build --strategy=Javac=worker" >> $HOME/.bazelrc
  - echo "build --build_tag_filters=-no$TRAVIS_OS_NAME" >> $HOME/.bazelrc
  - echo "test --test_tag_filters=-no$TRAVIS_OS_NAME" >> $HOME/.bazelrc
  - echo "test --test_output=errors" >> $HOME/.bazelrc
  - echo "test --test_verbose_timeout_warnings" >> $HOME/.bazelrc

before_script:
  - mkdir -p "$HOME/.cache/bazel/"
  - bazel version

script:
  - bazel test //ryu/... //src/...
  - if [ "$TRAVIS_OS_NAME" = "osx" ]; then bazel test --run_under="leaks --atExit -- " //ryu/...; fi
  - bazel run -c opt //ryu/benchmark:ryu_benchmark --
  - bazel run -c opt //ryu/benchmark:ryu_printf_benchmark -- -samples=200
  - bazel test --copt=-DRYU_ONLY_64_BIT_OPS //ryu/...
  - bazel run -c opt --copt=-DRYU_ONLY_64_BIT_OPS //ryu/benchmark:ryu_benchmark --
  - bazel run -c opt --copt=-DRYU_ONLY_64_BIT_OPS //ryu/benchmark:ryu_printf_benchmark -- -samples=200
  - bazel test --copt=-DRYU_OPTIMIZE_SIZE //ryu/...
  - bazel run -c opt --copt=-DRYU_OPTIMIZE_SIZE //ryu/benchmark:ryu_benchmark --
  - bazel run -c opt --copt=-DRYU_OPTIMIZE_SIZE //ryu/benchmark:ryu_printf_benchmark -- -samples=200
  - bazel test --copt=-DRYU_OPTIMIZE_SIZE --copt=-DRYU_ONLY_64_BIT_OPS //ryu/...
  - bazel run -c opt --copt=-DRYU_OPTIMIZE_SIZE --copt=-DRYU_ONLY_64_BIT_OPS //ryu/benchmark:ryu_benchmark
  - bazel run -c opt --copt=-DRYU_OPTIMIZE_SIZE --copt=-DRYU_ONLY_64_BIT_OPS //ryu/benchmark:ryu_printf_benchmark -- -samples=200
  - bazel test -c opt --copt=-DRYU_FLOAT_FULL_TABLE //ryu/...
  - bazel test -c opt --copt=-DRYU_ONLY_64_BIT_OPS --copt=-DRYU_32_BIT_PLATFORM //ryu/...
