version: 1.0.{build}

# Test matrix: MinGW compilers only (Visual Studio testing moved to GitHub Actions)
environment:
  matrix:
    - COMPILER: gcc
      PLATFORM: mingw32
    - COMPILER: gcc
      PLATFORM: mingw64
    - COMPILER: clang
      PLATFORM: mingw64

install:
  - echo Installing %COMPILER% %PLATFORM%
  - mkdir bin
  # Setup MinGW environment
  - set "PATH_MINGW32=c:\MinGW\bin;c:\MinGW\usr\bin"
  - set "PATH_MINGW64=c:\msys64\mingw64\bin;c:\msys64\usr\bin"
  - copy C:\MinGW\bin\mingw32-make.exe C:\MinGW\bin\make.exe >nul 2>&1
  - copy C:\MinGW\bin\gcc.exe C:\MinGW\bin\cc.exe >nul 2>&1

build_script:
  - echo "*** Building %COMPILER% %PLATFORM% ***"
  # Configure PATH for MinGW builds
  - if [%PLATFORM%]==[mingw32] set PATH=%PATH_MINGW32%;%PATH%
  - if [%PLATFORM%]==[mingw64] set PATH=%PATH_MINGW64%;%PATH%

  # GCC Build
  - if [%COMPILER%]==[gcc] (
      echo "GCC build started" &&
      gcc -v &&
      make -v &&
      make -j -C programs lz4 V=1 &&
      make -j -C tests fullbench V=1 &&
      make -j -C tests fuzzer V=1 &&
      make -j -C lib lib V=1 LDFLAGS="-static-libgcc" &&
      echo "Packaging GCC build..." &&
      mkdir bin\dll bin\static bin\example bin\include &&
      copy tests\fullbench.c bin\example\ &&
      copy lib\xxhash.* bin\example\ &&
      copy lib\lz4*.h bin\include\ &&
      copy lib\liblz4.a bin\static\liblz4_static.lib &&
      copy lib\liblz4.dll.a bin\dll\ >nul 2>&1 &&
      (copy lib\liblz4.dll bin\dll\ 2>nul || copy lib\msys-lz4-1.dll bin\dll\liblz4.dll 2>nul || copy lib\cyglz4-1.dll bin\dll\liblz4.dll 2>nul || echo DLL copy warning) &&
      copy lib\dll\example\* bin\example\ >nul 2>&1 &&
      copy programs\lz4.exe bin\lz4.exe &&
      copy tests\*.exe programs\
    )

  # Clang Build
  - if [%COMPILER%]==[clang] (
      echo "Clang build started" &&
      clang -v &&
      make -v &&
      set "CFLAGS=--target=x86_64-w64-mingw32 -Werror -Wconversion -Wno-sign-conversion" &&
      make -j -C programs lz4 CC=clang V=1 &&
      make -j -C tests fullbench CC=clang V=1 &&
      make -j -C tests fuzzer CC=clang V=1 &&
      make -j -C lib lib CC=clang V=1 &&
      copy tests\*.exe programs\
    )

  # Create release archives (GCC only)
  - if [%COMPILER%]==[gcc] if [%PLATFORM%]==[mingw64] 7z.exe a -bb1 bin\lz4_x64.zip NEWS .\bin\lz4.exe README.md .\bin\example .\bin\dll .\bin\static .\bin\include
  - if [%COMPILER%]==[gcc] if [%PLATFORM%]==[mingw64] appveyor PushArtifact bin\lz4_x64.zip
  - if [%COMPILER%]==[gcc] if [%PLATFORM%]==[mingw32] 7z.exe a -bb1 bin\lz4_x86.zip NEWS .\bin\lz4.exe README.md .\bin\example .\bin\dll .\bin\static .\bin\include
  - if [%COMPILER%]==[gcc] if [%PLATFORM%]==[mingw32] appveyor PushArtifact bin\lz4_x86.zip

test_script:
  - echo "*** Testing %COMPILER% %PLATFORM% ***"
  - cd programs
  - lz4 -h
  - lz4 -i1b lz4.exe
  - lz4 -i1b5 lz4.exe
  - lz4 -i1b10 lz4.exe
  - lz4 -i1b15 lz4.exe
  - echo "------- lz4 tested -------"
  - fullbench.exe -i0 fullbench.exe
  - echo "Launching fuzzer test..."
  - fuzzer.exe -v -T20s
  - cd ..

artifacts:
  - path: bin\lz4_x64.zip
    name: LZ4 Windows x64 Build
  - path: bin\lz4_x86.zip
    name: LZ4 Windows x86 Build
