name: Build
on:
  push:
    branches:
      - master
jobs:
  todos_linux:
    runs-on: ubuntu-latest
    steps:
    - uses: hecrj/setup-rust-action@v2
    - name: Install cargo-deb
      run: cargo install cargo-deb
    - uses: actions/checkout@master
    - name: Install dependencies
      run: |
        export DEBIAN_FRONTED=noninteractive
        sudo apt-get -qq update
        sudo apt-get install -y libxkbcommon-dev
    - name: Build todos binary
      run: cargo build --verbose --profile release-opt --package todos
    - name: Archive todos binary
      uses: actions/upload-artifact@v4
      with:
        name: todos-x86_64-unknown-linux-gnu
        path: target/release-opt/todos
    - name: Pack todos .deb package
      run: cargo deb --no-build --profile release-opt --package todos
    - name: Rename todos .deb package
      run: mv target/debian/*.deb target/debian/plushie-iced-todos-x86_64-debian-linux-gnu.deb
    - name: Archive todos .deb package
      uses: actions/upload-artifact@v4
      with:
        name: todos-x86_64-debian-linux-gnu
        path: target/debian/plushie-iced-todos-x86_64-debian-linux-gnu.deb

  todos_windows:
    runs-on: windows-latest
    steps:
    - uses: hecrj/setup-rust-action@v2
    - uses: actions/checkout@master
    - name: Enable static CRT linkage
      run: |
        echo '[target.x86_64-pc-windows-msvc]' >> .cargo/config
        echo 'rustflags = ["-Ctarget-feature=+crt-static"]' >> .cargo/config
    - name: Run the application without starting the shell
      run: |
        sed -i '1 i\#![windows_subsystem = \"windows\"]' examples/todos/src/main.rs
    - name: Build todos binary
      run: cargo build --verbose --profile release-opt --package todos
    - name: Archive todos binary
      uses: actions/upload-artifact@v4
      with:
        name: todos-x86_64-pc-windows-msvc
        path: target/release-opt/todos.exe

  todos_macos:
    runs-on: macOS-latest
    steps:
    - uses: hecrj/setup-rust-action@v2
    - uses: actions/checkout@master
    - name: Build todos binary
      env:
        MACOSX_DEPLOYMENT_TARGET: 10.14
      run: cargo build --verbose --profile release-opt --package todos
    - name: Open binary via double-click
      run: chmod +x target/release-opt/todos
    - name: Archive todos binary
      uses: actions/upload-artifact@v4
      with:
        name: todos-x86_64-apple-darwin
        path: target/release-opt/todos

  todos_raspberry:
    runs-on: ubuntu-latest
    steps:
    - uses: hecrj/setup-rust-action@v2
    - uses: actions/checkout@master
    - name: Install cross
      run: cargo install cross
    - name: Build todos binary for Raspberry Pi 3/4 (64 bits)
      run: cross build --verbose --profile release-opt --package todos --target aarch64-unknown-linux-gnu
    - name: Archive todos binary
      uses: actions/upload-artifact@v4
      with:
        name: todos-aarch64-unknown-linux-gnu
        path: target/aarch64-unknown-linux-gnu/release-opt/todos
    - name: Build todos binary for Raspberry Pi 2/3/4 (32 bits)
      run: cross build --verbose --profile release-opt --package todos --target armv7-unknown-linux-gnueabihf
    - name: Archive todos binary
      uses: actions/upload-artifact@v4
      with:
        name: todos-armv7-unknown-linux-gnueabihf
        path: target/armv7-unknown-linux-gnueabihf/release-opt/todos
