name: CI Windows

on:
  push:
    paths-ignore:
      - '**.md'
      - '**.yml'
      - '!**.bat'
      - '!**/windows_ci.yml'
      - 'cmd/tools/**'
      - '!cmd/tools/builders/**.v'
  pull_request:
    paths-ignore:
      - '**.md'
      - '**.yml'
      - '!**.bat'
      - '!**/windows_ci.yml'
      - '!**/windows-install-sqlite.bat'
      - 'cmd/tools/**'
      - '!cmd/tools/builders/**.v'

concurrency:
  group: windows-${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.sha || github.ref }}
  cancel-in-progress: true

jobs:
  gcc-windows:
    runs-on: windows-2025
    timeout-minutes: 90
    env:
      VFLAGS: -cc gcc
    steps:
      - uses: actions/checkout@v4
      - name: Show tool versions
        run: |
          gcc --version
          pkg-config --version
          openssl version
          echo "Flags for openssl:"
          pkg-config openssl --cflags
          echo "Flags for openssl libs:"
          pkg-config openssl --libs
          .github/workflows/find_openssl.bat
          echo "OpenSSL files:"
          where.exe /R "C:\Program Files\OpenSSL" *.*
          echo "Include files for openssl:"
          dir "c:/Program Files/OpenSSL/include"
          echo "Lib Include files for openssl:"
          dir "c:/Program Files/OpenSSL/lib/VC/x64/"
      - name: Build
        run: |
          .\make.bat -gcc
          .\v.exe symlink
          .\v.exe -stats vlib/crypto/ecdsa/ecdsa_test.v
      - name: Test v binaries
        run: v -silent build-vbinaries
      - name: All code is formatted
        run: v -silent test-cleancode
      - name: Test new v.c
        run: |
          v -o v.c cmd/v
          gcc -Werror -municode -w v.c -lws2_32
      - name: Install dependencies
        run: |
          v retry -- v setup-freetype
          .\.github\workflows\windows-install-sqlite.bat
      - name: v doctor
        run: |
          v doctor
      - name: Verify `v test` works
        run: |
          echo $VFLAGS
          v cmd/tools/test_if_v_test_system_works.v
          ./cmd/tools/test_if_v_test_system_works
      - name: Test pure V math module
        run: v -silent -exclude @vlib/math/*.c.v test vlib/math/
      - name: Self tests
        run: v -silent test-self vlib
      # - name: Test
      #   run: v -silent test-all
      - name: Build option_test.c.v with -autofree
        run: v -autofree vlib/v/tests/options/option_test.c.v
      - name: Test v->js
        run: v -o hi.js examples/js_hello_world.v && node hi.js
      - name: Build examples
        run: v -silent build-examples
      - name: v2 self compilation
        run: v -o v2.exe cmd/v && .\v2.exe -o v3.exe cmd/v
      - name: compile vdoctor.v with -prod
        run: v -showcc -prod cmd/tools/vdoctor.v
      - name: compile vup.v with -prod
        run: v -showcc -prod cmd/tools/vup.v

  msvc-windows:
    runs-on: windows-2022
    timeout-minutes: 60
    env:
      VFLAGS: -cc msvc
    steps:
      - uses: actions/checkout@v4
      - name: Build
        run: |
          echo %VFLAGS%
          echo $VFLAGS
          .\make.bat -msvc
          .\v.exe symlink
      - name: Build V with WX
        run: v -cflags /WX self
      - name: All code is formatted
        run: v -silent test-cleancode
      - name: Test -cc msvc works
        run: v -no-retry-compilation run examples/hello_world.v
      - name: Install dependencies
        run: |
          v retry -- v setup-freetype
          .\.github\workflows\windows-install-sqlite.bat
      - name: v doctor
        run: |
          v doctor
      - name: Verify `v test` works
        run: |
          echo $VFLAGS
          v cmd/tools/test_if_v_test_system_works.v
          ./cmd/tools/test_if_v_test_system_works
      - name: Test pure V math module
        run: v -silent -exclude @vlib/math/*.c.v test vlib/math/
      - name: Self tests
        run: v -silent test-self vlib
      # - name: Test
      #   run: v -silent test-all
      - name: Test v->js
        run: v -o hi.js examples/js_hello_world.v && node hi.js
      - name: Test v binaries
        run: v build-vbinaries
      - name: Build examples
        run: v -silent build-examples
      - name: v2 self compilation
        run: v -o v2.exe cmd/v && .\v2.exe -o v3.exe cmd/v

  tcc-windows:
    runs-on: windows-2022
    timeout-minutes: 60
    env:
      VFLAGS: -cc tcc -no-retry-compilation
    steps:
      - uses: actions/checkout@v4
      - name: Build with make.bat -tcc
        run: |
          .\make.bat -tcc
          .\v.exe symlink
      - name: All code is formatted
        run: v -silent test-cleancode
      - name: Test new v.c
        run: |
          v -o v.c cmd/v
          .\thirdparty\tcc\tcc.exe -Werror -w -ladvapi32 -lws2_32 -bt10 v.c
      - name: Install dependencies
        run: |
          v retry -- v setup-freetype
          .\.github\workflows\windows-install-sqlite.bat
      - name: v doctor
        run: |
          v doctor
      - name: Verify `v test` works
        run: |
          v cmd/tools/test_if_v_test_system_works.v
          .\cmd\tools\test_if_v_test_system_works.exe
      - name: Verify `v vlib/v/gen/c/coutput_test.v` works
        run: v vlib/v/gen/c/coutput_test.v
      - name: Make sure running TCC64 instead of TCC32
        run: v test .github\workflows\make_sure_ci_run_with_64bit_compiler_test.v
      - name: Test ./v doc -v clipboard *BEFORE building tools*
        run: v doc -v clipboard
      - name: Test v build-tools
        run: v -silent -W build-tools
      - name: Test pure V math module
        run: v -silent -exclude @vlib/math/*.c.v test vlib/math/
      - name: Self tests
        run: v -silent test-self vlib
      - name: Test v->js
        run: v -o hi.js examples/js_hello_world.v && node hi.js
      - name: Test v binaries
        run: v build-vbinaries
      - name: Build examples
        run: v -silent build-examples
      - name: v2 self compilation
        run: v -o v2.exe cmd/v && .\v2.exe -o v3.exe cmd/v && .\v3.exe -o v4.exe cmd/v

        ## tcc32
        # - name: Build with make.bat -tcc32
        #   run: |
        #     Remove-Item -Recurse -Force .\thirdparty\tcc
        #     v wipe-cache
        #     .\make.bat -tcc32
        # - name: Test new v.c
        #   run: v -o v.c cmd/v && .\thirdparty\tcc\tcc.exe -Werror -g -w -ladvapi32 -lws2_32 -bt10 v.c
        # - name: v doctor
        #   run: v doctor
        #
        # - name: Verify `v test` works
        #   run: |
        #     v cmd/tools/test_if_v_test_system_works.v
        #     .\cmd\tools\test_if_v_test_system_works.exe
        #
        # - name: Verify `v vlib/v/gen/c/coutput_test.v` works
        #   run: |
        #     v vlib/v/gen/c/coutput_test.v
        #
        # - name: Make sure running TCC32 instead of TCC64
        #   run: v -stats .github\workflows\make_sure_ci_run_with_32bit_compiler_test.v
        #
        # - name: Test v build-tools
        #   run: v -silent -W build-tools
        #
        # - name: Test ./v doc clipboard
        #   run: v doc clipboard
        #
        # - name: Self tests
        #   run: v -silent test-self vlib
        # - name: Test v->js
        #   run: v -o hi.js examples/js_hello_world.v && node hi.js
        # - name: Test v binaries
        #   run: v -silent build-vbinaries
        # - name: Build examples
        #   run: v -silent build-examples
        # - name: v2 self compilation
        #   run: v -o v2.exe cmd/v && .\v2.exe -o v3.exe cmd/v
