# Copyright (C) Viktor Szakats
#
# SPDX-License-Identifier: curl

name: windows

on:
  push:
    branches:
      - master
      - '*/ci'
    paths-ignore:
      - '**/*.md'
      - '.azure-pipelines.yml'
      - '.circleci/**'
      - 'appveyor.*'
      - 'packages/**'
      - 'plan9/**'
      - 'projects/**'
      - 'winbuild/**'
  pull_request:
    branches:
      - master
    paths-ignore:
      - '**/*.md'
      - '.azure-pipelines.yml'
      - '.circleci/**'
      - 'appveyor.*'
      - 'packages/**'
      - 'plan9/**'
      - 'projects/**'
      - 'winbuild/**'

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
  cancel-in-progress: true

permissions: {}

jobs:
  cygwin:
    name: "cygwin, ${{ matrix.build == 'cmake' && 'CM' || 'AM' }} ${{ matrix.platform }} ${{ matrix.name }}"
    runs-on: windows-latest
    timeout-minutes: 45
    defaults:
      run:
        shell: C:\cygwin\bin\bash.exe '{0}'
    env:
      SHELLOPTS: 'igncr'
    strategy:
      matrix:
        include:
          - { build: 'automake', platform: 'x86_64', tflags: ''       , config: '--enable-debug --disable-threaded-resolver', name: 'openssl' }
          - { build: 'cmake'   , platform: 'x86_64', tflags: 'skipall', config: '-DCURL_USE_OPENSSL=ON', name: 'openssl R' }
      fail-fast: false
    steps:
      - run: git config --global core.autocrlf input
        shell: pwsh
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
      - uses: cygwin/cygwin-install-action@006ad0b0946ca6d0a3ea2d4437677fa767392401 # v4
        with:
          platform: ${{ matrix.platform }}
          # https://cygwin.com/cgi-bin2/package-grep.cgi
          packages: autoconf libtool ${{ matrix.build }} gcc-core gcc-g++ binutils make libssl-devel zlib-devel libbrotli-devel libnghttp2-devel libpsl-devel libssh2-devel
          site: https://mirrors.kernel.org/sourceware/cygwin/

      - name: 'autotools autoreconf'
        if: ${{ matrix.build == 'automake' }}
        timeout-minutes: 2
        run: autoreconf -fi

      - name: 'autotools configure'
        if: ${{ matrix.build == 'automake' }}
        timeout-minutes: 5
        run: |
          PATH="/usr/bin:$(cygpath "${SYSTEMROOT}")/System32"
          mkdir bld && cd bld && ../configure --enable-warnings --enable-werror \
            --prefix="${HOME}"/install \
            --enable-websockets \
            --with-openssl \
            --with-libssh2 \
            --disable-dependency-tracking \
            ${{ matrix.config }}

      - name: 'autotools configure log'
        if: ${{ matrix.build == 'automake' && !cancelled() }}
        run: cat bld/config.log 2>/dev/null || true

      - name: 'curl_config.h'
        if: ${{ matrix.build == 'automake' }}
        run: cat bld/lib/curl_config.h | grep -F '#define' | sort || true

      - name: 'curl_config.h (full)'
        if: ${{ matrix.build == 'automake' }}
        run: cat bld/lib/curl_config.h || true

      - name: 'autotools build'
        if: ${{ matrix.build == 'automake' }}
        timeout-minutes: 10
        run: make -C bld -j5 V=1 install

      - name: 'curl version'
        if: ${{ matrix.build == 'automake' }}
        timeout-minutes: 1
        run: |
          find . -name '*.exe' -o -name '*.dll'
          bld/src/curl.exe --disable --version

      - name: 'autotools build examples'
        if: ${{ matrix.build == 'automake' }}
        timeout-minutes: 5
        run: make -C bld -j5 V=1 examples

      - name: 'autotools build tests'
        if: ${{ matrix.build == 'automake' && matrix.tflags != 'skipall' }}
        timeout-minutes: 15
        run: make -C bld -j5 V=1 -C tests

      - name: 'autotools run tests'
        if: ${{ matrix.build == 'automake' && matrix.tflags != 'skipall' && matrix.tflags != 'skiprun' }}
        timeout-minutes: 40
        run: |
          export TFLAGS='-j8 ${{ matrix.tflags }}'
          if [ -x "$(cygpath "${SYSTEMROOT}/System32/curl.exe")" ]; then
            TFLAGS+=" -ac $(cygpath "${SYSTEMROOT}/System32/curl.exe")"
          fi
          make -C bld -j5 V=1 test-ci

      - name: 'cmake configure'
        if: ${{ matrix.build == 'cmake' }}
        timeout-minutes: 5
        run: |
          PATH="/usr/bin:$(cygpath "${SYSTEMROOT}")/System32"
          cmake -B bld ${options} \
            -DCMAKE_UNITY_BUILD=ON \
            -DCURL_WERROR=ON \
            -DBUILD_EXAMPLES=ON \
            -DENABLE_WEBSOCKETS=ON \
            -DCURL_BROTLI=ON -DUSE_NGHTTP2=ON \
            ${{ matrix.config }}

      - name: 'cmake configure log'
        if: ${{ matrix.build == 'cmake' && !cancelled() }}
        run: cat bld/CMakeFiles/CMake*.yaml 2>/dev/null || true

      - name: 'curl_config.h'
        if: ${{ matrix.build == 'cmake' }}
        run: cat bld/lib/curl_config.h | grep -F '#define' | sort || true

      - name: 'curl_config.h (full)'
        if: ${{ matrix.build == 'cmake' }}
        run: cat bld/lib/curl_config.h || true

      - name: 'cmake build'
        if: ${{ matrix.build == 'cmake' }}
        timeout-minutes: 10
        run: cmake --build bld --config '${{ matrix.type }}' --parallel 5

      - name: 'curl version'
        if: ${{ matrix.build == 'cmake' }}
        timeout-minutes: 1
        run: |
          find . -name '*.exe' -o -name '*.dll' | grep -v '/examples/'
          PATH="$PWD/bld/lib:$PATH"
          bld/src/curl.exe --disable --version

      - name: 'cmake build tests'
        if: ${{ matrix.build == 'cmake' && matrix.tflags != 'skipall' }}
        timeout-minutes: 15
        run: cmake --build bld --config '${{ matrix.type }}' --parallel 5 --target testdeps

      - name: 'cmake run tests'
        if: ${{ matrix.build == 'cmake' && matrix.tflags != 'skipall' && matrix.tflags != 'skiprun' }}
        timeout-minutes: 40
        run: |
          export TFLAGS='-j8 ${{ matrix.tflags }}'
          if [ -x "$(cygpath "${SYSTEMROOT}/System32/curl.exe")" ]; then
            TFLAGS+=" -ac $(cygpath "${SYSTEMROOT}/System32/curl.exe")"
          fi
          PATH="$PWD/bld/lib:$PATH"
          cmake --build bld --config '${{ matrix.type }}' --target test-ci

  msys2:  # both msys and mingw-w64
    name: "${{ matrix.sys == 'msys' && 'msys2' || 'mingw' }}, ${{ matrix.build == 'cmake' && 'CM' || 'AM' }} ${{ matrix.env }} ${{ matrix.name }} ${{ matrix.test }}"
    runs-on: windows-latest
    timeout-minutes: 45
    defaults:
      run:
        shell: msys2 {0}
    strategy:
      matrix:
        include:
          - { build: 'autotools', sys: 'msys'   , env: 'x86_64'      , tflags: '!19                !1233', config: '--enable-debug --disable-threaded-resolver --disable-proxy', name: '!proxy' }
          - { build: 'autotools', sys: 'msys'   , env: 'x86_64'      , tflags: '!19 !504 !704 !705 !1233', config: '--enable-debug --disable-threaded-resolver', name: 'default' }
          - { build: 'cmake'    , sys: 'msys'   , env: 'x86_64'      , tflags: 'skipall'                 , config: '-DENABLE_DEBUG=ON -DENABLE_THREADED_RESOLVER=OFF', name: 'default' }
          - { build: 'autotools', sys: 'msys'   , env: 'x86_64'      , tflags: '!19 !504 !704 !705 !1233', config: '', name: 'default R' }
          - { build: 'autotools', sys: 'mingw64', env: 'x86_64'      , tflags: 'skiprun'                 , config: '--enable-debug --disable-threaded-resolver --disable-curldebug --enable-static=no', name: 'default' }
          # FIXME: WebSockets test results ignored due to frequent failures on native Windows:
          - { build: 'cmake'    , sys: 'mingw64', env: 'x86_64'      , tflags: '~2301 ~2302'             , config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON', type: 'Debug', name: 'schannel U' }
          - { build: 'cmake'    , sys: 'ucrt64' , env: 'ucrt-x86_64' , tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DENABLE_CURLDEBUG=ON', type: 'Release', name: 'schannel R TrackMemory' }
          - { build: 'cmake'    , sys: 'clang64', env: 'clang-x86_64', tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_OPENSSL=ON -DENABLE_UNICODE=OFF', type: 'Release', name: 'openssl' }
          - { build: 'cmake'    , sys: 'mingw64', env: 'x86_64'      , tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DBUILD_EXAMPLES=OFF', type: 'Release', test: 'uwp', name: 'schannel R' }
      fail-fast: false
    steps:
      - run: git config --global core.autocrlf input
        shell: pwsh
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
      - uses: msys2/setup-msys2@5df0ca6cbf14efcd08f8d5bd5e049a3cc8e07fd2 # v2
        if: ${{ matrix.sys == 'msys' }}
        with:
          msystem: ${{ matrix.sys }}
          # https://packages.msys2.org/search
          install: gcc ${{ matrix.build }} make openssl-devel zlib-devel brotli-devel libnghttp2-devel libpsl-devel libssh2-devel
      - uses: msys2/setup-msys2@5df0ca6cbf14efcd08f8d5bd5e049a3cc8e07fd2 # v2
        if: ${{ matrix.sys != 'msys' }}
        with:
          msystem: ${{ matrix.sys }}
          install: >-
            mingw-w64-${{ matrix.env }}-cc
            mingw-w64-${{ matrix.env }}-${{ matrix.build }} make
            mingw-w64-${{ matrix.env }}-openssl
            mingw-w64-${{ matrix.env }}-libssh2

      - name: 'autotools autoreconf'
        if: ${{ matrix.build == 'autotools' }}
        timeout-minutes: 2
        run: autoreconf -fi

      - name: 'autotools configure'
        if: ${{ matrix.build == 'autotools' }}
        timeout-minutes: 5
        run: |
          mkdir bld && cd bld && ../configure --enable-warnings --enable-werror \
            --prefix="${HOME}"/install \
            --enable-websockets \
            --with-openssl \
            --with-libssh2 \
            --disable-dependency-tracking \
            ${{ matrix.config }}

      - name: 'autotools configure log'
        if: ${{ matrix.build == 'autotools' && !cancelled() }}
        run: cat bld/config.log 2>/dev/null || true

      - name: 'curl_config.h'
        if: ${{ matrix.build == 'autotools' }}
        run: cat bld/lib/curl_config.h | grep -F '#define' | sort || true

      - name: 'curl_config.h (full)'
        if: ${{ matrix.build == 'autotools' }}
        run: cat bld/lib/curl_config.h || true

      - name: 'autotools build'
        if: ${{ matrix.build == 'autotools' }}
        timeout-minutes: 10
        run: make -C bld -j5 V=1 install

      - name: 'curl version'
        if: ${{ matrix.build == 'autotools' }}
        timeout-minutes: 11
        run: |
          find . -name '*.exe' -o -name '*.dll'
          bld/src/curl.exe --disable --version

      - name: 'autotools build examples'
        if: ${{ matrix.build == 'autotools' }}
        timeout-minutes: 5
        run: make -C bld -j5 V=1 examples

      - name: 'autotools build tests'
        if: ${{ matrix.build == 'autotools' && matrix.tflags != 'skipall' }}
        timeout-minutes: 10
        run: make -C bld -j5 V=1 -C tests

      - name: 'autotools run tests'
        if: ${{ matrix.build == 'autotools' && matrix.tflags != 'skipall' && matrix.tflags != 'skiprun' }}
        timeout-minutes: 30
        run: |
          export TFLAGS='-j14 ${{ matrix.tflags }}'
          if [ '${{ matrix.sys }}' != 'msys' ]; then
            TFLAGS+=' !TFTP !MQTT !WebSockets !SMTP ~FTP'
          fi
          if [ -x "$(cygpath "${SYSTEMROOT}/System32/curl.exe")" ]; then
            TFLAGS+=" -ac $(cygpath "${SYSTEMROOT}/System32/curl.exe")"
          fi
          make -C bld -j5 V=1 test-ci

      - name: 'cmake configure'
        if: ${{ matrix.build == 'cmake' }}
        timeout-minutes: 5
        run: |
          if [[ '${{ matrix.env }}' = 'clang'* ]]; then
            options='-DCMAKE_C_COMPILER=clang'
          else
            options='-DCMAKE_C_COMPILER=gcc'
          fi
          if [ '${{ matrix.test }}' = 'uwp' ]; then
            options+=' -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0'
            pacman --noconfirm --ask 20 --noprogressbar --sync --needed 'mingw-w64-${{ matrix.env }}-winstorecompat-git'
            specs="$(realpath gcc-specs-uwp)"
            gcc -dumpspecs | sed -e 's/-lmingwex/-lwindowsapp -lmingwex -lwindowsapp -lwindowsappcompat/' -e 's/-lmsvcrt/-lmsvcr120_app/' > "${specs}"
            cflags="-specs=$(cygpath -w "${specs}") -DWINSTORECOMPAT -DWINAPI_FAMILY=WINAPI_FAMILY_APP"
            # CMake (as of v3.26.4) gets confused and applies the MSVC rc.exe command-line
            # template to windres. Reset it to the windres template manually:
            rcopts='<CMAKE_RC_COMPILER> -O coff <DEFINES> <INCLUDES> <FLAGS> <SOURCE> <OBJECT>'
          else
            rcopts=''
          fi
          [ '${{ matrix.type }}' = 'Debug' ] && options+=' -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG='
          [ '${{ matrix.type }}' = 'Release' ] && options+=' -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE='
          cmake -B bld ${options} \
            "-DCMAKE_C_FLAGS=${cflags}" \
            "-DCMAKE_RC_COMPILE_OBJECT=${rcopts}" \
            '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \
            -DCMAKE_UNITY_BUILD=ON \
            -DCURL_WERROR=ON \
            -DBUILD_EXAMPLES=ON \
            -DENABLE_WEBSOCKETS=ON \
            -DCURL_BROTLI=ON -DUSE_NGHTTP2=ON \
            ${{ matrix.config }}

      - name: 'cmake configure log'
        if: ${{ matrix.build == 'cmake' && !cancelled() }}
        run: cat bld/CMakeFiles/CMake*.yaml 2>/dev/null || true

      - name: 'curl_config.h'
        if: ${{ matrix.build == 'cmake' }}
        run: cat bld/lib/curl_config.h | grep -F '#define' | sort || true

      - name: 'curl_config.h (full)'
        if: ${{ matrix.build == 'cmake' }}
        run: cat bld/lib/curl_config.h || true

      - name: 'cmake build'
        if: ${{ matrix.build == 'cmake' }}
        timeout-minutes: 10
        run: cmake --build bld --config '${{ matrix.type }}' --parallel 5

      - name: 'curl version'
        if: ${{ matrix.build == 'cmake' }}
        timeout-minutes: 1
        run: |
          find . -name '*.exe' -o -name '*.dll' | grep -v '/examples/'
          if [ '${{ matrix.test }}' != 'uwp' ]; then  # UWP missing 'msvcr120_app.dll', fails with exit code 0xc0000135
            PATH="$PWD/bld/lib:$PATH"
            bld/src/curl.exe --disable --version
          fi

      - name: 'cmake build tests'
        if: ${{ matrix.build == 'cmake' && matrix.tflags != 'skipall' }}
        timeout-minutes: 10
        run: cmake --build bld --config '${{ matrix.type }}' --parallel 5 --target testdeps

      - name: 'cmake run tests'
        if: ${{ matrix.build == 'cmake' && matrix.tflags != 'skipall' && matrix.tflags != 'skiprun' }}
        timeout-minutes: 40
        run: |
          export TFLAGS='-j14 ${{ matrix.tflags }}'
          if [ '${{ matrix.sys }}' != 'msys' ]; then
            TFLAGS+=' !TFTP !MQTT !WebSockets !SMTP ~FTP'
          fi
          if [ -x "$(cygpath "${SYSTEMROOT}/System32/curl.exe")" ]; then
            TFLAGS+=" -ac $(cygpath "${SYSTEMROOT}/System32/curl.exe")"
          fi
          PATH="$PWD/bld/lib:$PATH"
          cmake --build bld --config '${{ matrix.type }}' --target test-ci

  old-mingw-w64:
    name: 'old-mingw, CM ${{ matrix.env }} ${{ matrix.name }}'
    runs-on: windows-latest
    timeout-minutes: 45
    defaults:
      run:
        shell: C:\msys64\usr\bin\bash.exe {0}
    strategy:
      matrix:
        include:
          - name: 'schannel'
            env: '9.5.0-x86_64'
            dir: 'mingw64'
            url: 'https://github.com/brechtsanders/winlibs_mingw/releases/download/9.5.0-10.0.0-msvcrt-r1/winlibs-x86_64-posix-seh-gcc-9.5.0-mingw-w64msvcrt-10.0.0-r1.7z'
            config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=OFF'
            type: 'Release'
            tflags: '~2301 ~2302 ~3027'
          - name: 'schannel U'
            env: '7.3.0-x86_64'
            dir: 'mingw64'
            url: 'https://downloads.sourceforge.net/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/7.3.0/threads-win32/seh/x86_64-7.3.0-release-win32-seh-rt_v5-rev0.7z'
            config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON'
            type: 'Release'
            tflags: '~2301 ~2302 ~3027'
          - name: 'schannel !unity'
            env: '6.4.0-i686'
            dir: 'mingw32'
            url: 'https://downloads.sourceforge.net/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/6.4.0/threads-win32/dwarf/i686-6.4.0-release-win32-dwarf-rt_v5-rev0.7z'
            config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=OFF -DCMAKE_UNITY_BUILD=OFF'
            type: 'Debug'
            tflags: 'skiprun'
      fail-fast: false
    steps:
      - name: 'cache compiler (gcc ${{ matrix.env }})'
        uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
        id: cache-compiler
        with:
          path: ~\my-cache
          key: ${{ runner.os }}-mingw-w64-${{ matrix.env }}

      - name: 'install compiler (gcc ${{ matrix.env }})'
        if: ${{ steps.cache-compiler.outputs.cache-hit != 'true' }}
        timeout-minutes: 5
        run: |
          cd "${USERPROFILE}" || exit 1
          mkdir my-cache
          cd my-cache || exit 1
          curl --fail --silent --show-error --retry 3 --retry-connrefused --output pack.bin --location --proto-redir =https '${{ matrix.url }}'
          pwd
          7z x -y pack.bin >/dev/null
          rm -r -f pack.bin
          ls -l

      - run: git config --global core.autocrlf input
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

      - name: 'cmake configure'
        timeout-minutes: 5
        run: |
          PATH="$(cygpath "${USERPROFILE}")/my-cache/${{ matrix.dir }}/bin:/c/msys64/usr/bin:$PATH"
          [ '${{ matrix.type }}' = 'Debug' ] && options+=' -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG='
          [ '${{ matrix.type }}' = 'Release' ] && options+=' -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE='
          cmake -B bld ${options} \
            '-GMSYS Makefiles' \
            -DCMAKE_C_COMPILER=gcc \
            '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \
            -DCMAKE_UNITY_BUILD=ON \
            -DCURL_WERROR=ON \
            -DBUILD_EXAMPLES=ON \
            -DENABLE_WEBSOCKETS=ON \
            ${{ matrix.config }}

      - name: 'cmake configure log'
        if: ${{ !cancelled() }}
        run: cat bld/CMakeFiles/CMake*.yaml 2>/dev/null || true

      - name: 'curl_config.h'
        run: cat bld/lib/curl_config.h | grep -F '#define' | sort || true

      - name: 'curl_config.h (full)'
        run: cat bld/lib/curl_config.h || true

      - name: 'cmake build'
        timeout-minutes: 10
        run: |
          PATH="$(cygpath "${USERPROFILE}")/my-cache/${{ matrix.dir }}/bin:/c/msys64/usr/bin:$PATH"
          cmake --build bld --config '${{ matrix.type }}' --parallel 5

      - name: 'curl version'
        timeout-minutes: 1
        run: |
          find . -name '*.exe' -o -name '*.dll' | grep -v '/examples/'
          PATH="$PWD/bld/lib:$PATH"
          bld/src/curl.exe --disable --version

      - name: 'cmake build tests'
        if: ${{ matrix.tflags != 'skipall' }}
        timeout-minutes: 10
        run: |
          PATH="$(cygpath "${USERPROFILE}")/my-cache/${{ matrix.dir }}/bin:/c/msys64/usr/bin:$PATH"
          cmake --build bld --config '${{ matrix.type }}' --parallel 5 --target testdeps

      - name: 'cmake run tests'
        if: ${{ matrix.tflags != 'skipall' && matrix.tflags != 'skiprun' }}
        timeout-minutes: 40
        run: |
          PATH="$(cygpath "${USERPROFILE}")/my-cache/${{ matrix.dir }}/bin:/c/msys64/usr/bin:$PATH"
          export TFLAGS='-j14 !TFTP !MQTT !WebSockets ~FTP ${{ matrix.tflags }}'
          if [ -x "$(cygpath "${SYSTEMROOT}/System32/curl.exe")" ]; then
            TFLAGS+=" -ac $(cygpath "${SYSTEMROOT}/System32/curl.exe")"
          fi
          PATH="$PWD/bld/lib:$PATH"
          cmake --build bld --config '${{ matrix.type }}' --target test-ci

  msvc:
    name: 'msvc, CM ${{ matrix.arch }}-${{ matrix.plat }} ${{ matrix.name }}'
    runs-on: windows-latest
    timeout-minutes: 55
    defaults:
      run:
        shell: bash
    env:
      VCPKG_BINARY_SOURCES: 'clear;x-gha,readwrite'
      VCPKG_DISABLE_METRICS: '1'
    strategy:
      matrix:
        include:
        - name: 'schannel U'
          install: 'brotli zlib zstd libpsl nghttp2 libssh2[core,zlib] pkgconf gsasl'
          arch: 'x64'
          plat: 'windows'
          type: 'Debug'
          tflags: '~1516 ~2301 ~2302 ~2303 ~2307'
          config: '-DENABLE_DEBUG=ON -DENABLE_UNICODE=ON  -DCURL_USE_SCHANNEL=ON  -DCURL_BROTLI=ON -DCURL_ZSTD=ON -DCURL_USE_LIBPSL=ON -DUSE_NGHTTP2=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBSSH2=ON -DUSE_WIN32_IDN=ON -DCURL_USE_GSASL=ON'
        - name: 'openssl'
          install: 'brotli zlib zstd libpsl nghttp2 nghttp3 openssl libssh2 pkgconf gsasl'
          arch: 'x64'
          plat: 'windows'
          type: 'Debug'
          tflags: '~1516 ~2301 ~2302 ~2303 ~2307'
          config: '-DENABLE_DEBUG=ON -DENABLE_UNICODE=OFF -DCURL_USE_SCHANNEL=OFF -DCURL_BROTLI=ON -DCURL_ZSTD=ON -DCURL_USE_LIBPSL=ON -DUSE_NGHTTP2=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBSSH2=ON -DCURL_USE_OPENSSL=ON -DUSE_OPENSSL_QUIC=ON -DCURL_USE_GSASL=ON'
        - name: 'openssl'
          install: 'brotli zlib zstd        nghttp2 nghttp3 openssl libssh2'
          arch: 'x64'
          plat: 'uwp'
          type: 'Debug'
          tflags: 'skipall'
          config: '-DENABLE_DEBUG=ON -DENABLE_UNICODE=OFF -DCURL_USE_SCHANNEL=OFF -DCURL_BROTLI=ON -DCURL_ZSTD=ON                      -DUSE_NGHTTP2=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBSSH2=ON -DCURL_USE_OPENSSL=ON -DUSE_OPENSSL_QUIC=ON'
        - name: 'libressl'
          install: 'brotli zlib zstd libpsl nghttp2 libressl libssh2[core,zlib]'
          arch: 'x64'
          plat: 'windows'
          type: 'Debug'
          tflags: '~1516 ~2301 ~2302 ~2303 ~2307'
          config: '-DENABLE_DEBUG=ON -DENABLE_UNICODE=OFF -DCURL_USE_SCHANNEL=OFF -DCURL_BROTLI=ON -DCURL_ZSTD=ON -DCURL_USE_LIBPSL=ON -DUSE_NGHTTP2=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBSSH2=ON -DCURL_USE_OPENSSL=ON'
        - name: 'boringssl-ECH'
          install: 'brotli zlib zstd libpsl nghttp2 boringssl libssh2[core,zlib]'
          arch: 'x64'
          plat: 'windows'
          type: 'Debug'
          tflags: '~1516 ~2301 ~2302 ~2303 ~2307'
          config: '-DENABLE_DEBUG=ON -DENABLE_UNICODE=OFF -DCURL_USE_SCHANNEL=OFF -DCURL_BROTLI=ON -DCURL_ZSTD=ON -DCURL_USE_LIBPSL=ON -DUSE_NGHTTP2=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBSSH2=ON -DCURL_USE_OPENSSL=ON -DUSE_HTTPSRR=ON -DUSE_ECH=ON'
        - name: '!ssl'
          install: 'brotli zlib zstd libpsl pkgconf libidn2 libssh'
          arch: 'x64'
          plat: 'windows'
          type: 'Debug'
          tflags: '~1516 ~2301 ~2302 ~2303 ~2307'
          # WARNING: libssh uses hard-coded world-writable paths (/etc/..., ~/.ssh/) to
          #          read its configuration from, making it vulnerable to attacks on
          #          Windows. Do not use this component till there is a fix for these.
          # https://github.com/curl/curl-for-win/blob/3951808deb04df9489ee17430f236ed54436f81a/libssh.sh#L6-L8
          config: '-DENABLE_DEBUG=ON -DENABLE_UNICODE=OFF -DCURL_USE_SCHANNEL=OFF -DCURL_BROTLI=ON -DCURL_ZSTD=ON -DCURL_USE_LIBPSL=ON -DHTTP_ONLY=ON -DUSE_LIBIDN2=ON -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=ON'
        - name: 'wolfssl'
          install: 'brotli zlib zstd libpsl nghttp2 wolfssl libssh2 pkgconf gsasl'
          arch: 'x64'
          plat: 'windows'
          type: 'Debug'
          tflags: '~1516'
          config: '-DENABLE_DEBUG=ON -DENABLE_UNICODE=OFF -DCURL_USE_SCHANNEL=OFF -DCURL_BROTLI=ON -DCURL_ZSTD=ON -DCURL_USE_LIBPSL=ON -DUSE_NGHTTP2=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBSSH2=ON -DCURL_USE_WOLFSSL=ON -DCURL_USE_GSASL=ON'
      fail-fast: false
    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

      - name: 'vcpkg cache setup'
        uses: actions/github-script@v7
        with:
          script: |
            core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
            core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

      - name: 'vcpkg versions'
        timeout-minutes: 1
        run: |
          git -C "$VCPKG_INSTALLATION_ROOT" show --no-patch --format='%H %ai'
          vcpkg version

      - name: 'vcpkg build'
        timeout-minutes: 35
        run: vcpkg x-set-installed ${{ matrix.install }} '--triplet=${{ matrix.arch }}-${{ matrix.plat }}'

      - name: 'cmake configure'
        timeout-minutes: 5
        run: |
          if [[ '${{ matrix.install }}' = *'libressl'* ]]; then
            # without this, CMake gets confused about the non-vcpkg OpenSSL
            # installed on the runner and fails when linking.
            options+=" -DOPENSSL_ROOT_DIR=$VCPKG_INSTALLATION_ROOT/installed/${{ matrix.arch }}-${{ matrix.plat }}"
          fi
          cmake -B bld ${options} \
            "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" \
            "-DVCPKG_INSTALLED_DIR=$VCPKG_INSTALLATION_ROOT/installed" \
            '-DVCPKG_TARGET_TRIPLET=${{ matrix.arch }}-${{ matrix.plat }}' \
            -DCMAKE_VS_GLOBALS=TrackFileAccess=false \
            '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \
            -DCMAKE_UNITY_BUILD=ON \
            -DCURL_WERROR=ON \
            -DBUILD_EXAMPLES=ON \
            -DENABLE_WEBSOCKETS=ON \
            -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \
            -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE= \
            ${{ matrix.config }}

      - name: 'cmake configure log'
        if: ${{ !cancelled() }}
        run: cat bld/CMakeFiles/CMake*.yaml 2>/dev/null || true

      - name: 'curl_config.h'
        run: cat bld/lib/curl_config.h | grep -F '#define' | sort || true

      - name: 'curl_config.h (full)'
        run: cat bld/lib/curl_config.h || true

      - name: 'cmake build'
        timeout-minutes: 5
        run: cmake --build bld --config '${{ matrix.type }}' --parallel 5

      - name: 'curl version'
        timeout-minutes: 5
        run: |
          find . -name '*.exe' -o -name '*.dll' | grep -v '/examples/'
          if [ '${{ matrix.plat }}' != 'uwp' ]; then
            PATH="$PWD/bld/lib:$VCPKG_INSTALLATION_ROOT/installed/${{ matrix.arch }}-${{ matrix.plat }}/bin:$PATH"
            bld/src/curl.exe --disable --version
          fi

      - name: 'cmake build tests'
        if: ${{ matrix.tflags != 'skipall' }}
        timeout-minutes: 10
        run: cmake --build bld --config '${{ matrix.type }}' --parallel 5 --target testdeps

      - name: 'cmake run tests'
        if: ${{ matrix.tflags != 'skipall' && matrix.tflags != 'skiprun' }}
        timeout-minutes: 30
        run: |
          export TFLAGS='-j14 !TFTP !MQTT !WebSockets !SMTP ~FTP ${{ matrix.tflags }}'
          if [[ '${{ matrix.config }}' = *'-DUSE_WIN32_IDN=ON'* ]]; then
            TFLAGS+=' ~165'
            if [[ '${{ matrix.config }}' != *'-DENABLE_UNICODE=ON'* ]]; then
              TFLAGS+=' ~1448 ~2046 ~2047'
            fi
          elif [[ '${{ matrix.config }}' = *'-DUSE_LIBIDN2=ON'* ]]; then
            TFLAGS+=' ~165 ~1448 ~2046 ~2047'
          fi
          PATH="$PWD/bld/lib:$VCPKG_INSTALLATION_ROOT/installed/${{ matrix.arch }}-${{ matrix.plat }}/bin:$PATH"
          cmake --build bld --config '${{ matrix.type }}' --target test-ci
