language: c
env:
  - PATH=$PATH:/usr/local/opt/binutils/bin
script:
  - |
    if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
        if [[ "$TRAVIS_COMPILER" == "clang" ]]; then
           choco install cygwin cyg-get && \
           cyg-get.bat default autoconf automake make gcc-core clang pkg-config libpcre-devel cmake python27-setuptools ruby wget && \
           export SHELLOPTS && set -o igncr && \
           cmd.exe //C "C:\\tools\\cygwin\\bin\\bash.exe -lc 'cd /cygdrive/$TRAVIS_BUILD_DIR; make header; make'" 
        else
           choco install cygwin cyg-get && \
           cyg-get.bat default autoconf automake make gcc-core clang pkg-config libpcre-devel cmake python27-setuptools ruby wget && \
           export SHELLOPTS && set -o igncr && \
           cmd.exe //C "C:\\tools\\cygwin\\bin\\bash.exe -lc 'cd /cygdrive/$TRAVIS_BUILD_DIR; make header; make; ./install-cmocka-linux.sh; export PATH="$PATH":/cygdrive/$TRAVIS_BUILD_DIR:/cygdrive/$TRAVIS_BUILD_DIR/cmocka/src; make test'"
        fi 
    elif [[ "$TRAVIS_CPU_ARCH" == "arm64" ]]; then
        make header && make && make -C tests/unit test && make -C tests/regress test
    else
        make header && make && make -C bindings/go && make -C bindings/go test && make test    
    fi
compiler:
  - clang
  - gcc
os:
  - linux
  - windows
arch:
  - amd64
  - arm64
matrix:
  fast_finish: true
  exclude:
    - os: windows
      arch: arm64
  include:

    - name: "Compiler: clang C"
      os: osx
      osx_image: xcode10.1
      python: 3.7
      compiler: clang
      before_cache:
        - brew cleanup
        - find /usr/local/Homebrew \! -regex ".+\.git.+" -delete;
      cache:
        directories:
          - $HOME/Library/Caches/Homebrew
          - /usr/local/Homebrew
      before_install:
        - cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core && git stash && git clean -d -f
      script:
        - cd $TRAVIS_BUILD_DIR
        - make header && make && make -C bindings/go && make -C bindings/go test && make test

    - name: "Compiler: gcc C"
      os: osx
      osx_image: xcode10.1
      python: 3.7
      compiler: gcc
      before_cache:
        - brew cleanup
        - find /usr/local/Homebrew \! -regex ".+\.git.+" -delete;
      cache:
        directories:
          - $HOME/Library/Caches/Homebrew
          - /usr/local/Homebrew
      before_install:
        - cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core && git stash && git clean -d -f
      script:
        - cd $TRAVIS_BUILD_DIR
        - make header && make && make -C bindings/go && make -C bindings/go test && make test

    - name: "Linux clang ASAN"
      os: linux
      compiler: clang
      env:
        - PATH=$PATH:/usr/local/opt/binutils/bin
        - ASAN_OPTIONS=detect_leaks=0
        - CXXFLAGS="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize=fuzzer-no-link"
        - CFLAGS="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize=fuzzer-no-link"
        - LDFLAGS="-fsanitize=address"
      script: 
        - make header && make
        - make -C tests/fuzz && sh tests/fuzz/dlcorpus.sh

    - name: "Linux clang MSAN"
      os: linux
      compiler: clang
      env:
        - PATH=$PATH:/usr/local/opt/binutils/bin
        - ASAN_OPTIONS=detect_leaks=0
        - CXXFLAGS="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=memory -fsanitize=fuzzer-no-link"
        - CFLAGS="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=memory -fsanitize=fuzzer-no-link"
        - LDFLAGS="-fsanitize=memory"
      script: 
        - make header && make
        - make -C tests/fuzz && sh tests/fuzz/dlcorpus.sh

    - name: "Linux clang USAN"
      os: linux
      compiler: clang
      env:
        - PATH=$PATH:/usr/local/opt/binutils/bin
        - ASAN_OPTIONS=detect_leaks=0
        - CXXFLAGS="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined -fsanitize=fuzzer-no-link"
        - CFLAGS="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined -fsanitize=fuzzer-no-link"
        - LDFLAGS="-fsanitize=undefined"
      script: 
        - make header && make
        - make -C tests/fuzz && sh tests/fuzz/dlcorpus.sh

    - name: "Linux 32bit"
      os: linux
      compiler: gcc
      env:
        - CFLAGS="-m32" LDFLAGS="-m32" LDFLAGS_STATIC="-m32" UNICORN_QEMU_FLAGS="--cpu=i386"
        - PATH=$PATH:/usr/local/opt/binutils/bin
      script: make header && make && make -C tests/unit test && make -C tests/regress test
      addons:
        apt:
          packages:
            - lib32ncurses5-dev
            - lib32z1-dev
            - libpthread-stubs0-dev
            - lib32gcc-4.8-dev
            - libc6-dev-i386
            - gcc-multilib
            - libcmocka-dev:i386

    - name: "Linux Cmake 32bit"
      os: linux
      compiler: gcc
      env: 
        - CFLAGS="-m32" LDFLAGS="-m32" LDFLAGS_STATIC="-m32" UNICORN_QEMU_FLAGS="--cpu=i386"
        - PATH=$PATH:/usr/local/opt/binutils/bin
      script:
        - mkdir build
        - cd build
        - ../cmake.sh x86
        - cp libunicorn.* ../
        - make -C ../tests/unit test && make -C ../tests/regress test
      addons:
        apt:
          packages:
            - lib32ncurses5-dev
            - lib32z1-dev
            - libpthread-stubs0-dev
            - lib32gcc-4.8-dev
            - libc6-dev-i386
            - gcc-multilib
            - libcmocka-dev:i386

    - name: "Linux Cmake 64bit"
      os: linux
      compiler: gcc
      env:
        - PATH=$PATH:/usr/local/opt/binutils/bin
      script:
        - mkdir build
        - cd build
        - ../cmake.sh
        - cp libunicorn.* ../
        - make -C ../tests/unit test && make -C ../tests/regress test

    - name: "Linux Cmake Static 32bit"
      os: linux
      compiler: gcc
      env: 
        - CFLAGS="-m32" LDFLAGS="-m32" LDFLAGS_STATIC="-m32" UNICORN_QEMU_FLAGS="--cpu=i386"
        - PATH=$PATH:/usr/local/opt/binutils/bin
      script:
        - mkdir build
        - cd build
        - cmake -DCMAKE_BUILD_TYPE=Release -DUNICORN_ARCH=x86 -DUNICORN_BUILD_SHARED=OFF .. && make -j8
# temporarily disable test for static build
#        - cp libunicorn.* ../
#        - make -C ../tests/unit test && make -C ../tests/regress test
      addons:
        apt:
          packages:
            - lib32ncurses5-dev
            - lib32z1-dev
            - libpthread-stubs0-dev
            - lib32gcc-4.8-dev
            - libc6-dev-i386
            - gcc-multilib
            - libcmocka-dev:i386

    - name: "Linux Cmake Static 64bit"
      os: linux
      compiler: gcc
      env:
        - PATH=$PATH:/usr/local/opt/binutils/bin
      script:
        - mkdir build
        - cd build
        - cmake -DCMAKE_BUILD_TYPE=Release -DUNICORN_BUILD_SHARED=OFF .. && make -j8
#        - cp libunicorn.* ../
#        - make -C ../tests/unit test && make -C ../tests/regress test

    - name: "MacOSX brew"
      os: osx
      osx_image: xcode10.1
      python: 3.7
      before_cache:
        - brew cleanup
        - find /usr/local/Homebrew \! -regex ".+\.git.+" -delete;
      cache:
        directories:
          - $HOME/Library/Caches/Homebrew
          - /usr/local/Homebrew
      before_install:
        - cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core && git stash && git clean -d -f
      script:
        - brew install --HEAD unicorn
        - brew test unicorn

    - name: "Windows nmake 32bit"
      os: windows
      language: shell
      script:
        - mkdir build
        - cd build
        - cmd.exe //C 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat' x86 '&' cmd.exe //C '..\nmake.bat' x86 

    - name: "Windows nmake 64bit"
      os: windows
      language: shell
      script:
        - mkdir build
        - cd build
        - cmd.exe //C 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat' amd64 '&' cmd.exe //C '..\nmake.bat'

    - name: "Windows MSVC 32bit"
      os: windows
      language: shell
      env:
        - MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
      script:
        - PATH=$MSBUILD_PATH:$PATH
        - cmd.exe //C 'msbuild.exe msvc/unicorn.sln /m:2 /nologo /p:Configuration=Release /p:Platform=Win32'

    - name: "Windows MSVC 64bit"
      os: windows
      language: shell
      env:
        - MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
      script:
        - PATH=$MSBUILD_PATH:$PATH
        - cmd.exe //C 'msbuild.exe msvc/unicorn.sln /m:2 /nologo /p:Configuration=Release /p:Platform=x64'

    - name: "Windows MSYS2/MinGW32"
      os: windows
      language: shell
      env:
        - PATH=/C/tools/msys64/mingw32/bin:$PATH
      before_install:
        - |
          if [[ ! -f /C/tools/msys64/msys2_shell.cmd ]]; then
               rm -rf /C/tools/msys64
          fi
        - choco uninstall -y mingw
        - choco upgrade --no-progress -y msys2
        - export msys2='cmd //C RefreshEnv.cmd '
        - export msys2+='& set MSYS=winsymlinks:nativestrict '
        - export msys2+='& C:\\tools\\msys64\\msys2_shell.cmd -defterm -no-start'
        - export shell="$msys2 -mingw32 -full-path -here -c \$\* --"
        - export msys2+=" -msys2 -c \$\* --"
        - $msys2 pacman --sync --noconfirm --needed \
                autoconf \
                automake \
                make \
                perl \ 
                python \
                mingw-w64-i686-libtool \	
                mingw-w64-i686-toolchain \
                mingw-w64-i686-gcc \
                mingw-w64-i686-cmake \	
                mingw-w64-i686-cmocka \	
                mingw-w64-i686-python3-setuptools \
                unzip
        - export CPPFLAGS=-D__USE_MINGW_ANSI_STDIO=1
        - export CC=i686-w64-mingw32-gcc
        - export AR=gcc-ar
        - export RANLIB=gcc-ranlib
        - export CFLAGS="-m32"
        - export LDFLAGS="-m32"
        - export LDFLAGS_STATIC="-m32"
        - export UNICORN_QEMU_FLAGS="--cpu=i386"
#      before_cache:
#        - $msys2 pacman --sync --clean --noconfirm
#      cache:
#        timeout:
#          1000
#        directories:
#          - $HOME/AppData/Local/Temp/chocolatey
#          - /C/tools/msys64
      script:
        - $shell make header; $shell make; cp unicorn.dll /C/Windows/SysWOW64/; $shell make test

    - name: "Windows MSYS2/MinGW64"
      os: windows
      language: shell
      env:
        - PATH=/C/tools/msys64/mingw64/bin:$PATH
      before_install:
        - | 
          if [[ ! -f /C/tools/msys64/msys2_shell.cmd ]]; then 
               rm -rf /C/tools/msys64
          fi
        - choco uninstall -y mingw
        - choco upgrade --no-progress -y msys2
        - export msys2='cmd //C RefreshEnv.cmd '
        - export msys2+='& set MSYS=winsymlinks:nativestrict '
        - export msys2+='& C:\\tools\\msys64\\msys2_shell.cmd -defterm -no-start'
        - export shell="$msys2 -mingw64 -full-path -here -c \$\* --"
        - export msys2+=" -msys2 -c \$\* --"
        - $msys2 pacman --sync --noconfirm --needed \
                autoconf \
                automake \
                make \
                perl \ 
                python \
                mingw-w64-x86_64-libtool \
                mingw-w64-x86_64-toolchain \
                mingw-w64-x86_64-cmake \
                mingw-w64-x86_64-cmocka \
                mingw-w64-x86_64-python3-setuptools
                unzip
        - export CPPFLAGS=-D__USE_MINGW_ANSI_STDIO=1
        - export CC=x86_64-w64-mingw32-gcc
        - export AR=gcc-ar
        - export RANLIB=gcc-ranlib
#      before_cache:
#        - $msys2 pacman --sync --clean --noconfirm
#      cache:
#        timeout:
#          1000
#        directories:
#          - $HOME/AppData/Local/Temp/chocolatey
#          - /C/tools/msys64
      script:
        - $shell make header; $shell make; cp unicorn.dll /C/Windows/System32/; $shell make test
addons:
  apt:
    packages:
      - libpthread-stubs0-dev
      - libcmocka-dev
  homebrew:
    update: true
    brewfile: true
