version: '{build}-{branch}'

os: 'Visual Studio 2015'

environment:
  matrix:
    - ARCH: x64
      MSYS2_ARCH: x86_64
      MSYS2_DIR: msys64
      MSYSTEM: MINGW64
      GOPATH: c:\gopath
      GOROOT: c:\go
      GOARCH: amd64
      EXTLD: x86_64-w64-mingw32-gcc
    - ARCH: x86
      MSYS2_ARCH: i686
      MSYS2_DIR: msys64
      MSYSTEM: MINGW32
      GOPATH: c:\gopath
      GOROOT: c:\go
      GOARCH: 386
      EXTLD: i686-w64-mingw32-gcc

clone_folder: C:\gopath\src\github.com\square\ghostunnel

before_build:
  # Go paths
  - set PATH=%GOROOT%\bin;C:\%GOPATH%\bin;%PATH%
  # MSYS paths
  - set PATH=C:\%MSYS2_DIR%\%MSYSTEM%\bin;C:\%MSYS2_DIR%\usr\bin;%PATH%
  # Install build deps
  - bash -lc "for n in `seq 1 3`; do pacman --noconfirm -S mingw-w64-%MSYS2_ARCH%-libtool && break || sleep 15; done"

build_script:
  - git describe > version
  - set /p GIT_VERSION= < version
  # Build without PKCS11 enabled
  - set CGO_ENABLED=0
  - go build -o ghostunnel-%GIT_VERSION%-windows-%GOARCH%-without-pkcs11.exe -i .
  - sha256sum ghostunnel-%GIT_VERSION%-windows-%GOARCH%-without-pkcs11.exe > ghostunnel-%GIT_VERSION%-windows-%GOARCH%-without-pkcs11.exe.sha256sum
  # Build with PKCS11 enabled
  - set CGO_ENABLED=1
  - go build -o ghostunnel-%GIT_VERSION%-windows-%GOARCH%-with-pkcs11.exe -ldflags "-w -extldflags \"-static\" -extld=%EXTLD%" -i .
  # Execute tests
  - go test -v ./...
