name: "Build and check Lexilla on Win32 with Visual C++"

on: [push]

jobs:
    # Compile for amd64 and cross-compile for arm64. Tests run only for amd64.
    build:

        runs-on: windows-latest

        strategy:
          matrix:
            arch:
              - amd64
              - amd64_arm64
        env:
          TEST: ${{ matrix.arch == 'amd64' && 'test' || '' }}
        steps:
        - uses: actions/checkout@v6
        - name: Preparing nmake
          uses: ilammy/msvc-dev-cmd@v1
          with:
            arch: ${{ matrix.arch }}
        - name: Cache Scintilla
          id: cache-scintilla
          uses: actions/cache@v5
          with:
            path: scintilla
            key: ${{ runner.os }}-scintilla
        - name: Install Scintilla source
          if: steps.cache-scintilla.outputs.cache-hit != 'true'
          run: |
              pwd
              New-Item -Name "scintilla" -Type Directory -Force
              cd scintilla
              curl --fail --location --show-error --retry 3 -O https://www.scintilla.org/scintilla500.zip
              ls
              7z x scintilla500.zip
              cd ..
        - name: Copy Scintilla
          run: |
              xcopy /s scintilla\scintilla\ ..\scintilla\
        - name: Unit Test
          run: |
              cd test/unit
              nmake -f test.mak DEBUG=1 $env:TEST
              cd ../..
        - name: Build Lexilla
          run: |
              cd src
              nmake -f lexilla.mak DEBUG=1
              cd ..
        - uses: actions/upload-artifact@v6
          with:
              name: lexilla${{ matrix.arch == 'amd64_arm64' && '-arm64' || '' }}.dll
              path: bin/lexilla.dll
        - name: Test lexing and folding
          run: |
              cd test
              nmake -f testlexers.mak DEBUG=1 $env:TEST
              cd ..
        - name: Check metadata
          if: matrix.arch == 'amd64'
          run: |
              cd test/Metadata
              cl Metadata.cxx ../../access/LexillaAccess.cxx -EHsc -std:c++17 -I ../../include -I ../../access -I ../../../scintilla/include -Fe: Metadata
              ./Metadata -check
              cd ../..
        - name: CheckLexilla C Example
          if: matrix.arch == 'amd64'
          run: |
              cd examples/CheckLexilla
              cl -MP CheckLexilla.c -I ../../include -Fe: CheckLexilla
              .\CheckLexilla.exe
              cd ../..
        - name: SimpleLexer Example
          run: |
              cd examples/SimpleLexer
              cl -MP -std:c++17 -EHsc -LD -I ../../../scintilla/include -I ../../include -I ../../lexlib SimpleLexer.cxx ../../lexlib/*.cxx
              cd ../..
