version: '{branch}.{build}'
branches:
  only:
  - master

image: Visual Studio 2017

environment:
  PHP_SDK_BINARY_TOOLS_VER: php-sdk-2.1.1

  matrix:
    - ARCH: x86
      PHP_VER: 7.2
      VC_VER: vc15
    - ARCH: x64
      PHP_VER: 7.2
      VC_VER: vc15
    - ARCH: x86
      PHP_VER: 7.3
      VC_VER: vc15
    - ARCH: x64
      PHP_VER: 7.3
      VC_VER: vc15
install:
- cmd: cinst wget
build_script:
- cmd: >-
    "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" %ARCH%

    wget https://github.com/OSTC/php-sdk-binary-tools/archive/%PHP_SDK_BINARY_TOOLS_VER%.zip --no-check-certificate -q -O php-sdk-binary-tools-%PHP_SDK_BINARY_TOOLS_VER%.zip

    7z x -y php-sdk-binary-tools-%PHP_SDK_BINARY_TOOLS_VER%.zip -oC:\projects

    move C:\projects\php-sdk-binary-tools-%PHP_SDK_BINARY_TOOLS_VER% C:\projects\php-sdk
    
    C:\projects\php-sdk\bin\phpsdk_setvars.bat

    git clone https://github.com/php/php-src C:\projects\php-src -b PHP-%PHP_VER% --depth=1

    mkdir C:\projects\php-src\ext\pthreads

    xcopy C:\projects\pthreads C:\projects\php-src\ext\pthreads /s /e /y /q

    phpsdk_deps -u -t %VC_VER% -b %PHP_VER% -a %ARCH% -f -d C:\projects\php-src\deps

    wget http://www.mirrorservice.org/sites/sources.redhat.com/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip -q

    7z x -y pthreads-w32-2-9-1-release.zip -oC:\projects\pthreads-w32

    copy C:\projects\pthreads-w32\Pre-built.2\include\pthread.h C:\projects\php-src\deps\include\pthread.h

    copy C:\projects\pthreads-w32\Pre-built.2\include\sched.h C:\projects\php-src\deps\include\sched.h

    copy C:\projects\pthreads-w32\Pre-built.2\include\semaphore.h C:\projects\php-src\deps\include\semaphore.h

    copy C:\projects\pthreads-w32\Pre-built.2\lib\%ARCH%\pthreadVC2.lib C:\projects\php-src\deps\lib\pthreadVC2.lib

    cd C:\projects\php-src

    buildconf.bat

    configure.bat --disable-all --enable-cli --enable-zts --with-pthreads=shared --with-prefix=C:\projects\pthreads\bin --with-php-build=deps --enable-ipv6

    nmake

    nmake install

    cd C:\projects\pthreads\bin

    copy C:\projects\pthreads-w32\Pre-built.2\dll\%ARCH%\pthreadVC2.dll C:\projects\pthreads\bin\pthreadVC2.dll

    echo [PHP] > php.ini

    echo extension_dir = "ext" >> php.ini

    echo extension=php_pthreads.dll >> php.ini

    set TEST_PHP_EXECUTABLE=%cd%\php.exe

    php -v

    php -m
test_script:
- cmd: >-
    set REPORT_EXIT_STATUS=1

    php.exe /projects/php-src/run-tests.php /projects/php-src/ext/pthreads -q --show-diff --offline
artifacts:
  - path: bin
    name: master
    type: zip
