name: Windows

on: [push]

env:
  SDL2: 2.30.2
  SDL2_TTF: 2.22.0
  SDL2_MIXER: 2.8.0
  SDL2_IMAGE: 2.8.2
  SDL2_GFX: 1.0.4

permissions:
  contents: write

jobs:
  deploy:
    runs-on: windows-latest

    steps:
      - name: Checkout 
        uses: actions/checkout@v4

      - name: Download SDL2 Libraries
        run: |
          curl -L "https://github.com/libsdl-org/SDL/releases/download/release-${{ env.SDL2 }}/SDL2-devel-${{ env.SDL2 }}-VC.zip" -o "sdl2_devel.zip"
          curl -L "https://github.com/libsdl-org/SDL_ttf/releases/download/release-${{ env.SDL2_TTF }}/SDL2_ttf-${{ env.SDL2_TTF }}-win32-x64.zip" -o "sdl2_ttf.zip"
          curl -L "https://github.com/libsdl-org/SDL_image/releases/download/release-${{ env.SDL2_IMAGE }}/SDL2_image-${{ env.SDL2_IMAGE }}-win32-x64.zip" -o "sdl2_image.zip"
          curl -L "https://github.com/libsdl-org/SDL_mixer/releases/download/release-${{ env.SDL2_MIXER }}/SDL2_mixer-${{ env.SDL2_MIXER }}-win32-x64.zip" -o "sdl2_mixer.zip"
          curl -L "https://sourceforge.net/projects/sdl2gfx/files/SDL2_gfx-${{ env.SDL2_GFX }}.tar.gz/download" -o "sdl2_gfx.tar.gz"
      
      - name: Extract SDL2 DLLs
        run: |
          7z --help
          7z --version
          7z x ./sdl2_devel.zip
          mv ./sdl2/SDL2-${{ SDL2 }}/lib/x64/SDL2.dll ./
          mv ./sdl2/SDL2-${{ SDL2 }}/lib/x64/SDL2.lib ./
          7z x ./sdl2_image.zip SDL2_image.dll
          7z x ./sdl2_ttf.zip SDL2_ttf.dll
          7z x ./sdl2_mixer.zip SDL2_mixer.dll

      - name: Setup Rust (Windows)
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: x86_64-pc-windows-gnu
          override: true

      - name: Rust Cache
        uses: Swatinem/rust-cache@v2

      - name: Build
        run: cargo build --release

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          path: ./target/release/pacman.exe
          retention-days: 7
          if-no-files-found: error