shithub: m8c

ref: e512e08297b86058e7ec65d92211955c084533d4
dir: /.github/workflows/build-windows.yml/

View raw version
name: m8c win32/win64 build

on:
  push:
  pull_request:
  workflow_dispatch:

jobs:
  build-win:
    runs-on: windows-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - { sys: mingw32, env: i686, win: win32 }
          - { sys: mingw64, env: x86_64, win: win64 }
    name: ${{ matrix.win }}
    defaults:
      run:
        shell: msys2 {0}
    env:
      MINGW_ARCH: ${{ matrix.sys }}
      SDL_VERSION: 3.2.8
    steps:

    - name: 'git config'
      run: git config --global core.autocrlf input
      shell: bash

    - name: 'Checkout'
      uses: actions/checkout@v4
      with:
        fetch-depth: 0

    - name: 'Setup MSYS2'
      uses: msys2/setup-msys2@v2
      with:
        msystem: ${{ matrix.sys }}
        update: true
        install: mingw-w64-${{ matrix.env }}-toolchain make mingw-w64-${{ matrix.env }}-cmake zip dos2unix autoconf automake-wrapper libtool make unzip

    - name: 'Cache SDL3 files'
      id: cache-sdl3-files
      uses: actions/cache@v4
      with:
        path: 'SDL3-3.2.8'
        key: win-sdl3-files-${{ matrix.sys }}

    - name: 'Download SDL3 sources'
      if: steps.cache-sdl3-files.outputs.cache-hit != 'true'
      run: |
        (curl https://www.libsdl.org/release/SDL3-$SDL_VERSION.tar.gz || curl -L https://github.com/libsdl-org/SDL/releases/download/release-$SDL_VERSION/SDL3-$SDL_VERSION.tar.gz) | tar zxvf -

    - name: 'Build and install SDL3'
      if: steps.cache-sdl3-files.outputs.cache-hit != 'true'
      run: |
        pushd SDL3-$SDL_VERSION
        mkdir build_${{ matrix.env }}
        cmake -S . -B build_${{ matrix.env }} -DCMAKE_TOOLCHAIN_FILE=build-scripts/cmake-toolchain-mingw64-${{ matrix.env }}.cmake
        cmake --build build_${{ matrix.env }} --parallel
        popd

    - name: 'Install SDL3'
      run: |
        pushd SDL3-$SDL_VERSION
        cmake --install build_${{ matrix.env }} --prefix C:/Libraries
        popd

    - name: 'Cache libserialport files'
      id: cache-libserialport-files
      uses: actions/cache@v4
      with:
        path: 'libserialport-master'
        key: win-libserialport-files-${{ matrix.sys }}

    - name: 'Build libserialport manually'
      if: steps.cache-libserialport-files.outputs.cache-hit != 'true'
      run: |
        wget https://github.com/sigrokproject/libserialport/archive/refs/heads/master.zip
        unzip master.zip
        pushd libserialport-master
        ./autogen.sh
        ./configure
        make
        popd

    - name: 'Install libserialport'
      run: |
        pushd libserialport-master
        make install
        popd

    - name: Set current date as env variable
      run: echo "NOW=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

    - name: 'Build package'
      run: |
        cmake . -G Ninja -DCMAKE_PREFIX_PATH=C:/Libraries -DCMAKE_BUILD_TYPE=Release
        cmake --build .
        strip -g m8c.exe
        if [ ${{ matrix.win }} == "win32" ]
        then        
          cp C:/Libraries/bin/SDL3.dll .
          cp /mingw32/bin/libgcc_s_dw2-1.dll .
          cp /mingw32/bin/libserialport-0.dll .
          cp /mingw32/bin/libwinpthread-1.dll .
        else
          cp C:/Libraries/bin/SDL3.dll .
          cp /mingw64/bin/libserialport-0.dll .
        fi
        unix2dos README.md LICENSE AUDIOGUIDE.md
    - name: 'Upload artifact (win32)'
      if: matrix.win == 'win32'
      uses: actions/upload-artifact@v4
      with:
        name: m8c-${{ env.NOW }}-${{ matrix.win }}
        path: |
          m8c.exe
          SDL3.dll
          libserialport-0.dll
          libgcc_s_dw2-1.dll
          libwinpthread-1.dll
          gamecontrollerdb.txt
          LICENSE
          README.md
          AUDIOGUIDE.md
    - name: 'Upload artifact (win64)'
      if: matrix.win == 'win64'
      uses: actions/upload-artifact@v4
      with:
        name: m8c-${{ env.NOW }}-${{ matrix.win }}
        path: |
          m8c.exe
          SDL3.dll
          libserialport-0.dll
          gamecontrollerdb.txt
          LICENSE
          README.md
          AUDIOGUIDE.md